apache / apache/couchdb

Can set couch_peruser.database_prefix with illegal characters

Open
#2,291 3 comments 0 reactions 0 assignees View on GitHub
bug enhancement patches-welcome
Dominant language
Erlang
Stars
7k
Forks
1.1k
Avg merge
1d 16h
Merged PRs (30d)
9

Description

## Description

When using couch_peruser it is allowed to set database_prefix with illegal characters for a database name. For us this resulted in CouchDB crashing and being unable to start until we changed the configuration manually in local.ini

## Steps to Reproduce

1. Set up single node CouchDB
2. Run
```
curl -H 'Content-Type: application/json' -X PUT http://localhost:5984/_node/nonode@nohost/_config/couch_peruser/database_prefix -d '"userdb-.-"'
curl -H 'Content-Type: application/json' -X PUT http://localhost:5984/_node/nonode@nohost/_config/couch_peruser/enable -d '"true"'
```
3. CouchDB has now crashed, and will crash immediately on restart. The error messages I saw after attempted restart were:
```
Error: {error,{illegal_database_name,<<"userdb-.-">>}}
[error] 2019-10-31T14:28:37.769379Z nonode@nohost <0.416.0> -------- CRASH REPORT Process couch_peruser (<0.416.0>) with 0 neighbors exited with reason: bad return value {error,{illegal_database_name,<<"userdb-.-">>}} at gen_server:init_it/6(line:356) <= proc_lib:init_p_do_apply/3(line:247); initial_call: {couch_peruser,init,['Argument__1']}, ancestors: [couch_peruser_sup,<0.414.0>], messages: [], links: [<0.415.0>,<0.87.0>], dictionary: [], trap_exit: false, status: running, heap_size: 1598, stack_size: 27, reductions: 1586
[error] 2019-10-31T14:28:37.769649Z nonode@nohost <0.415.0> -------- Supervisor couch_peruser_sup had child couch_peruser started with couch_peruser:start_link() at undefined exit with reason bad return value {error,{illegal_database_name,<<"userdb-.-">>}} in context start_error
[error] 2019-10-31T14:28:37.770164Z nonode@nohost <0.413.0> -------- CRASH REPORT Process (<0.413.0>) with 0 neighbors exited with reason: {{shutdown,{failed_to_start_child,couch_peruser,{bad_return_value,{error,{illegal_database_name,<<"userdb-.-">>}}}}},{couch_peruser_app,start,[normal,[]]}} at application_master:init/4(line:134) <= proc_lib:init_p_do_apply/3(line:247); initial_call: {application_master,init,['Argument__1','Argument__2',...]}, ancestors: [<0.412.0>], messages: [{'EXIT',<0.414.0>,normal}], links: [<0.412.0>,<0.9.0>], dictionary: [], trap_exit: true, status: running, heap_size: 376, stack_size: 27, reductions: 105
[info] 2019-10-31T14:28:37.770459Z nonode@nohost <0.9.0> -------- Application couch_peruser exited with reason: {{shutdown,{failed_to_start_child,couch_peruser,{bad_return_value,{error,{illegal_database_name,<<"userdb-.-">>}}}}},{couch_peruser_app,start,[normal,[]]}}

```

## Expected Behaviour

Setting `couch_peruser.database_prefix` to a value with invalid database characters will throw an error.

## Your Environment

* CouchDB Version used: 2.3.1
* Operating System and version: Debain 10 (buster)

Contributor guide

Open the contributing guide

Research direction

Start at the couch_peruser component and reproduce the configuration change using couch_peruser/database_prefix with the example invalid value. Trace its startup handling and add coverage for rejecting invalid database characters; done means the configuration reports an error without causing CouchDB to crash or fail to restart.

Written by the indexing model from the issue text.

Assessment

Tech stack
erlang
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.