Skip to content

sec(api): PATCH requests skip CSRF validation (plans and ladder tranche edits) #1101

Open

Description

@IAmJSD

Found while documenting the API in #262 (PR #1100).

requiresCSRFValidation in internal/api/middleware.go only enforces CSRF on POST, PUT and DELETE:

// Only POST, PUT, DELETE need CSRF protection
if method != "POST" && method != "PUT" && method != "DELETE" {
    return false
}

Two routes change state through PATCH with AuthUser, so a session-authenticated request reaches them with no CSRF check:

  • PATCH /api/plans/{id} (patchPlanHandler, router.go:152)
  • PATCH /api/ladder/tranches/{id} (amendLadderTrancheHandler, router.go:334)

Suggested fix: treat every method except GET, HEAD and OPTIONS as state-changing, so future verbs are covered too. Add a test that a session PATCH without X-CSRF-Token is refused on both routes, plus a guard test that every non-safe-method route requires CSRF.

Activity

  1. IAmJSD commented on Oct 19, 2026

    @IAmJSD
    CollaboratorAuthor

    Claiming: working on this

  2. self-assigned this
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions