Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating index with "ddoc":"" makes DB read-only #1472

Closed
ermouth opened this issue Jul 31, 2018 · 6 comments
Closed

Creating index with "ddoc":"" makes DB read-only #1472

ermouth opened this issue Jul 31, 2018 · 6 comments

Comments

@ermouth
Copy link
Contributor

ermouth commented Jul 31, 2018

Expected Behavior

CouchDB should prevent creation of Mango index ddoc with the _design/ _id.

Current Behavior

POST-ing JSON body with "ddoc":"" field to /db/_index creates a ddoc, which seems non-deletable, effectively breaks replication and makes DB non-writable (both PUT and POST fail with 500).

Steps to Reproduce

  1. Open Fauxton
  2. Create a DB
  3. Open Mango query tab and then Mango indexes
  4. Create index with any name and "ddoc":"" field

Context

I was creating Mango index editor in Couch Photon, and noticed the issue during UI tests.

Your Environment

  • Version used: CouchDB 2.1.2 single node
  • Browser Name and version: Chrome 66
  • Operating System and version (desktop or mobile): Xenial
@wohali
Copy link
Member

wohali commented Jul 31, 2018

@ermouth I think this was fixed for 2.2.0, see #961

@wohali wohali closed this as completed Jul 31, 2018
@wohali
Copy link
Member

wohali commented Jul 31, 2018

if not let me know and we can reopen

@ermouth
Copy link
Contributor Author

ermouth commented Jul 31, 2018

#961 is unrelated. Letting you know it is not fixed in 2.2.x branch. Just built 2.2.0 from sources to check it.

@wohali wohali reopened this Jul 31, 2018
@wohali wohali modified the milestone: 2.2.0 Jul 31, 2018
@wohali
Copy link
Member

wohali commented Aug 7, 2018

Confirmed:

$ curl -X PUT localhost:15984/abc
{"error":"file_exists","reason":"The database could not be created, the file already exists."}
$ curl -X POST -H "Content-Type: application/json" localhost:15984/abc/_index -d '{"ddoc":"", "index":{"fields": ["food"]}}'
{"result":"created","id":"_design/","name":"3c4336c43e5e1a54362c91818f3909a95ba10120"}
$ curl localhost:15984/abc/_design
{"error":"not_found","reason":"missing"}
$ curl localhost:15984/abc/_design/
{"error":"not_found","reason":"missing"}
$ curl localhost:15984/abc/_all_docs
{"total_rows":3,"offset":0,"rows":[
{"id":"_design/","key":"_design/","value":{"rev":"1-b17f56e26b76133f3c9dc111f6222da6"}},
{"id":"a","key":"a","value":{"rev":"1-73a83873149212c382ed9432f4df7b3a"}},
{"id":"b","key":"b","value":{"rev":"1-0f07c7dbc9a29f0d0c2729f9c61f5411"}}
]}

@nickva
Copy link
Contributor

nickva commented Nov 4, 2021

This still happens. With auto-indexer (ken) it's even worse as it will start crashing as well and flooding the logs with failures that look like:

[error] 2021-11-04T17:19:00.390502Z [email protected] emulator -------- Error in process <0.16318.0> on node '[email protected]' with exit value:
{{nocatch,{illegal_docid,<<"Illegal document id `_design/`">>}},[{couch_doc,validate_docid,1,[{file,"src/couch_doc.erl"},{line,213}]},{couch_doc,transfer_fields,3,[{file,"src/couch_doc.erl"},{line,252}]},{ken_server,'-update_db_indexes/2-fun-1-',4,[{file,"src/ken_server.erl"},{line,280}]},{lists,foldl,3,[{file,"lists.erl"},{line,1263}]},{ken_server,update_db_indexes,2,[{file,"src/ken_server.erl"},{line,279}]}]}

jiahuili430 added a commit to jiahuili430/couchdb that referenced this issue Apr 26, 2022
Creating an index with "ddoc":"" or "name":"" should return a 400 Bad Request.

Testing recommendations:
```
curl -X DELETE $db/abc && curl -X PUT $db/abc
curl -X POST $db/abc/_index -H 'Content-Type: application/json' -d '{"ddoc": "", "index": {"fields": ["foo"]}}'
curl -X POST $db/abc/_index -H 'Content-Type: application/json' -d '{"name": "", "index": {"fields": ["bar"]}}'

{"error":"invalid_empty_string","reason":"Index name/ddoc cannot be empty"}
```

Related Issues: apache#1472
tonysun83 pushed a commit that referenced this issue Apr 26, 2022
Creating an index with "ddoc":"" or "name":"" should return a 400 Bad Request.

This fixes: #1472
@jaydoane
Copy link
Contributor

jaydoane commented Jun 1, 2022

It appears that #3990 fixes this issue, so closing as resolved.

@jaydoane jaydoane closed this as completed Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants