Skip to content

VeilStream: stop SINs, addresses, names and wrapped PII reaching the model - #11

Open
PermutationResearch wants to merge 1 commit into
mainfrom
fix/veilstream-pii-leaks
Open

PermutationResearch wants to merge 1 commit into
mainfrom
fix/veilstream-pii-leaks

Conversation

@PermutationResearch

Copy link
Copy Markdown
Owner

An end-to-end check of the private chat proxy found values going to the upstream model unmasked. The test used fake data and a local echo upstream.

Case Leaked before
English sentence SIN 046 454 286, street address
French sentence name Élodie Gagnon-Bouchard, NAS 046-454-286, address 88 boulevard René-Lévesque Est
JSON / code "name":"Paul Roy", "sin":"046454286", 77 Main Street
Values wrapped onto the next line everything: name, card, SIN, email

The same script re-run through the real proxy on this branch: no case leaks any value.

What changed (src/veilstream/detector.ts, policy.ts)

  • SIN / NAS: any 9-digit format next to SIN, NAS, social insurance or assurance sociale, or a 3-3-3 grouped number with a valid Luhn check digit.
  • Addresses: French order (88 boulevard René-Lévesque Est), English order (77 Main Street), and Canadian postal codes. Before this, the server detector had no address pattern at all.
  • Names: accented and hyphenated words, French introductions (je m'appelle, mon nom est, je suis), courtesy titles (M., Mme, Dr.), and quoted or unquoted name fields.
  • Wrapped values: a single line break reads as a space, with offsets unchanged. A blank line still separates form fields, a word followed by a colon is treated as a field label, and trailing whitespace stays outside the masked span so the text keeps its layout. Emails match across a line break next to @.
  • Capture-group offsets now come from the regex d flag. Before, the code assumed the group ended the match, which was wrong for "name":"…".

Trade-off: SIN, ADDRESS and POSTAL_CODE use the policy's irreversible redaction, as SSN already does. The model's reply therefore shows [SIN] or [ADDRESS] where the user's original value was. Names, emails, phones and cards still round-trip exactly.

Measured (server detector, main → this branch)

Corpus Change
Generated, 600 cases recall 0.393 → 0.445 (ADDRESS 0/75 → 33/75, PERSON 149 → 224 of 675); cases with a false mask unchanged at 75
Structured benchmark, 4000 ADDRESS 0/853 → 257/853, SSN 496 → 566 of 608
France structured, 257 ADDRESS 0/274 → 16/274
PIIBench test, 2000 PERSON 23 → 44 of 660

The structured sets now have more cases with a mask outside a labelled span: 2255 → 2562 of 4000, and 134 → 184 of 257 for France. I reviewed the new masks. They are real PII those sets don't label:

  • names in sets that only label card and ID data;
  • addresses such as 45 Avenue des Champs-Élysées;
  • Canadian postal codes;
  • three 9-digit numbers that happen to pass the SIN check.

Two genuine over-masks found during review were fixed before this commit: names joined across a blank line into the next form label, and card numbers consuming the following line break.

Tests

  • test/veilstream-pii-leaks.test.ts: one test per leak, all 8 seen failing on main, plus ordinary text that must stay untouched ("Order 123 456 789", "The Montreal Canadiens won", "Je suis content").
  • VeilStream, private-chat and private-mode suites: 108/108 pass.
  • npm run typecheck passes; Biome and ESLint are clean on changed files.
  • DEV_MODE=true npm test: 697 of 698 pass. The failure is the live-inspector jailbreak test, which hits a cold ML inspector on port 8001 and exceeds its 2 s timeout. It fails, then passes, on rerun, so it is unrelated to this change.

Not in this PR

  • Browser package: packages/veilstream-browser has its own copy of the regex detector, still without these fixes. The server build compiles only src/, so merging the two detectors means changing how they are built and shared. That is a separate change.
  • Remaining misses: names in prose with no cue (no introduction, title or field) still pass through. On PIIBench, person recall is 44 of 660. Closing that gap needs the NLP sidecar (PII_DETECTOR_URL), not more regex.
  • Unchanged pattern quality: US address recall is 257/853 and French 16/274. Unit numbers, PO boxes and other formats are not covered.

🤖 Generated with Claude Code

… the model

Through the proxy's default regex detector, these values reached the
upstream model in clear (fake data, local echo upstream):

- Canadian SIN / NAS in any format ("046 454 286", "046-454-286",
  "sin":"046454286"); only the US 3-2-4 SSN shape was matched.
- Street addresses and postal codes ("1234 Rue Sainte-Catherine Ouest",
  "88 boulevard René-Lévesque Est", "77 Main Street", "H3G 1P1"); the
  server detector had no address pattern.
- Names with accents or hyphens, names after French introductions
  ("je m'appelle Élodie Gagnon-Bouchard"), and names in "name" fields.
- Any value wrapped onto the next line: name, card, SIN and email.

Detection changes in src/veilstream/detector.ts:
- SIN: any 9-digit format next to SIN / NAS / social insurance /
  assurance sociale, or a 3-3-3 grouped number with a valid Luhn digit.
- ADDRESS: French order (number, street type, name, direction) and
  English order (number, name, street type); POSTAL_CODE: Canadian codes.
- PERSON: Unicode name words, French introductions, courtesy titles
  (M., Mme, Dr.), and quoted or unquoted name fields.
- Patterns read a single line break as a space, with offsets unchanged,
  so wrapped values match; a blank line still separates form fields, a
  word followed by a colon is a field label, and trailing whitespace is
  left outside the masked span. Emails match across a break next to @.
- Capture-group offsets come from the `d` flag instead of assuming the
  group ends the match, which was wrong for "name":"…" fields.

The default policy redacts SIN, ADDRESS and POSTAL_CODE irreversibly, as
it already does for SSN, so a reply shows [SIN] or [ADDRESS] where the
original value was. Names, emails, phones and cards still round-trip.

Measured with the server detector, main -> this branch:
- 600-case generated corpus: recall 0.393 -> 0.445 (ADDRESS 0/75 -> 33/75,
  PERSON 149/675 -> 224/675); cases with a false mask unchanged at 75.
- Structured benchmark (4000): ADDRESS 0/853 -> 257/853, SSN 496 -> 566
  of 608. France set (257): ADDRESS 0/274 -> 16/274.
- New masks outside labelled spans are real PII those sets leave
  unlabelled (names in card/ID-only sets, addresses, postal codes) plus
  three 9-digit numbers that happen to pass the SIN check.

test/veilstream-pii-leaks.test.ts covers each leak (all 8 failed before)
and ordinary text that must stay untouched.
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.

2 participants