-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: implement CSRF protection for OAuth flows with nonce validation #20983
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
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2ab7563
feat: implement CSRF protection for OAuth flows with nonce validation
iQQBot 9864027
refactor: consolidate fragment protection and fix context provider co…
iQQBot fd3ec9b
fix: handle GitHub OAuth api subdomain edge case with secure redirect
iQQBot bd2f098
fix: simplify api subdomain redirect test to avoid dependency injecti…
iQQBot d059c2a
docs: update domain examples to use gitpod.io instead of preview domains
iQQBot dc0dda6
fix cookie
iQQBot 4afef34
Update authenticator.ts
iQQBot b6f8777
Update authenticator.ts
iQQBot 001903f
minor stuff
geropl 1bf86ee
cleanup old redirect logic
iQQBot 6768661
cleanup
iQQBot df392be
1
iQQBot b33555f
feat: add feature flags for nonce validation and strict authorize ret…
iQQBot 8072d9f
fix: validate OAuth callback origin against SCM provider domain
iQQBot 25fd345
1
iQQBot 10b52a6
remove the origin check logic
iQQBot 3a5811a
update sorry url
iQQBot 6d200db
move files
iQQBot 8a7443e
use safeRedirect for redirect
iQQBot 11354aa
1
iQQBot 2508f23
[server] minor refactor/renames
geropl b23349b
moah changes
geropl 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Copyright (c) 2024 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { expect } from "chai"; | ||
|
||
describe("API Subdomain Redirect Logic", () => { | ||
// Test the core logic without complex dependency injection | ||
function isApiSubdomainOfConfiguredHost(hostname: string, configuredHost: string): boolean { | ||
return hostname === `api.${configuredHost}`; | ||
} | ||
|
||
describe("isApiSubdomainOfConfiguredHost", () => { | ||
it("should detect api subdomain of configured host", () => { | ||
const configuredHost = "gitpod.io"; | ||
const testCases = [ | ||
{ hostname: "api.gitpod.io", expected: true }, | ||
{ hostname: "api.preview.gitpod-dev.com", expected: false }, // Different configured host | ||
{ hostname: "gitpod.io", expected: false }, // Main domain | ||
{ hostname: "workspace-123.gitpod.io", expected: false }, // Other subdomain | ||
{ hostname: "api.evil.com", expected: false }, // Different domain | ||
]; | ||
|
||
testCases.forEach(({ hostname, expected }) => { | ||
const result = isApiSubdomainOfConfiguredHost(hostname, configuredHost); | ||
expect(result).to.equal(expected, `Failed for hostname: ${hostname}`); | ||
}); | ||
}); | ||
|
||
it("should handle GitHub OAuth edge case correctly", () => { | ||
// This is the specific case mentioned in the login completion handler | ||
const configuredHost = "gitpod.io"; | ||
const apiSubdomain = `api.${configuredHost}`; | ||
|
||
const result = isApiSubdomainOfConfiguredHost(apiSubdomain, configuredHost); | ||
expect(result).to.be.true; | ||
}); | ||
|
||
it("should handle preview environment correctly", () => { | ||
const configuredHost = "preview.gitpod-dev.com"; | ||
const apiSubdomain = `api.${configuredHost}`; | ||
|
||
const result = isApiSubdomainOfConfiguredHost(apiSubdomain, configuredHost); | ||
expect(result).to.be.true; | ||
}); | ||
}); | ||
|
||
describe("OAuth callback flow scenarios", () => { | ||
it("should identify redirect scenarios correctly", () => { | ||
const scenarios = [ | ||
{ | ||
name: "GitHub OAuth Callback on API Subdomain", | ||
hostname: "api.gitpod.io", | ||
configuredHost: "gitpod.io", | ||
shouldRedirect: true, | ||
}, | ||
{ | ||
name: "Regular Login on Main Domain", | ||
hostname: "gitpod.io", | ||
configuredHost: "gitpod.io", | ||
shouldRedirect: false, | ||
}, | ||
{ | ||
name: "Workspace Port (Should Not Redirect)", | ||
hostname: "3000-gitpod.io", | ||
configuredHost: "gitpod.io", | ||
shouldRedirect: false, | ||
}, | ||
]; | ||
|
||
scenarios.forEach((scenario) => { | ||
const result = isApiSubdomainOfConfiguredHost(scenario.hostname, scenario.configuredHost); | ||
expect(result).to.equal( | ||
scenario.shouldRedirect, | ||
`${scenario.name}: Expected ${scenario.shouldRedirect} for ${scenario.hostname}`, | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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.