apache / couchdb

Seamless multi-master syncing database with an intuitive HTTP/JSON API, designed for reliability
https://couchdb.apache.org/
Apache License 2.0
6.26k stars 1.03k forks source link

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

Closed ermouth closed 2 years ago

ermouth commented 6 years ago

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

wohali commented 6 years ago

@ermouth I think this was fixed for 2.2.0, see https://github.com/apache/couchdb/pull/961

wohali commented 6 years ago

if not let me know and we can reopen

ermouth commented 6 years ago

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 commented 6 years ago

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 commented 3 years ago

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 node1@127.0.0.1 emulator -------- Error in process <0.16318.0> on node 'node1@127.0.0.1' 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}]}]}
jaydoane commented 2 years ago

It appears that https://github.com/apache/couchdb/pull/3990 fixes this issue, so closing as resolved.