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 }}
Repository navigation
Auth checks return the wrong http status code when aclErrorStatus is set to 403 #1812
When aclErrorStatus is set to 403, it fails one use case, when the accessToken is supplied but invalid.
Consider the following use cases:
attempt to access a protected resource without creds (missing token): 401(a auth/login failure)
attempt to access a protected resource with invalid creds (fake token): 401 (a auth/login failure)
attempt to access a protected resource with expired creds (old token): 401 (a auth/login failure)
attempt to access a protected resource with valid creds (valid token) that requires an elevated permission (higher role) : 403 (access denied)
Out of these 4 use cases, # 2 and # 3 fail to return 401 and instead return 403. This is because in application.js, the logic that returns 401 does not check for a valid token (i.e. if the token has a valid userId), leaving further ACL failures to default to aclErrorStatus, which is set to 403. See annotated code below:
varerrStatusCode=modelSettings.aclErrorStatus||app.get('aclErrorStatus')||401;/////// HANDLE 401 USE CASESif(!req.accessToken){// <- this lets a fake or expired token get away from a 401errStatusCode=401;}////// LAST CHANCE FOR 401 USE CASES ENDS HERE////// EVERYTHING BELOW USES errStatusCodeif(Model.checkAccess){
...
}
Suggested fix:
varerrStatusCode=modelSettings.aclErrorStatus||app.get('aclErrorStatus')||401;if(!req.accessToken||!req.accessToken.userId){// Checks both the presence and validity of a tokenerrStatusCode=401;}if(Model.checkAccess){
...
}
Activity
simoami commentedon Nov 12, 2015
Sorry, this might be the result of a modified token middleware. Need to investigate some more. closing for now.