-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: allow any port on loopback OAuth2 redirect URIs #29013
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
13 commits
Select commit
Hold shift + click to select a range
3bbc6ec
feat(codersdk): add a loopback-aware redirect URI comparator
BobbyHo 81e2fde
fix(coderd/httpapi): allow any port on loopback redirect URIs
BobbyHo ac9f591
test(coderd/oauth2provider): cover the loopback redirect port excepti…
BobbyHo 61d4bd4
docs(admin/integrations): describe the loopback redirect port exception
BobbyHo baca1c6
Merge branch 'main' into plat488-1-loopback-comparator
BobbyHo c33f0b4
Merge branch 'main' into plat488-1-loopback-comparator
BobbyHo 182b465
docs(codersdk): cite RFC 8252 correctly in the IsLoopbackAddress comment
BobbyHo 6cf371f
docs(admin/integrations): say which hosts and clients get the loopbac…
BobbyHo 6fa2fc6
refactor(codersdk): unexport isLoopbackAddress and clarify RedirectUR…
BobbyHo 2eeee6c
fix(coderd): say the loopback port may differ in the redirect_uri mis…
BobbyHo e521650
test(coderd/httpapi): collapse the loopback component mismatch cases
BobbyHo 573912d
Merge branch 'main' into plat488-1-loopback-comparator
BobbyHo 27ad55f
Merge branch 'main' into plat488-1-loopback-comparator
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package codersdk_test | ||
|
|
||
| import ( | ||
| "net/url" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
@@ -86,3 +87,43 @@ func TestOAuth2ClientRegistrationRequest_DetermineClientType(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestRedirectURIMatches(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| registered string | ||
| presented string | ||
| want bool | ||
| }{ | ||
| {"ExactMatch", "https://app.example.com/callback", "https://app.example.com/callback", true}, | ||
| {"CustomSchemeExact", "cursor://anysphere.cursor-mcp/oauth/callback", "cursor://anysphere.cursor-mcp/oauth/callback", true}, | ||
| {"LoopbackIPv4PortDiffers", "http://127.0.0.1/callback", "http://127.0.0.1:53219/callback", true}, | ||
| {"LoopbackIPv6PortDiffers", "http://[::1]/callback", "http://[::1]:53219/callback", true}, | ||
| {"LocalhostPortDiffers", "http://localhost/callback", "http://localhost:53219/callback", true}, | ||
| {"RegisteredPortDoesNotPin", "http://localhost:9876/callback", "http://localhost:53219/callback", true}, | ||
| {"PresentedWithoutPort", "http://127.0.0.1:53219/callback", "http://127.0.0.1/callback", true}, | ||
| {"LoopbackPathDiffers", "http://127.0.0.1/callback", "http://127.0.0.1:53219/other", false}, | ||
| {"LoopbackSchemeDiffers", "http://127.0.0.1/callback", "https://127.0.0.1:53219/callback", false}, | ||
| {"LoopbackHostSubstitution", "http://127.0.0.1/callback", "http://localhost:53219/callback", false}, | ||
| {"LoopbackQueryDiffers", "http://127.0.0.1/callback", "http://127.0.0.1:53219/callback?next=x", false}, | ||
| {"LoopbackUserinfoDiffers", "http://127.0.0.1/callback", "http://[email protected]:53219/callback", false}, | ||
| {"LocalhostSubdomain", "http://app.localhost/callback", "http://app.localhost:53219/callback", false}, | ||
| {"OtherLoopbackIP", "http://127.0.0.2/callback", "http://127.0.0.2:53219/callback", false}, | ||
| {"HTTPSLoopbackPortDiffers", "https://127.0.0.1/callback", "https://127.0.0.1:53219/callback", false}, | ||
| {"NonLoopbackPortDiffers", "https://app.example.com/callback", "https://app.example.com:8443/callback", false}, | ||
| {"LoopbackPresentedAgainstNonLoopback", "https://app.example.com/callback", "http://127.0.0.1:53219/callback", false}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| registered, err := url.Parse(tt.registered) | ||
| require.NoError(t, err) | ||
| presented, err := url.Parse(tt.presented) | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.want, codersdk.RedirectURIMatches(presented, registered)) | ||
| }) | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package codersdk | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestIsLoopbackAddress(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| for _, host := range []string{"localhost", "127.0.0.1", "::1"} { | ||
| require.True(t, isLoopbackAddress(host), host) | ||
| } | ||
| // Callers pass url.URL.Hostname(), which strips IPv6 brackets. | ||
| for _, host := range []string{"", "[::1]", "app.localhost", "127.0.0.2", "0.0.0.0", "example.com"} { | ||
| require.False(t, isLoopbackAddress(host), host) | ||
| } | ||
| } |
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.
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.