Repository navigation
Description
What type of feature is this?
Add native CSRF (Cross-Site Request Forgery) origin validation to SecurityPolicy, following the same pattern as the existing CORS support.
What this feature does / why we need it:
Envoy has a built-in envoy.filters.http.csrf filter that validates the Origin header against allowed origins on mutating requests (POST, PUT, DELETE, PATCH). Currently, there's no way to configure this filter through Envoy Gateway without using EnvoyPatchPolicy.
This is a common production requirement — in our case, 74% of routes (1,395 out of 1,890) need CSRF with origin suffix matching.
Proposed API:
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: my-route
csrf:
additionalOrigins:
- type: Suffix
value: newrelic.com
- type: Exact
value: https://example.comImplementation approach:
The CSRF filter follows the exact same pattern as CORS in Envoy Gateway:
- API:
SecurityPolicy.csrfwithadditionalOrigins []StringMatch(reuses existingStringMatchtype) - IR:
CSRFstruct inSecurityFeatureswithAdditionalOrigins []*StringMatch - xDS: New
csrf.goimplementing thehttpFilterinterface — empty filter at HCM level, per-routeCsrfPolicyviatyped_per_filter_config
Envoy's CsrfPolicy proto supports:
filter_enabled— percentage of requests to check (default 100%)additional_origins—StringMatcherlist for allowed origins beyond the destinationshadow_enabled— audit mode without blocking
The initial implementation would expose additionalOrigins with full StringMatch support (Exact, Prefix, Suffix, RegularExpression). filter_enabled and shadow_enabled can be added later.
Behavior:
- CSRF only checks mutating methods (POST, PUT, DELETE, PATCH) — GET/HEAD always pass
- The
Originheader is matched against the request destination AND anyadditionalOrigins - Missing
Originheader on mutating requests → 403 - Non-matching
Origin→ 403
/cc @arkodg
Activity
albsga4 commentedon Apr 24, 2026
PR ready: #8836
Follows the exact CORS pattern — disabled at HCM level, enabled per-route via typed_per_filter_config. Supports Exact/Prefix/Suffix/RegularExpression origin matching.
github-actions commentedon May 26, 2026
This issue has been automatically marked as stale because it has not had activity in the last 30 days.