fix(create-blocks-app): harden demo template against Set-Cookie CRLF injection and single-quote XSS#204
Merged
Merged
Conversation
…injection and single-quote XSS
svidgen
approved these changes
Jul 15, 2026
soberm
approved these changes
Jul 15, 2026
hfurkanbozkurt
enabled auto-merge (squash)
July 15, 2026 19:41
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.
Summary
Fixes two security defects in the
demotemplate of@aws-blocks/create-blocks-app, surfaced by a security bench-audit of the demo template. Both are minimal, focused hardening changes to template code that ships to every user who scaffolds thedemotemplate.Defect 1 — Set-Cookie header (CRLF) injection
The public (no
requireAuth)setCookie/deleteCookieAPI methods intemplates/demo/aws-blocks/index.tswrote a user-controlled cookiename/valuestraight into theSet-Cookieresponse header:A
name/valuecontaining CR (\r) or LF (\n) can inject additional response headers (HTTP response splitting / header injection).Fix: a small module-level
assertNoCrlf(value, field)guard rejects any component containing CR/LF, invoked forname+valueinsetCookieandnameindeleteCookiebefore the header is written.getCookie(read-only) is unchanged.Defect 2 — Incomplete HTML escaping (XSS via single quote)
escapeHtmlintemplates/demo/src/index.tsescaped&,<,>, and"but not the single quote ('). The helper is interpolated into single-quoted JS attribute contexts, e.g.:A
'in the interpolated value breaks out of the JS string literal → XSS.Fix: append
.replace(/'/g, ''')to the chain (&remains escaped first, so no double-encoding).Tests
src/cookie-crlf.test.ts— mirrors the guard + Set-Cookie builder; asserts valid headers build and that CRLF inname/value(plus bare CR, bare LF, anddeleteCookie) is rejected.src/escape-html.test.ts— mirror now escapes'; added "escapes single quotes" and "prevents single-quote attribute breakout" tests; the all-special-chars test now includes'.tscclean,node --test).Changeset
Added
.changeset/fix-demo-template-security.md(patchbump for@aws-blocks/create-blocks-app).Notes
escapeHtml; PR fix(create-blocks-app): decouple template E2E readiness from sample APIs #198 (open) touches only templatee2e.test.tsfiles (no overlap with these files).