Skip to content

Conversation

@perber
Copy link
Owner

@perber perber commented Dec 30, 2025

No description provided.

Copy link
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 CSRF (Cross-Site Request Forgery) protection for the application by adding CSRF tokens to authentication flows and protected endpoints. The implementation reorganizes middleware into separate auth and security packages, introduces a new CSRF cookie mechanism, and updates both backend and frontend code to handle CSRF tokens.

Key changes:

  • Implements CSRF token generation, validation, and middleware protection
  • Reorganizes middleware code into auth and security subpackages with a shared utils package
  • Integrates CSRF token issuance in login, logout, and token refresh flows

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
internal/http/middleware/security/csrf.go New CSRF middleware that validates tokens for mutating HTTP methods
internal/http/middleware/security/csrf_cookie.go Manages CSRF cookie lifecycle (issue, read, clear) with secure/insecure modes
internal/http/middleware/security/csrf_test.go Tests for CSRF middleware validation logic
internal/http/middleware/security/csrf_cookie_test.go Tests for CSRF cookie operations
internal/http/middleware/security/rate_limiter.go Moved rate limiter to security package
internal/http/middleware/security/rate_limiter_test.go Updated package declaration for rate limiter tests
internal/http/middleware/auth/auth.go Moved authentication middleware to auth package
internal/http/middleware/auth/auth_cookie.go Refactored to use shared RequireSecure utility
internal/http/middleware/auth/auth_cookie_test.go Updated tests to use utils.RequireSecure
internal/http/middleware/utils/require_secure.go Extracted shared logic for HTTPS detection
internal/http/router.go Updated imports and integrated CSRF middleware into protected routes
internal/http/api/login_user.go Added CSRF token issuance on successful login
internal/http/api/logout_user.go Added CSRF token clearing on logout
internal/http/api/refresh_token_user.go Added CSRF token issuance on token refresh
ui/leafwiki-ui/src/lib/api/auth.ts Added CSRF token extraction from cookies and inclusion in API requests
Comments suppressed due to low confidence (1)

internal/http/middleware/auth/auth_cookie.go:1

  • The package declaration is incorrect. This file is in the internal/http/middleware/auth/ directory and is imported as auth_middleware, so it should declare package auth instead of package middleware.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@perber perber force-pushed the feature/csrf-protection branch from 34fdd11 to 8f41e1e Compare December 30, 2025 19:44
perber and others added 2 commits December 30, 2025 20:45
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@perber perber force-pushed the feature/csrf-protection branch 2 times, most recently from d699da5 to d62aa2d Compare December 30, 2025 20:06
Copy link
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

Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

internal/http/middleware/auth/auth_cookie.go:1

  • The package declaration is package middleware but the file is in the internal/http/middleware/auth/ directory. The package name should be auth to match the directory structure and import alias used in router.go. This inconsistency will cause import issues.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

perber and others added 2 commits December 30, 2025 21:21
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@perber perber force-pushed the feature/csrf-protection branch from 68762af to 25a5aea Compare December 30, 2025 20:42
@perber perber merged commit 625a9c9 into releases/v0.7.0 Dec 30, 2025
5 checks passed
@perber perber deleted the feature/csrf-protection branch December 30, 2025 20:47
perber added a commit that referenced this pull request Jan 3, 2026
perber added a commit that referenced this pull request Jan 4, 2026
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