fix(security): strip fake BEGIN UNTRUSTED markers from page content - #30
Conversation
) Add a second replace in wrapUntrustedPageContent() to neutralize [BEGIN UNTRUSTED PAGE CONTENT nonce=] patterns injected by attacker-controlled pages, symmetric with the existing [END UNTRUSTED nonce=] strip. Without this, a malicious page could inject a fake opening marker to confuse downstream parsers into treating attacker-controlled content as a trusted wrapper frame. Also update JSDoc to document both strips.
RapierCraft
left a comment
There was a problem hiding this comment.
APPROVED: commit 10afaf2 after context-aware security review (1 agent: General Security). 0 findings.
Security Review
Reviewed: src/index.ts — wrapUntrustedPageContent()
Fix verified correct:
- The new
.replace(/\[BEGIN UNTRUSTED PAGE CONTENT nonce=/g, "[BEGIN_UNTRUSTED_PAGE_CONTENT_nonce=")(lines 76-79) correctly neutralizes fake opening markers in attacker-controlled content - The existing
.replace(/\[END UNTRUSTED nonce=/g, "[END_UNTRUSTED_nonce=")(line 80) retains the END strip - Crucially: both replaces run on
body(the input content) BEFORE the real markers are joined in at lines 82-84. The real markers use a runtime-generated${nonce}value and are never affected by the strip patterns - No injection risk, no secrets, no new env vars, no infrastructure changes
- Prettier reformatting in other parts of the file is cosmetic — no logic changes
Automated checks: TypeScript build passes, Prettier formatting passes, no secrets detected.
Safe to merge.
|
APPROVED: commit 10afaf2 after context-aware security review (1 agent: General Security). 0 findings. Safe to merge. |
PR Review Summary: #30 - fix(security): strip fake BEGIN UNTRUSTED markers from page contentReview IntegrityReviewed commit: Verdict: APPROVEDContext-Aware ReviewDomains: Security (UNTRUSTED_INPUT_PROCESSING) | Agents: 1 (General Security inline review) Integration Checks (Phase 2.5)Code registration: pass — single-function change, all 8+ call sites in same file, no registration needed Risk Matrix
FindingsNo findings — review is clean. Automated Checks
RecommendationMerge approved. The fix correctly adds symmetric BEGIN-marker stripping to match the existing END-marker strip. Implementation is correct — strips run on input body before real nonce-bearing markers are added. Context-aware review complete. 1 inline security review. 0 findings triaged. PR merged. |
Summary
Adds symmetric stripping of
[BEGIN UNTRUSTED PAGE CONTENT nonce=patterns from page content insidewrapUntrustedPageContent(), matching the existing[END UNTRUSTED nonce=]strip.Without this, an attacker-controlled page could inject a fake opening marker into the content body to confuse downstream parsers into treating attacker-controlled content as a trusted wrapper frame.
Changes
src/index.ts: Chain.replace(/\[BEGIN UNTRUSTED PAGE CONTENT nonce=/g, "[BEGIN_UNTRUSTED_PAGE_CONTENT_nonce=")before the existing END strip inwrapUntrustedPageContent()src/index.ts: Update JSDoc comment to document both BEGIN and END marker strippingTesting
[BEGIN UNTRUSTED PAGE CONTENT nonce=xxxis neutralized to[BEGIN_UNTRUSTED_PAGE_CONTENT_nonce=xxxin output [type:unit][END UNTRUSTED nonce=xxxis neutralized to[END_UNTRUSTED_nonce=xxxin output [type:unit]npm run buildpasses [type:unit]Closes #25
Implementation branch:
fix/strip-begin-untrusted-markers-25Base:
main