Skip to content

[Bug] CSRF middleware incorrectly blocks OpenAI-compatible /v1/ endpoints #149

Description

@ryuknull

Description

The CsrfGuard middleware applies to all state-changing HTTP methods (POST, PUT, DELETE, PATCH). While this is correct for management API routes (/api/*), it incorrectly blocks public-facing, OpenAI-compatible endpoints like POST /v1/chat/completions.

Standard LLM clients (OpenAI SDK, LangChain, etc.) do not support CSRF headers, leading to a csrf_missing error when attempting to use the gateway.

Affected Files

crates/infrastructure/transport-axum/src/middleware/csrf_guard.rs

Steps to Reproduce

  1. Start the server with CSRF enabled.
  2. Attempt a POST /v1/chat/completions request using a valid API key but no CSRF token.
  3. Observe the 403 Forbidden response with csrf_missing.

Proposed Fix

The middleware should skip CSRF validation for any path starting with /v1/.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions