Skip to content

redactSecrets: P2/P3 follow-ups from deep-review on #2188 #2237

Open

Description

@alex-fedotyev

Follow-up to #2235 tracking the P2/P3 items from the deep-review on the original #2188 that were deferred (out of scope for the P0/P1 security fix).

P2 (recommended)

  • bearer regex prose false positives. Case-insensitive with no \b prefix, so prose like a bearer of bad news matches and rewrites the next word to Bearer [REDACTED]. Either drop the i flag and add \b anchors, or require an Authorization\s*: lead-in.
  • basic regex prose false positives. Same shape: Basic auth required is mangled into Basic [REDACTED] required. Add \b and require base64-shaped values (minimum length plus +///=).
  • json-quoted escape handling. Value class [^"]* stops at the first literal quote regardless of escape, so {"password":"abc\"def","user":"alice"} matches "password":"abc\" and leaks def","user":"alice". Change to (?:[^"\\]|\\.)*.
  • Oversized PEM bound. The {0,16000}? bound for ReDoS safety silently fails to redact PRIVATE KEY blocks larger than ~16 KB (encrypted PKCS#8, multi-key OpenSSH, RSA-8192 with metadata). Either widen, document the limit with an explicit test, or pair with a line-counter pass.
  • basic-auth-url ReDoS bounds. Greedy password class [^/\s]+ permits @ and is followed by literal @ plus host, producing O(n²) backtracking on adversarial inputs like https://a: + b@.repeat(N) + end. Either drop @ from the password class or bound it.
  • Vendor-token shapes deferred at PR time. Stripe (sk_live_, rk_live_, pk_live_, whsec_), Google (AIza…), Twilio (AC…/SK…), Datadog. Low-false-positive shapes that are cheap to add when seen.
  • Session cookies. SECRET_KEY_TOKENS does not include session-cookie names (session, sid, jsessionid, connect.sid, phpsessid). A Cookie: or Set-Cookie: line carrying an opaque session token slips through.
  • AWS secret access key. Once AKIA… is matched, the paired 40-char secret only gets redacted via key-name (AWS_SECRET_ACCESS_KEY=…); camel-case variants like secretAccessKey: … may slip through. Add fixtures and consider the proximity rule.
  • Pattern coverage test ordering. expect.arrayContaining([...]) is one-way; misses additions, duplicates, reordering, even though the source comment declares pattern order load-bearing. Replace with exact ordered toEqual([...]) or fixture-driven coverage.

P3 (nitpicks)

  • Idempotence assertion: redactSecrets(redactSecrets(x)) === redactSecrets(x).
  • Prose-negative tests for bearer / Basic mid-sentence.
  • pem, json-quoted, http-header missing from the multi-secret integration fixture.
  • Pattern-ordering invariant pinned by test (password=eyJa.b.c preserves JWT shape).
  • PEM ReDoS guard threshold expect(elapsed).toBeLessThan(500) is brittle wall-clock. Use same-runner baseline or a 1 MB input that genuinely catastrophic regex would blow.
  • Default-ignorable code-point bypass (NFKC normalization, ZWSP / ZWNJ / FEFF stripping).
  • bearer trailing punctuation (., /) consumed: Bearer abc123. Note... swallows the trailing period.
  • HTTP-header replacement always emits : , rewriting Api-Key:abc123 to Api-Key: [REDACTED]. Capture and reuse the original separator.
  • REDACTION_PATTERN_NAMES typed string[]; widen to readonly string[] and mark @internal.
  • PATTERNS: RedactionPattern[] widens each name from string-literal type to string. Use as const satisfies readonly RedactionPattern[].
  • redactSecrets(input: string) has no boundary guard; passing non-string through any throws TypeError. Coerce or guard.
  • Large-input perf cap or single-alternation composition (currently 12 sequential replace passes).

Reference

Originating deep-review: #2188 (comment)
P0/P1 fix landed in #2235.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

apienhancementp2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions