Skip to content

fix: b64 encode props with URL-sensitive characters#530

Merged
harlan-zw merged 1 commit intomainfrom
worktree-fix-special-chars-529
Mar 23, 2026
Merged

fix: b64 encode props with URL-sensitive characters#530
harlan-zw merged 1 commit intomainfrom
worktree-fix-special-chars-529

Conversation

@harlan-zw
Copy link
Copy Markdown
Collaborator

🔗 Linked issue

Fixes #529, fixes #528

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

Props containing URL-sensitive characters (#, ?, /, \, =, &, ,, etc.) were percent-encoded by encodeURIComponent, producing %23, %3F, etc. in the URL path. Intermediaries (proxies, CDNs, h3, prerender crawlers) decode these unpredictably, breaking URL parsing. ? becomes a query delimiter, # becomes a fragment, / splits the path segment.

The fix: after encodeURIComponent, if the result contains %, use the existing ~<b64> encoding path instead. This eliminates percent-encoded characters from URLs entirely while keeping simple ASCII values human-readable.

Impact on #529: Characters like #, ?, \ in defineOgImage props no longer break image generation.

Impact on #528: Full image URLs as props (e.g. https://images.prismic.io/xxx/img.png?auto=format,compress) are now preserved intact through encoding/decoding.

Backward compatible: the decoder already handles both %-encoded (legacy) and ~-prefixed (b64) values.

Adds 38 new tests including stress tests for path injection, extension confusion, param injection, null bytes, every ASCII special character, and verifies encoded output never contains raw #, ?, /, \, =, &, or %.

Props containing characters like #, ?, /, \, =, & produce percent-encoded
sequences (%23, %3F, etc.) that get decoded by proxies, CDNs, and prerender
crawlers, breaking URL parsing. Now these values use the existing ~<b64>
encoding path instead, eliminating percent-encoded characters from URLs.

Fixes #529, fixes #528
@harlan-zw harlan-zw changed the title fix(encoding): b64 encode props with URL-sensitive characters fix: b64 encode props with URL-sensitive characters Mar 23, 2026
@harlan-zw harlan-zw merged commit 6e8f49e into main Mar 23, 2026
6 checks passed
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.

fix: cannot generate images when properties passed to defineOgImage contain some special chars fix: image urls als props

1 participant