You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
when owner is set to true, the source code uses the following logic:
if (options.owner && !authorized) {
// NOTE (EK): This just scopes the query for the resource requested to the
// current user, which will result in a 404 if they are not the owner.
hook.params.query[options.ownerField] = id;
authorized = true;
which is fine for find method, coz when finding, if the query.userId is wrong, feathers will return 404.
But at least in mongoose, update/patch/remove/get don't rely on query to execute, and the behavior is like this: update: the modification is executed despite it's neither admin or owner patch and remove: the modification is not executed, and no error thrown. the unchanged data is returned to client get: the data is returned to client despite that it's neither admin or owner.
so I think the right way to do this is just like what EK wrote in TODO:
// TODO (EK): Maybe look up the actual document in this hook and throw a Forbidden error
// if (field && id && field.toString() !== id.toString()) {
// throw new errors.Forbidden('You do not have valid permissions to access this.');
// }
and the code could simply be like this (untested):
this.get(hook.id).then(data => {
if (data[options.ownerField].toString() !== id.toString()) {
throw new errors.Forbidden('You do not have valid permissions to access this.');
}
return hook;
});
(restrictToOwner has the same issue.)
The text was updated successfully, but these errors were encountered:
@beeplin you are absolutely correct. I had thought about this but I think was too tired to really grok my error. I'm going to be doing a patch tomorrow for this so that it will throw a legit Forbidden error if you are not authorized.
ekryski
changed the title
[bug] the new hook restrictToRoles with owner:true not work correctly with update/patch/remove
restrictToOwner hook needs to throw an error and not scope the query
Mar 26, 2016
when
owner
is set totrue
, the source code uses the following logic:which is fine for
find
method, coz whenfind
ing, if thequery.userId
is wrong, feathers will return 404.But at least in mongoose,
update/patch/remove/get
don't rely onquery
to execute, and the behavior is like this:update
: the modification is executed despite it's neither admin or ownerpatch
andremove
: the modification is not executed, and no error thrown. the unchanged data is returned to clientget
: the data is returned to client despite that it's neither admin or owner.so I think the right way to do this is just like what EK wrote in TODO:
and the code could simply be like this (untested):
(
restrictToOwner
has the same issue.)The text was updated successfully, but these errors were encountered: