Skip to content

Commit

Permalink
fix(store): POST db/_all_docs is still just a read
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Sep 13, 2016
1 parent 714be28 commit 6248663
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/config/store/pre-auth-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function onStorePreAuth (request, reply) {
var storePath = request.path.substr('/hoodie/store/api/'.length)
var dbPath = storePath.split('/')[0]
var dbName = decodeURIComponent(dbPath)
var requiredAccess = request.method === 'get' ? 'read' : 'write'
var requiredAccess = isRead(request) ? 'read' : 'write'

return server.plugins.store.api.hasAccess(dbName, {
access: requiredAccess
Expand Down Expand Up @@ -78,3 +78,16 @@ function toSessionToken (request) {
}
return token
}

function isRead (request) {
if (request.method === 'get') {
return true
}

// POST db/_all_docs is still a read request
if (/^\/hoodie\/store\/api\/[^\/]+\/_all_docs$/.test(request.path)) {
return true
}

return false
}

0 comments on commit 6248663

Please sign in to comment.