Standard: at every trust boundary, enforce security invariants in a way that cannot be skipped by flags, parsing edge cases, alternate code paths, or serialization differences.

Checklist (apply consistently): 1) Feature flags must not become bypass switches

2) Validate identifiers and map them safely to filesystem/network usage

Example (route boundary):

function assertSessionId(raw: unknown): string {
  if (typeof raw !== 'string') throw new Error('invalid');
  if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(raw))
    throw new Error('invalid');
  return raw;
}

3) Handle untrusted filesystem objects safely (symlinks/TOCTOU)

4) Sanitize all outputs on every path (not just the happy path)

Example (cancel path must sanitize like append):

await finalize(segmentId,
  sanitizeStreamingImageMarkers(record.content),
  'Cancelled',
  false,
);

5) Authorization/auth token propagation must be end-to-end

6) Confidentiality: treat platform “internal” flags as security labels

7) Parsing/regex guards must be robust to escape and grammar edge cases

8) Enforce sender-policy and consistent untrusted-data framing before aggregation

9) Don’t trust carriers written by the audited execution

This standard is meant to be a practical code-review rubric: when you see “allow/skip/early return/regex parse/check-then-use”, require that the security invariant still holds and that untrusted data cannot reach sinks (filesystem paths, network endpoints, subprocess argv, UI/LLM text, or public replies) without the corresponding validation/sanitization/authorization guarantees.