Demo: shescape-based alternative to the H26-318 allowlist fix - #116
Open
junhoef wants to merge 1 commit into
Open
Demo: shescape-based alternative to the H26-318 allowlist fix#116junhoef wants to merge 1 commit into
junhoef wants to merge 1 commit into
Conversation
…ist (H26-318) Alternative to the regex-allowlist fix in #115. Validates redirectValue is a genuine https URL with the native URL class, then lets shescape quote/escape both Prismic-controlled values for safe embedding in bin/redirects.sh - removing the need to enumerate every safe character by hand (which is how the query-string regression in #115 happened). Pinned to shescape@2.1.14: v3 dropped CommonJS support (this package builds to CJS via Babel for require()-based consumers) and v1.x has known CVEs, including a critical one, in the version ranges below 2.1.14.
shackpank
reviewed
Aug 5, 2026
shackpank
left a comment
Member
There was a problem hiding this comment.
Seems good, but is sort of a symptom of one project generating shell code for a different project to execute (https://github.com/holidayextras/ssg-toolbox/blob/50bc65dc559532f4e860e54f467d3f0f9a2a8ce3/bin/deployment.sh#L105)?
ie this wouldn't be needed if instead we did something like, write a redirects.json, and ssg-toolbox picks up, uses the S3 javascript sdk to make the requested changes...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This is not meant to be merged — it's a side-by-side alternative to #115 for comparison, showing what the H26-318 command-injection fix looks like using a library instead of a hand-rolled character allowlist.
src/writeRedirect.jsstill validatesredirectValueis a genuinehttps:URL (via the nativeURLclass), but instead ofSAFE_PAGE_URL/SAFE_REDIRECT_URLregexes, it usesshescapeto quote/escape both Prismic-controlled values before they're embedded inbin/redirects.sh. Since escaping works on the actual string content rather than a pre-approved character set, this sidesteps the exact class of regression found in #115 (a real production redirect using a UTM query string was silently rejected because?/&/=weren't in the allowlist).Pinned to
shescape@2.1.14specifically:shescape@3.xdropped CommonJS support entirely (pure ESM) — this package builds to CJS via Babel forrequire()-based consumers (ssg-hx-uk,ssg-paultonsbreaks, etc.), so a v3 dependency would throwERR_REQUIRE_ESMat runtime for every downstream consumer.shescape@1.xhas known CVEs, including one rated critical.2.1.14is the earliest version with all known advisories patched and still ships arequireexport condition.What tests does this PR have?
Rewrote
test/writeRedirect.test.js(11 unit tests) against the shescape-based implementation:ssg-paultonsbreaks's productionbin/redirects.sh)uidfallback whenslugis absentHow can this be tested?
All 19 tests pass (8 pre-existing
simulate-request+ 11 newwriteRedirect).Also validated against every unique redirect URL and page slug that exists in
ssg-paultonsbreaks's real, checked-inbin/redirects.sh(production data) — all pass.Any tech debt?
None new, but worth flagging for whoever compares this against #115:
shescape'squote()wraps the whole value in shell quotes, so the command template had to change from"s3://$BUCKET/${pageUrl}.html"(one big double-quoted string) to"s3://$BUCKET/"${safePageUrl}".html"(adjacent quoted segments concatenated by bash) so$BUCKETstill expands at deploy time while the Prismic-controlled segment stays fully quoted. This is a bit less readable than the single-string-with-regex-validation approach in #115.What gif best describes how you feel?
https://media.giphy.com/media/xUOxf48UtjF3O7HYUE/giphy.gif
For reviewer