Skip to content

fix(pii): detect and redact JSON Web Tokens (JWTs) - #2

Merged
aymandakirgh merged 1 commit into
mainfrom
fix/pii-jwt-redaction
Jun 18, 2026
Merged

fix(pii): detect and redact JSON Web Tokens (JWTs)#2
aymandakirgh merged 1 commit into
mainfrom
fix/pii-jwt-redaction

Conversation

@aymandakirgh

Copy link
Copy Markdown
Owner

Why

The LLM02 PII guard documents JWT detection (`pii-output.ts` comment: "JWT-like strings") but never implemented it. The only token rule matches `Bearer `, and its body excludes `.`, so:

  • A bare JWT (eyJ...header.payload.signature, no Bearer prefix) returns safe=true and leaks completely — verified empirically.
  • A Bearer-prefixed JWT redacts only the header segment; the payload (which routinely carries sub/email/name PII claims) and signature still leak.

A JWT in model output is both a bearer credential and a PII carrier, so this is a real LLM02 false negative.

What

  • New dedicated jwt pattern in PII_PATTERNS, anchored on the base64url header prefix eyJ (the encoding of {" that begins every JWT header JSON object), spanning all three header.payload.signature segments.
  • Score 92 > bearer-token (90) so the shared position-based overlap resolution always prefers the full three-segment span — the whole token is redacted even when Bearer-prefixed.
  • The eyJ anchor + minimum segment lengths keep false positives near zero. Benchmark category thresholds still met (npm run bench).
  • 3 regression tests (bare JWT, full Bearer-JWT redaction incl. PII payload, dotted non-JWT negative) + README LLM02 row updated.

Verification

  • npm run typecheck ✅ · npm run lint ✅ · npm test305 passed / 1 skipped ✅ · npm run benchAll category thresholds met

The PII guard's comment claimed to flag "JWT-like strings", but the only
token rule matched `Bearer <token>` — and that pattern stops at the first
`.`, so a bare JWT passed through with safe=true while a Bearer-prefixed
JWT had only its header segment redacted. In both cases the payload (which
routinely carries `sub`/`email`/`name` PII claims) and signature leaked.

Add a dedicated JWT rule anchored on the base64url header prefix `eyJ` (the
encoding of `{"`), spanning all three header.payload.signature segments.
Score 92 > bearer-token (90) so overlap resolution redacts the whole token
even when `Bearer`-prefixed. The anchor plus minimum segment lengths keep
false positives near zero — benchmark category thresholds still met.

Adds 3 regression tests and updates the LLM02 coverage row in the README.

Co-authored-by: mattia-mamini-gh <281593356+mattia-mamini-gh@users.noreply.github.com>
@aymandakirgh
aymandakirgh merged commit 2412ac0 into main Jun 18, 2026
3 checks passed
@aymandakirgh
aymandakirgh deleted the fix/pii-jwt-redaction branch June 18, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant