Skip to content
Snippets Groups Projects
Commit 78ae4767 authored by Jure's avatar Jure
Browse files

fix(server): additionally protect /api/users

BREAKING CHANGE: This adds additional authorization checks for the new user creation REST endpoint.
Your authsome modes have to be updated.
parent abfc0955
No related branches found
No related tags found
No related merge requests found
......@@ -56,9 +56,17 @@ const UsersAPI = app => {
// Create a user
app.post('/api/users', async (req, res, next) => {
try {
let user = new User(req.body)
// TODO: Remove this in favor of checking in authsome
if (req.body.admin) throw new ValidationError('invalid property: admin')
const properties = await applyPermissionFilter({
req,
target: req.route,
filterable: req.body,
})
let user = new User(properties)
user = await user.save()
res.status(STATUS.CREATED).json(user)
} catch (err) {
......
......@@ -77,6 +77,10 @@ function unauthenticatedUser(operation, object) {
}
}
if (operation === 'POST' && object && object.path === '/api/users') {
return true
}
return false
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment