mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #87] [MERGED] fix: resolve CodeQL security alerts (ReDoS, incomplete sanitization) #297
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#297
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/87
Author: @dknecht
Created: 2/26/2026
Status: ✅ Merged
Merged: 2/26/2026
Merged by: @southpolesteve
Base:
main← Head:fix/codeql-security-alerts📝 Commits (1)
60f28d2fix: resolve CodeQL security alerts (ReDoS, incomplete sanitization, bad code gen)📊 Changes
9 files changed (+295 additions, -98 deletions)
View changed files
📝
packages/vinext/src/config/config-matchers.ts(+117 -35)📝
packages/vinext/src/index.ts(+62 -42)📝
packages/vinext/src/server/middleware-codegen.ts(+13 -7)📝
packages/vinext/src/server/middleware.ts(+21 -12)📝
tests/e2e/app-router/isr.spec.ts(+7 -1)📝
tests/font-google.test.ts(+1 -0)📝
tests/rsc-streaming.test.ts(+1 -0)📝
tests/safe-json.test.ts(+4 -1)📝
tests/shims.test.ts(+69 -0)📄 Description
Summary
Resolves all 26 open CodeQL code scanning alerts from https://github.com/cloudflare/vinext/security/code-scanning.
Production code fixes (3 files)
Single-pass tokenizers replace chained
.replace()— CodeQL flagged chained string replacements as incomplete sanitization since later passes could re-process earlier outputs. Refactored to single-pass regex tokenizer loops in:matchConfigPattern()in bothconfig-matchers.tsandindex.ts(alerts #25-28, #30-33, #50)matchMiddlewarePattern()inlined in the prod server entry template (same pattern as alert #29)matchPattern()inmiddleware.ts(alert #29)New
escapeHeaderSource()helper — shared single-pass converter for Next.js header/rewrite/redirect source patterns, used bymatchHeaders()andapplyHeaders(). Correctly handles:param(constraint)patterns (improvement over old code which silently dropped constraints).Additional fixes:
decodeURIComponentparity:index.tscatch-all matcher now decodes percent-encoded values, matchingconfig-matchers.tsbehavior[^/:..]+→[^/:.]+lgtmsuppression + safety comment forJSON.stringifycode gen (alert #35)Test file suppressions (5 files)
Added
lgtm[js/redos],lgtm[js/bad-tag-filter], andlgtm[js/incomplete-sanitization]comments for confirmed false positives:New tests
9 unit tests for
escapeHeaderSourcecovering literal paths, dot escaping, named params, glob star, plus/question escaping, constrained params, alternation groups, standalone groups, and multiple groups.Verification
pnpm run typecheck— cleanpnpm run lint— cleanpnpm vitest run— 731 tests pass across affected suites🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.