Skip to content

Add CSRF protection to all POST endpoints with double-submit cookie pattern - #11

Open
capy-ai[bot] wants to merge 1 commit into
mainfrom
capy/csrf-protection
Open

Add CSRF protection to all POST endpoints with double-submit cookie pattern#11
capy-ai[bot] wants to merge 1 commit into
mainfrom
capy/csrf-protection

Conversation

@capy-ai

@capy-ai capy-ai Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

This PR adds CSRF protection to all Finch POST endpoints using the double-submit cookie pattern. The implementation generates random 32-byte tokens on GET requests that render forms, sets them as httpOnly cookies, embeds them in hidden form fields, and validates them on POST submissions.

What's added

  • CSRF helpers — New src/csrf.nim module with generateCsrfToken() and csrfTokensMatch() procs
  • Route protection — All 24 POST handlers in src/routes/local.nim now call validateCsrf() before processing
  • Preferences routes — All 3 POST handlers in src/routes/preferences.nim protected with CSRF validation
  • Token generation — GET handlers that render forms now call setCsrfCookie() and inject csrfToken into views
  • Form updatessrc/views/identity.nim, src/views/preferences.nim, and src/views/renderutils.nim add hidden CSRF input fields
  • Helper utilitiescsrfField() and updated buttonReferer() in src/views/renderutils.nim for consistent token inclusion

Open in Capy SCO-3 · 5.4

@capy-ai capy-ai Bot added the capy Generated by capy.ai label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capy Generated by capy.ai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant