Repository navigation
fix(scope): reject empty array from validateScope for a requested scope #518 - #532
Open
alikendir0 wants to merge 1 commit into
Open
alikendir0 wants to merge 1 commit into
alikendir0 wants to merge 1 commit into
Conversation
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
If the model's
validateScope()returns an empty array, the handlers accept it, because the check isif (!validatedScope)and[]is truthy. With the "filter out invalid scopes" example from the model docs this means a request for a scope the client isn't allowed at all still gets an authorization code, and the token endpoint answers 200 withscope: "".This changes the check in
AbstractGrantType#validateScopeandAuthorizeHandler#validateScopeso an empty array is rejected withinvalid_scopewhen a scope was actually requested. When no scope was requested, an empty array is still accepted like before. The issue asks for[]to be rejected in every case, but I didn't want to break models that return[]for scope-less requests (scope is optional since #103). If you'd rather have the strict version it's a one-line change, just say so.@Figo5 offered to send a PR in the issue. I didn't see one after a month so I went ahead, but I'm happy to close this if you'd rather do it yourself.
Linked issue(s)
Fixes #518
Involved parts of the project
lib/grant-types/abstract-grant-type.js(authorization_code, client_credentials, password, and extension grants that callvalidateScope)lib/handlers/authorize-handler.jsThe refresh_token grant doesn't call
validateScope, so it's untouched. I also updated the JSDoc inlib/model.jsand regenerateddocs/apiwithnpm run docs:api.Added tests?
Yes, for
AbstractGrantType#validateScope, the authorize handler (error redirect, no code saved) and the token handler (400invalid_scope, no token saved). The three rejection tests fail on master. Two more tests pin the "no scope requested" case so it keeps working.OAuth2 standard
RFC 6749 section 3.3 defines
scopeas one or more scope tokens, soscope: ""in a token response isn't valid. Sections 4.1.2.1 and 5.2 defineinvalid_scopefor the authorization and token endpoints.Reproduction
Use a model whose
validateScopefilters the requested scopes:Send an authorization request with
scope=admin. On master you get a code, and exchanging it returns 200 withscope: "". With this change the authorization request redirects witherror=invalid_scope.One thing I left alone: with no scope requested and a model returning
[], the token response still containsscope: ""(fromTokenHandler#updateSuccessResponse). That felt like a separate change, but I can add it here if you want.