Skip to content

fix(config): correctly validate cacheHandlers names - #95358

Merged
unstubbable merged 1 commit into
vercel:canaryfrom
Partha-Shankar:fix-cachehandlers-validation
Jul 2, 2026
Merged

unstubbable merged 1 commit into
vercel:canaryfrom
Partha-Shankar:fix-cachehandlers-validation

Conversation

@Partha-Shankar

Copy link
Copy Markdown
Contributor

What?

The current cacheHandlers validation uses /[a-z-]/, which only checks whether a key contains at least one lowercase letter or hyphen.

As a result, invalid keys such as abc123, abc_123, abc.def, and handler! are accepted even though they contain characters outside the documented allowed set.

Why?

The validation error states that handler names must only contain a-z and -, but the current implementation does not enforce that constraint because the regex is not anchored.

How?

  • Replace /[a-z-]/ with /^[a-z-]+$/ so the entire handler name is validated.
  • Add regression tests covering both valid and invalid handler names.

Testing

  • Added regression tests in packages/next/src/server/config.test.ts.

@unstubbable
unstubbable force-pushed the fix-cachehandlers-validation branch from e512a66 to 78277a4 Compare July 2, 2026 13:55
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Stats cancelled

Commit: 78277a4
View workflow run

@github-actions

github-actions Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 78277a4

@unstubbable unstubbable left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@unstubbable
unstubbable merged commit 8688f98 into vercel:canary Jul 2, 2026
218 of 221 checks passed
m-kawafuji pushed a commit to m-kawafuji/next.js that referenced this pull request Aug 8, 2026
## What?

The current `cacheHandlers` validation uses `/[a-z-]/`, which only
checks whether a key contains at least one lowercase letter or hyphen.

As a result, invalid keys such as `abc123`, `abc_123`, `abc.def`, and
`handler!` are accepted even though they contain characters outside the
documented allowed set.

## Why?

The validation error states that handler names must only contain `a-z`
and `-`, but the current implementation does not enforce that constraint
because the regex is not anchored.

## How?

- Replace `/[a-z-]/` with `/^[a-z-]+$/` so the entire handler name is
validated.
- Add regression tests covering both valid and invalid handler names.

## Testing

- Added regression tests in `packages/next/src/server/config.test.ts`.

<!-- NEXT_JS_LLM_PR -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants