Skip to content

security: validate OAuth state parameter to prevent CSRF attacks#406

Merged
its-me-abhishek merged 1 commit intomainfrom
security/oauth-state-validation
Jan 19, 2026
Merged

security: validate OAuth state parameter to prevent CSRF attacks#406
its-me-abhishek merged 1 commit intomainfrom
security/oauth-state-validation

Conversation

@cfsmp3
Copy link
Copy Markdown
Collaborator

@cfsmp3 cfsmp3 commented Jan 19, 2026

Summary

  • Generate cryptographically secure random state per OAuth request using crypto/rand
  • Store state in session and validate in callback to prevent CSRF attacks
  • Clear state after validation (one-time use)
  • Log warnings for state mismatches

Security Issue Addressed

OAuth State Not Validated (High) - Previously used hardcoded "state" parameter, making the OAuth flow vulnerable to CSRF attacks. An attacker could potentially trick a user into logging into the attacker's account.

Changes

  • backend/controllers/app_handlers.go:
    • Add generateOAuthState() function for secure random state generation
    • Update OAuthHandler to generate and store state in session
    • Update OAuthCallbackHandler to validate state before processing callback

Test plan

  • Test OAuth login flow works correctly
  • Verify state is validated (tampering with state should fail)
  • Verify expired/missing state is rejected

🤖 Generated with Claude Code

Generate cryptographically secure random state per OAuth request and
validate it in the callback to prevent cross-site request forgery.

- Add generateOAuthState() using crypto/rand for secure random generation
- Store state in session before redirect to OAuth provider
- Validate state in callback matches stored value
- Clear state after validation (one-time use)
- Log warnings for state mismatches

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Thank you for opening this PR!

Before a maintainer takes a look, it would be really helpful if you could walk through your changes using GitHub's review tools.

Please take a moment to:

  • Check the "Files changed" tab
  • Leave comments on any lines for functions, comments, etc. that are important, non-obvious, or may need attention
  • Clarify decisions you made or areas you might be unsure about and/or any future updates being considered.
  • Finally, submit all the comments!

More information on how to conduct a self review:
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request

This helps make the review process smoother and gives us a clearer understanding of your thought process.

Once you've added your self-review, we'll continue from our side. Thank you!

@its-me-abhishek its-me-abhishek merged commit 48d7505 into main Jan 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants