"Referer Header Required" error in couchdb when trying to use _find "Referer Header Required" error in couchdb when trying to use _find curl curl

"Referer Header Required" error in couchdb when trying to use _find


Probaly too late but for for the next people (like me) that will get on this topic, the problem is :

http://localhost:5984/mydb/_find

When you try to change POST in PUT you get the problem :

"reason":"Only reserved document ids may start with underscore."

the _document refer to special function so just change the name of the document :)

(should work in both post / put after this)


I managed to fix the Referer header required and the subsequent Referer header must match host by looking through the source code. Though the real problem was expecting _find to work in those ancient 1.X builds OS package managers default to. It's much better to upgrade to the latest version of couchdb (3.1.1).

You can workaround the error on old versions by adding vhosts to the config file /etc/couchdb/local.ini

[vhosts];localhost = /db/localhost = /*[httpd]x_forwarded_host = Y-Forwarded-Host

and potentially also using a custom header name for X-Forwarded-Host, in my case the software fetching the API call does some overly clever things to X-Forwarded-Host and Host headers.

so when you call couchdb just include the new header with either 'localhost'

curl -X POST http://localhost:5984/mydb/_find \-H 'Referer: localhost' \-H 'Y-Forwarded-Host: localhost' \-d '{"selector":{"member.email":"foo@bar.com"}}

or blank so they match

curl -X POST http://localhost:5984/mydb/_find \-H 'Referer' \-H 'X-Forwarded-Host' \-d '{"selector":{"member.email":"foo@bar.com"}}

neither header is needed in version 2 or 3 onward, they came to their senses.