mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #821] [MERGED] fix: use segment-based domain matching for CSRF origin wildcard patterns #871
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#871
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/821
Author: @southpolesteve
Created: 4/11/2026
Status: ✅ Merged
Merged: 4/12/2026
Merged by: @james-elicx
Base:
main← Head:fix/csrf-origin-wildcard-matching📝 Commits (1)
a091e1ffix: use segment-based domain matching for CSRF origin wildcard patterns📊 Changes
2 files changed (+123 additions, -6 deletions)
View changed files
📝
packages/vinext/src/server/request-pipeline.ts(+47 -6)📝
tests/shims.test.ts(+76 -0)📄 Description
Summary
Replace suffix-based wildcard origin matching with proper segment-by-segment DNS domain matching for server action CSRF origin validation.
Details
isOriginAllowed()usedString.endsWith()for wildcard patterns, so*.example.comwould match any hostname ending with.example.com, includingevil.example.com.attacker.com.The new
matchWildcardDomain()implementation splits both domain and pattern by.and compares segment-by-segment from right to left:*matches exactly one DNS label**matches one or more DNS labels*or**alone)Ported from Next.js:
csrf-protection.tscsrf-protection.test.tsTests
12 unit tests ported from Next.js covering:
*)**)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.