-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: Update persister_oauth2.go to handle special character | coming in t… #3849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ajayn84
wants to merge
4
commits into
ory:master
Choose a base branch
from
Ajayn84:fix/escape_pipe_char_for_consent_flow
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1606831
Update persister_oauth2.go to handle special character | coming in t…
Ajayn84 070518c
fix: Update persister_oauth2.go to handle special character | coming …
Ajayn84 64b6083
fix: update commit to fix review comments
Ajayn84 afe6d35
Merge branch 'master' into fix/escape_pipe_char_for_consent_flow
Ajayn84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,8 +118,8 @@ func (p *Persister) sqlSchemaFromRequest(ctx context.Context, signature string, | |
RequestedAt: r.GetRequestedAt(), | ||
InternalExpiresAt: sqlxx.NullTime(expiresAt), | ||
Client: r.GetClient().GetID(), | ||
Scopes: strings.Join(r.GetRequestedScopes(), "|"), | ||
GrantedScope: strings.Join(r.GetGrantedScopes(), "|"), | ||
Scopes: strings.Join(escapeDelimiter(r.GetRequestedScopes()), "|"), | ||
GrantedScope: strings.Join(escapeDelimiter(r.GetGrantedScopes()), "|"), | ||
GrantedAudience: strings.Join(r.GetGrantedAudience(), "|"), | ||
RequestedAudience: strings.Join(r.GetRequestedAudience(), "|"), | ||
Form: r.GetRequestForm().Encode(), | ||
|
@@ -179,13 +179,23 @@ func (r *OAuth2RequestSQL) toRequest(ctx context.Context, session fosite.Session | |
return nil, errorsx.WithStack(err) | ||
} | ||
|
||
scopes, err := unescapeDelimiter(r.Scopes) | ||
if err != nil { | ||
return nil, errorsx.WithStack(err) | ||
} | ||
|
||
grantedScopes, err := unescapeDelimiter(r.GrantedScope) | ||
if err != nil { | ||
return nil, errorsx.WithStack(err) | ||
} | ||
|
||
return &fosite.Request{ | ||
ID: r.Request, | ||
RequestedAt: r.RequestedAt, | ||
// ExpiresAt does not need to be populated as we get the expiry time from the session. | ||
Client: c, | ||
RequestedScope: stringsx.Splitx(r.Scopes, "|"), | ||
GrantedScope: stringsx.Splitx(r.GrantedScope, "|"), | ||
RequestedScope: scopes, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are splitting the data from db with "|" and then unescaping to get "|" back in the scopes if any |
||
GrantedScope: grantedScopes, | ||
RequestedAudience: stringsx.Splitx(r.RequestedAudience, "|"), | ||
GrantedAudience: stringsx.Splitx(r.GrantedAudience, "|"), | ||
Form: val, | ||
|
@@ -612,3 +622,29 @@ func (p *Persister) DeleteAccessTokens(ctx context.Context, clientID string) (er | |
p.QueryWithNetwork(ctx).Where("client_id=?", clientID).Delete(&OAuth2RequestSQL{Table: sqlTableAccess}), | ||
) | ||
} | ||
|
||
func escapeDelimiter(scopes []string) []string { | ||
escapedScopes := make([]string, len(scopes)) | ||
for i, scope := range scopes { | ||
if strings.Contains(scope, "|") { | ||
escapedScopes[i] = url.QueryEscape(scope) | ||
} else { | ||
escapedScopes[i] = scope | ||
} | ||
} | ||
return escapedScopes | ||
} | ||
|
||
func unescapeDelimiter(scopes string) ([]string, error) { | ||
updatedScopes := stringsx.Splitx(scopes, "|") | ||
if strings.Contains(scopes, "%26") { | ||
for i, scope := range updatedScopes { | ||
unescapedScope, err := url.QueryUnescape(scope) | ||
if err != nil { | ||
return nil, errors.Errorf("Error while url unescaping scope: %s", scope) | ||
} | ||
updatedScopes[i] = unescapedScope | ||
} | ||
} | ||
return updatedScopes, nil | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are escaping delimter "|" using queryescape and then joining with "|" delimiter, so that scopes with "|" are replaced with and then joined using "|"