Repository navigation
fix(core): reject URL patterns with several placeholders in one segment - #3303
Conversation
Two `([^/]+)` groups in one path segment can split it many ways, so
`resolveEmDashPath` backtracked catastrophically on crafted anonymous
paths (~8 s for `/{a}{b}{c}{d}{e}x` against a 200-char path). A literal
separator does not help: `[^/]+` also matches the literal, so
`/{a}-{b}-{c}x` is still polynomial. Requiring a `/` between
placeholders pins each group to its own segment and keeps matching linear.
- compileUrlPattern throws for multiple placeholders in a segment
- zod create/update bodies surface the specific message
- SchemaRegistry validates on create, seed create, and on update when the
pattern changes (unchanged stored patterns survive round-trips)
- validateSeed rejects such patterns before any seed writes
- resolveEmDashPath skips invalid stored patterns with a warning per
cache build instead of throwing on every request
- admin editor flags the pattern inline and disables save
🦋 Changeset detectedLatest commit: 2bf64fe The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
docs | 0ec2744 | Sep 27 2026, 01:29 PM |
There was a problem hiding this comment.
The core ReDoS fix is solid: compileUrlPattern now rejects two or more placeholders in the same path segment, resolveEmDashPath skips invalid stored patterns with a warning, and seeds/admin/REST/MCP schemas reject ambiguous patterns on write. Tests cover the DoS, the new validation rule, and seed rejection.
The main issue is that the changeset/docs promise an unchanged-invalid-pattern round-trip for API updates, but the implementation doesn't deliver it. The updateCollectionBody Zod schema validates urlPattern before the handler runs, so the registry's new unchanged-pattern bypass is unreachable from the REST route and the MCP tool. The admin component also always sends urlPattern on save, so it can't benefit from any such round-trip either. The registry bypass is essentially dead code in production.
Also note that validateSeed runs before applySeed writes anything, so the seed path won't exercise the registry bypass for invalid patterns either.
I recommend either (a) updating the changeset/docs to match the actual behavior (API callers must omit urlPattern, not echo the invalid one) and removing/simplifying the unreachable registry bypass, or (b) moving the unchanged-pattern tolerance into the REST/MCP layers so the documented round-trip actually works. If (b), add integration tests for a REST or MCP update that echoes an existing invalid pattern.
| // A stored pattern that fails validation must survive round-trips of unrelated edits. | ||
| if (input.urlPattern !== existingRow.url_pattern) this.validateUrlPattern(input.urlPattern); |
There was a problem hiding this comment.
[needs fixing] This bypass is meant to let an existing invalid urlPattern survive round-trip updates, but it is unreachable from the production API/MCP paths. Both the REST route (packages/core/src/astro/routes/api/schema/collections/[slug]/index.ts:52) and the MCP tool (packages/core/src/mcp/server.ts:2062-2069) parse the request with updateCollectionBody first, and urlPatternValue.superRefine rejects ambiguous patterns unconditionally before handleSchemaCollectionUpdate is called. Seeds don't reach this either because validateSeed rejects the pattern before applySeed invokes the registry. Either move this unchanged-pattern tolerance into the API/MCP layer so it is actually exercised, or remove it and update the changeset/docs to say callers must omit urlPattern for unrelated edits.
|
|
||
| Collection URL patterns now allow at most one placeholder per path segment. `/{year}/{month}/{slug}.html` and `/p-{id}/{slug}` are still valid, but `/{year}{month}/{slug}` and `/{slug}-{id}` are rejected when a collection is created or its pattern is changed through the admin, the REST API, the MCP `schema_update_collection` tool, or a seed. Seed files with such a pattern fail validation before anything is applied. The admin's collection editor shows the problem next to the URL Pattern field. | ||
|
|
||
| If a collection already has a pattern that breaks this rule, it keeps working for generating links in menus, sitemaps and redirects, but `resolveEmDashPath()` no longer matches it, and the site logs a warning naming the collection. API updates that send the stored pattern back unchanged still succeed. Give each placeholder its own segment (for example, change `/{slug}-{id}` to `/{id}/{slug}`) to route those entries again. The admin won't save changes to that collection until the pattern is fixed. |
There was a problem hiding this comment.
[needs fixing] The sentence "API updates that send the stored pattern back unchanged still succeed" does not match the actual flow. Because updateCollectionBody validates urlPattern before the registry bypass can compare it to the stored value, a REST or MCP update that echoes the existing invalid pattern is rejected with a 400. The admin editor also always sends the pattern, so it cannot round-trip an invalid one. Update this changeset (and the matching docs, if any) to reflect the actual behavior: the stored pattern is preserved only when the caller omits urlPattern or the registry is called directly.
| expect(await registry.getCollection("pages")).toBeNull(); | ||
| }); | ||
|
|
||
| it("keeps an unchanged stored pattern when other collection settings are updated", async () => { |
There was a problem hiding this comment.
[suggestion] This test only covers direct registry.updateCollection calls, which is the one path that exercises the unchanged-pattern bypass. Consider adding REST/MCP integration tests that echo an existing invalid urlPattern so the intended round-trip behavior is actually verified where users will hit it. That will also prevent the changeset/docs drift seen here.
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
The redirect middleware now only issues redirects to single-slash site-relative paths. Rows whose destination has a scheme, a `//` or `/\` prefix, or control characters (browsers strip tab/CR/LF, so `/\t/host` resolves as `//host`) are logged and skipped. Seeds, plugins with direct DB access, and manual DB edits could previously store an open redirect. compilePattern now escapes every regex metacharacter in literal text, including parentheses. Before, a literal `(...)` survived as live regex syntax: `/(.*.*.*x)/[p]` backtracked catastrophically on ordinary paths, and an unbalanced `(` threw during cache compilation, which disabled every redirect on the site. The rewrite also collects param names in source order, fixing swapped captures for `/[category]/[...rest]`. The redirect cache skips stored pattern rows that fail validatePattern, and seed validation now runs validatePattern, validateDestinationParams and the site-relative destination check, matching the redirects API.
# Conflicts: # packages/core/src/seed/validate.ts
# Conflicts: # packages/core/src/seed/validate.ts
The catalog extraction after emdash-cms#1939 and emdash-cms#3303 added five admin strings: the dashboard's core update notice and the error for a URL pattern with two placeholders in one path segment. German admins would have seen them in English on every site that has an update waiting. The changeset now names the update notice, the invitation emails and the unpublish term switch (depublizieren to zurückziehen).
* i18n(de): translate the taxonomy picker, link picker and plugin draft review The German admin catalog had fallen 72 entries behind after the taxonomy sidebar, link search, content validation messages and the plugin editor-draft and release verification work landed. German-speaking editors saw English in the taxonomy picker and when deleting a taxonomy, the publish confirmation, the URL and language settings, the link and code block language pickers, save validation errors and the save-conflict message, the plugin consent dialog's editor-content warning and release verification, the review dialog for plugin-proposed changes, and the registry's install errors. Validation messages quote the field label, because a label can be plural or German and the quoted form keeps the verb agreeing either way. The code block's "Set language" button now reads "Sprache festlegen" instead of "Sprache speichern": it opens the language choice and saves nothing. * i18n(de): complete the German admin and settle its terminology Upstream added about 550 admin strings since the last German pass, in site transfer, content relations, bulk term assignment, the bylines directory, block types and CLI device sign-in. German-speaking editors saw them in English. A review of the 2,400 older entries against their source found mistranslations (a passkey name read as a user name, Integer and Number both shown as "Zahl"), calques and one-off terms. The catalog now uses one term per concept: Plugin, Sammlung, veröffentlichen, löschen for delete and entfernen for remove, Beziehung for content relations. Progress messages use the passive, buttons the infinitive, and quotes German quotation marks. * i18n(de): translate the core update notice and the URL pattern error The catalog extraction after #1939 and #3303 added five admin strings: the dashboard's core update notice and the error for a URL pattern with two placeholders in one path segment. German admins would have seen them in English on every site that has an update waiting. The changeset now names the update notice, the invitation emails and the unpublish term switch (depublizieren to zurückziehen).
What does this PR do?
Fixes a ReDoS in public URL routing.
compileUrlPatternturns every collectionurl_patternplaceholder into([^/]+), andresolveEmDashPathmatches anonymous request paths against the result. When a pattern puts several placeholders in one path segment (/{a}{b}{c}{d}{e}x), the regex can split that segment in a huge number of ways. Before this change, one 200-character path took ~8 s to match. Anyone with schema access can set such a pattern through the normal collection create/update APIs.Putting a literal between the placeholders doesn't help, because
[^/]+also matches the literal. For example,/{a}-{b}-{c}xtakes 170 ms on a 1,000-character path and grows polynomially. This PR therefore uses a stricter rule: at most one placeholder per path segment. Each group can then only backtrack inside its own segment against a fixed-length literal, so matching is linear. An adversarial review pass measured 0.1–1.4 ms on 20k–60k-character paths.Where the rule is enforced:
compileUrlPatternthrowsURL patterns allow only one placeholder per path segment.schema_update_collectiontool) now show that message instead of a generic "Invalid URL pattern".SchemaRegistry.createCollection/createSeedCollectionreject such patterns withSchemaErrorINVALID_URL_PATTERN.updateCollectionrejects them only when the pattern changes.validateSeedrejects them, so a seed fails before anything is written.Existing stored patterns:
resolveEmDashPathnow skips a stored pattern that fails to compile andconsole.warns once per cache build, rather than throwing on every request. Before this change, any stored pattern that failed to compile (for example, one with a stray brace) broke routing for every collection. Outbound link generation (menus, sitemaps, redirects, hreflang) only substitutes values into the pattern, so it keeps working. API updates that send an unchanged stored pattern back still succeed, which keeps REST/MCP round-trips and seed re-applies withonConflict: "update"working on legacy sites.Compatibility trade-off to review: patterns like
/{slug}-{id}and/{year}{month}/{slug}could be saved before and are now rejected. On sites that already have one,resolveEmDashPathstops matching it. I found no such pattern anywhere in the repo's seeds, templates, docs, or the WordPress importer. If compact date forms turn out to matter, a follow-up could give the date tokens fixed-width regexes (\d{4},\d{2}), which would make{year}{month}safe without a separate segment.Out of scope, filed separately: seed-file redirect patterns skip
validatePattern, and/[a][b][c][d][e]xtakes ~41 s against a 200-character path in the redirect cache. It's the same bug class in a different subsystem.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change): fullpackages/coresuite (7369 passed) andContentTypeEditoradmin testspnpm formathas been run (on touched files)messages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
The collection editor with
/blog/{year}{slug}entered. The inline error appears and Save is disabled:The same state in Arabic (RTL). The message shows in English until the catalogs are extracted on merge:
Regression test before the fix (stored
/{a}{b}{c}{d}{e}x, 200-character path throughresolveEmDashPath):