Skip to content

Harden Netlify remotePatterns regex to match canonical wildcard semantics - #17018

Merged
matthewp merged 2 commits into
mainfrom
fix/netlify-remote-pattern-regex
Jun 10, 2026
Merged

matthewp merged 2 commits into
mainfrom
fix/netlify-remote-pattern-regex

Conversation

@matthewp

@matthewp matthewp commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • Tightens the regex produced by remotePatternToRegex so wildcard hostname and pathname patterns match strictly:
    • *. requires exactly one subdomain (bare apex no longer matches)
    • **. requires one or more subdomains (zero subdomains no longer matches)
    • /* matches a single path segment only, not deeper paths
  • Anchors the generated regex with $ so partial prefix matches are not possible

Testing

  • Updated existing assertion: *.example.org no longer matches bare example.org
  • Added assertion: /images/* does not match /images/a/b.jpg

Docs

  • No docs update needed -- this is an internal regex generation change with no user-facing API impact.

…egex

The generated regexes for Netlify Image CDN's remote_images config were
broader than Astro's canonical matchHostname/matchPathname helpers:

- *.host patterns used '?' (optional subdomain), allowing the apex host.
  Changed to required group so exactly one subdomain is required.
- **.host patterns used '*' (zero or more), allowing the apex host.
  Changed to '+' so at least one subdomain is required.
- Pathname regexes lacked an end anchor, so .test() could match a URL
  prefix (e.g. /ok/a inside /ok/a/b.jpg). Added '$' anchor.
- The /** and /* branches were not mutually exclusive (if/if instead of
  if/else if), causing /** to emit a redundant second group.
@changeset-bot

changeset-bot Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e02b189

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@astrojs/netlify Patch
@test/netlify-session Patch
@test/netlify-hosted-astro-project Patch

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

@github-actions github-actions Bot added the pkg: integration Related to any renderer integration (scope) label Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Dependency Count

This PR adds 41 new dependencies (2154 → 2195), which exceeds the threshold of 10.

⚠️ Package Trust Level Decreased

Caution

Decreased trust levels may indicate a higher risk of supply chain attacks. Please review these changes carefully.

📦 Package 🔒 Before 🔓 After
@smithy/core trusted-with-provenance none
@smithy/fetch-http-handler trusted-with-provenance none
@smithy/signature-v4 trusted-with-provenance none
@smithy/credential-provider-imds trusted-with-provenance none

@matthewp matthewp changed the title fix(netlify): harden remotePatterns regex generation Harden Netlify remotePatterns regex to match canonical wildcard semantics Jun 9, 2026
@matthewp
matthewp merged commit 1310277 into main Jun 10, 2026
24 checks passed
@matthewp
matthewp deleted the fix/netlify-remote-pattern-regex branch June 10, 2026 13:15
@astrobot-houston astrobot-houston mentioned this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants