-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: reject PKCE code_verifier below RFC 7636 length floor #28003
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7e3f6c0
fix(coderd/oauth2provider): reject PKCE code_verifier below RFC 7636 …
BobbyHo a125238
fix(scripts/oauth2): generate PKCE verifiers at the RFC 7636 floor le…
BobbyHo eea4094
fix(coderd/oauth2provider): validate code_challenge format at authorize
BobbyHo e7d78d5
fix(coderd/oauth2provider): return invalid_request for malformed code…
BobbyHo fb7e90b
fix(coderd/oauth2provider/oauth2providertest): restore e2e coverage o…
BobbyHo 4fe0b1b
fix(coderd/oauth2provider): revoke authorization code on PKCE failure
BobbyHo 663865a
fix: resolve remaining coder-agents-review findings on PKCE hardening
BobbyHo 912ce41
fix(docs/admin): document PKCE length and charset requirement
BobbyHo 1821ad4
fix: allow bare custom-scheme redirects for public clients (#28041)
BobbyHo 7ea2990
Merge branch 'main' into oauth2-pkce-verifier-length
BobbyHo dc99c2c
fix(coderd/oauth2provider): skip revoke logging when the code is alre…
BobbyHo 65f9fdc
fix(coderd/oauth2provider): revoke PKCE-failed codes on a detached co…
BobbyHo 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 |
|---|---|---|
|
|
@@ -267,6 +267,19 @@ func TestOAuth2PrivilegeEscalation(t *testing.T) { | |
| ClientName: fmt.Sprintf("native-app-3-%d", time.Now().UnixNano()), | ||
| TokenEndpointAuthMethod: "none", // Required for public clients | ||
| }, | ||
| { | ||
| // Bare custom schemes (no reverse-domain notation) are the | ||
| // schemes real native apps register with the OS, and PKCE, | ||
| // not the scheme's spelling, is what secures the redirect. | ||
| RedirectURIs: []string{"vscode://coder.authenticate"}, | ||
| ClientName: fmt.Sprintf("native-app-vscode-%d", time.Now().UnixNano()), | ||
| TokenEndpointAuthMethod: "none", | ||
| }, | ||
| { | ||
| RedirectURIs: []string{"jetbrains://coder-callback"}, | ||
| ClientName: fmt.Sprintf("native-app-jetbrains-%d", time.Now().UnixNano()), | ||
| TokenEndpointAuthMethod: "none", | ||
| }, | ||
| } | ||
|
|
||
| for i, req := range validCustomSchemeRequests { | ||
|
|
@@ -312,6 +325,54 @@ func TestOAuth2PrivilegeEscalation(t *testing.T) { | |
| require.Contains(t, err.Error(), "dangerous scheme") | ||
| }) | ||
| } | ||
|
|
||
| // mailto, tel, and sms are not in the dangerous-scheme blocklist | ||
| // above: they hand off to a mail client, dialer, or SMS app rather | ||
| // than injecting content, so they are harmless for a confidential | ||
| // client's redirect. A public client has no secret, so the redirect | ||
| // URI's scheme is its only mechanism for regaining control, and | ||
| // none of these three return control to it the way a real redirect | ||
| // scheme does. They are rejected for public clients specifically, | ||
| // with a distinct error from the dangerous-scheme case above. | ||
| publicClientDisallowedSchemeRequests := []struct { | ||
| req codersdk.OAuth2ClientRegistrationRequest | ||
| scheme string | ||
| }{ | ||
| { | ||
| req: codersdk.OAuth2ClientRegistrationRequest{ | ||
| RedirectURIs: []string{"mailto:[email protected]"}, | ||
| ClientName: fmt.Sprintf("native-app-mailto-%d", time.Now().UnixNano()), | ||
| TokenEndpointAuthMethod: "none", | ||
| }, | ||
| scheme: "mailto", | ||
| }, | ||
| { | ||
| req: codersdk.OAuth2ClientRegistrationRequest{ | ||
| RedirectURIs: []string{"tel:+15555550100"}, | ||
| ClientName: fmt.Sprintf("native-app-tel-%d", time.Now().UnixNano()), | ||
| TokenEndpointAuthMethod: "none", | ||
| }, | ||
| scheme: "tel", | ||
| }, | ||
| { | ||
| req: codersdk.OAuth2ClientRegistrationRequest{ | ||
| RedirectURIs: []string{"sms:+15555550100"}, | ||
| ClientName: fmt.Sprintf("native-app-sms-%d", time.Now().UnixNano()), | ||
| TokenEndpointAuthMethod: "none", | ||
| }, | ||
| scheme: "sms", | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range publicClientDisallowedSchemeRequests { | ||
| t.Run(fmt.Sprintf("PublicClientDisallowedScheme_%s", test.scheme), func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| _, err := client.PostOAuth2ClientRegistration(ctx, test.req) | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "public clients may not use the "+test.scheme+" scheme") | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
|
|
||
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.