You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: implement CSRF protection for OAuth flows with nonce validation (#20983)
* feat: implement CSRF protection for OAuth flows with nonce validation
- Add NonceService for cryptographically secure nonce generation and validation
- Include nonce in JWT state for OAuth authorization requests
- Store nonce in secure httpOnly cookie with SameSite=strict
- Validate nonce matches between state and cookie in auth callback
- Add origin/referer header validation for additional CSRF protection
- Use timing-safe comparison to prevent timing attacks
- Clear nonce cookie after successful validation or on error
This prevents CSRF attacks where malicious sites could initiate OAuth flows
on behalf of users by ensuring authorization requests originate from Gitpod.
Co-authored-by: Ona <[email protected]>
* refactor: consolidate fragment protection and fix context provider conflict
Co-authored-by: Ona <[email protected]>
* fix: handle GitHub OAuth api subdomain edge case with secure redirect
Co-authored-by: Ona <[email protected]>
* fix: simplify api subdomain redirect test to avoid dependency injection complexity
Replace complex Authenticator dependency injection test with simple unit test
that focuses on the core logic without requiring all service dependencies.
This makes the test more reliable and easier to maintain while still validating
the critical api subdomain detection logic for the GitHub OAuth edge case.
Co-authored-by: Ona <[email protected]>
* docs: update domain examples to use gitpod.io instead of preview domains
Update test examples and documentation to use production-appropriate
domain examples (gitpod.io) instead of specific preview environment
domains for better clarity and maintainability.
Co-authored-by: Ona <[email protected]>
* fix cookie
Co-authored-by: Ona <[email protected]>
* Update authenticator.ts
Co-authored-by: Copilot <[email protected]>
* Update authenticator.ts
Co-authored-by: Copilot <[email protected]>
* minor stuff
* cleanup old redirect logic
* cleanup
* 1
Co-authored-by: Ona <[email protected]>
* feat: add feature flags for nonce validation and strict authorize returnTo
Add two feature flags to control security features with safe defaults:
**Feature Flag 1: enable_nonce_validation (default: false)**
- Controls CSRF nonce validation in OAuth flows
- When disabled: Nonce is generated but not validated (future compatibility)
- When enabled: Full CSRF protection with nonce and origin validation
- Nonce cookies are always generated and cleared for consistency
**Feature Flag 2: enable_strict_authorize_return_to (default: false)**
- Controls returnTo validation strictness for /api/authorize endpoint
- When disabled: Falls back to login validation (broader patterns)
- When enabled: Uses strict authorize validation (limited to specific paths)
- /api/login always uses login validation regardless of flag
**Implementation Details:**
- Always generate nonce for consistency and future compatibility
- Only validate nonce when feature flag is enabled
- Always clear nonce cookies regardless of validation state
- Authorize endpoint checks flag and falls back gracefully
- Comprehensive logging for debugging and monitoring
**Backward Compatibility:**
- Default false ensures no breaking changes
- Gradual rollout possible via feature flag configuration
- Existing authentication flows continue to work
- Safe fallback behavior when flags are disabled
Co-authored-by: Ona <[email protected]>
* fix: validate OAuth callback origin against SCM provider domain
Update NonceService.validateOrigin to check request origin against the
expected SCM provider domain instead of Gitpod's own domain. This fixes
the CSRF protection logic for OAuth callbacks which legitimately come
from external providers (github.com, gitlab.com, etc.).
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
* 1
* remove the origin check logic
* update sorry url
* move files
* use safeRedirect for redirect
* 1
* [server] minor refactor/renames
* moah changes
---------
Co-authored-by: Ona <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Gero Posmyk-Leinemann <[email protected]>
Co-authored-by: Claude <[email protected]>
0 commit comments