Created
July 26, 2010 12:37
-
-
Save lizconlan/490482 to your computer and use it in GitHub Desktop.
CouchDB security - prevent non-admins from editing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(newDoc, oldDoc, userCtx) { | |
if (userCtx.roles.indexOf('_admin') !== -1) { | |
return; | |
} else { | |
throw({forbidden: 'Only admins may edit the database'}); | |
} | |
} |
version 2 blocks everything, version 1 left a loophole where an unauthorised user could upload an attachment and break the security model
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By default a new CouchDB database will have full public access.
Creating an admin user will only take you so far - it should prevent new databases being created and existing ones being deleted. You should also block reader access to any databases (e.g. ** _users **) that you do not want to be publicly available.
For data you are happy to open source:
_design/_auth
language
javascript
validate_doc_update
Run a few tests and you should be good to go :)