Reviewer · Security
Consistent security validation paths
When a feature touches security-sensitive mechanisms (taint tracking, CSP nonce enforcement, etc.), make sure the check is applied uniformly on every code path that can deliver data to the client — not just the "normal" or first-created path. New variants of a data flow (decoded/forwarded objects, cached or merged resources, alternate constructors) are easy...
When a feature touches security-sensitive mechanisms (taint tracking, CSP nonce enforcement, etc.), make sure the check is applied uniformly on every code path that can deliver data to the client — not just the “normal” or first-created path. New variants of a data flow (decoded/forwarded objects, cached or merged resources, alternate constructors) are easy to miss and become bypass routes if they return early or skip the shared validation helper.
Concretely:
- Reuse the same validation/sanitization helper everywhere a value can be serialized or emitted, instead of duplicating ad-hoc logic per code path. For taint checks, run the check both when a value is first captured and again when it is actually written out, so a value tainted after capture is still caught:
function serializeLedgerTotal(request, total) { // Decoded/forwarded totals must go through the same taint check // as freshly captured ones — don't let an early return skip it. if (isTaintedObject(total)) { throw new Error('Cannot serialize a tainted value.'); } ... } - Treat any branch that short-circuits before the shared check as a bug; audit early returns and alternate constructors whenever a new type/variant is added to an existing serialization or rendering path.
- For values that establish security context once (e.g. a CSP nonce used to create a resource), capture and require it up front rather than deriving it lazily per call, and never silently merge/cache content whose security context (nonce value) differs — a mismatch should be surfaced (dev warning or error) rather than producing output that quietly weakens the intended security guarantee.
- When exposing a new public option that affects a security-relevant attribute (e.g. a nonce), add it explicitly to the option type rather than inferring it implicitly, so correctness doesn’t depend on undocumented behavior.
Applying checks and security-context propagation consistently closes gaps where a “legitimate” alternate path (decoding, caching, merging) unintentionally becomes a way to bypass taint tracking or weaken CSP protections.</description>