Skip to content

fix: implement OAuth CSRF protection with state validation#30

Merged
hrntknr merged 2 commits intomainfrom
fix/oauth-csrf-protection
Aug 18, 2025
Merged

fix: implement OAuth CSRF protection with state validation#30
hrntknr merged 2 commits intomainfrom
fix/oauth-csrf-protection

Conversation

@hrntknr
Copy link
Copy Markdown
Member

@hrntknr hrntknr commented Aug 18, 2025

Summary

Implements OAuth CSRF protection by adding proper state validation to prevent OAuth CSRF attacks. This addresses a high-severity security vulnerability where both OAuth providers used hardcoded static state values and lacked state validation in callback handlers.

Type of Change

  • fix: A bug fix

Related Issues

Fixes #27

- Generate cryptographically secure random state for OAuth requests
- Store OAuth state in session during authorization
- Validate state parameter in callback handlers
- Add GenerateState utility function for secure random generation

Fixes #27
Copilot AI review requested due to automatic review settings August 18, 2025 12:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements OAuth CSRF protection by adding proper state validation to prevent OAuth CSRF attacks. The changes replace hardcoded static state values with randomly generated states and add validation in callback handlers.

  • Adds a new utility function to generate cryptographically secure random OAuth state values
  • Updates OAuth provider interfaces to accept and validate state parameters
  • Implements state storage in session and validation during OAuth callbacks

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/utils/main.go Adds GenerateState() function to create random OAuth state values
pkg/auth/main.go Updates Provider interface and implements state generation/validation in OAuth flow
pkg/auth/google.go Updates Google OAuth provider to use dynamic state and validate it during exchange
pkg/auth/github.go Updates GitHub OAuth provider to use dynamic state and validate it during exchange

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread pkg/utils/main.go Outdated
@hrntknr hrntknr merged commit e1030ba into main Aug 18, 2025
4 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.

OAuth CSRF Attack

2 participants