Skip to content

fix(platform): mask two-digit-year dates of birth after a keyword - #5083

Closed
tale-code-bot wants to merge 1 commit into
mainfrom
fix/pii-two-digit-year-dob
Closed

tale-code-bot wants to merge 1 commit into
mainfrom
fix/pii-two-digit-year-dob

Conversation

@tale-code-bot

Copy link
Copy Markdown
Collaborator

Summary

PII protection never masked a date of birth written with a two-digit year, such as DOB: 15/03/87, Geburtsdatum: 15.03.87 or date de naissance : 15/03/87. Since #1710 the numeric validator requires a four-digit year (yearLooksPlausible looks for /\d{4}/), so it dropped every \d{2}-year match of the dateOfBirth.yml knob.

Closes #4776 (Tale task TALE-154; the plan was posted on the task before the first edit).

Fix. A two-digit year on its own still passes: 15.03.87 could just as well be a version or a section number, which is what #1710 stopped masking. A new pass composed in services/platform/lib/pii/patterns/date-of-birth.ts masks it only right after a date-of-birth keyword of an enabled locale. The keywords come from dateOfBirth.contextKeywords (DOB, Geburtsdatum, date de naissance, …), which the locale data already has.

  • The keywords go through the shared composeKeywordAlternation and are word-bounded and case-insensitive, like the phone and national-ID keyword gates. The pass is cached in the existing DOB_REGEX_CACHE.
  • The keyword sits in a lookbehind, so it stays outside the span and the mask keeps it. DOB: 15/03/87 becomes DOB: [DATE_OF_BIRTH], the same result as DOB: 15/03/1987.
  • The pass is a regex with a validator, so it runs under the engine's exec budget like the other DOB passes. The validator accepts any two-digit year when day and month form a date in DMY, MDY or YMD order (YMD as in 생년월일: 87.03.15).
  • The day/month check is now one helper that the four-digit validator also uses; its logic is unchanged.
  • Allowed between keyword and date: up to 12 characters of whitespace, : or :, ., ,, = or dashes. The date must not run on into more digits or letters, so 15.03.87.12 and 15/03/87abc are not masked.

The knob regex and the four-digit validator are unchanged. The pattern description and the guardrails guide (EN, DE, FR) state the rule; the guide's sentence sits next to the existing one on keyword-gated identifiers.

Known limits:

  • With every locale enabled (the default when an organization picks none), short keywords of other locales also gate the pass: fi s., pl ur., cs/sk/uk nar., id TTL. For example, s. 3.2.10 would be masked. That is still narrower than the four-digit pass, which masks any plausible date anywhere.
  • A CJK keyword joined to the preceding word in running text does not gate. Phone and national-ID gates have the same letter-boundary limit.

Checklist

  • bun run check: not run in full on this worker (lint, typecheck, test and test:ui of every workspace). The gates this change touches ran instead; see the test plan. CI runs the rest.
  • bun run lint:sast: not run. The pinned opengrep binary is not cached on this worker, and fetching it is outside the lock files; the pre-commit opengrep step skipped for the same reason. CI's SAST job runs it.
  • Translations: N/A, no message key changed.
  • Docs updated in docs/{en,de,fr}/platform/admin/governance/guardrails.md.
  • README: N/A, no README describes date formats.

Test plan

Before the fix. At main 9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2 with only the new tests added, from services/platform:

bunx vitest --run --project pii tests/pii/smoke.test.ts

Result: 4 failed, 54 passed. Exactly the four keyword cases failed, each with expected 'pass' to be 'modified'.

After the fix. At head bdefd7f8cd04c4ecbdc33d0a631a179cd5362809, from services/platform unless noted:

Command Result
bunx vitest --run --project pii 9 files, 67,266 tests passed, including the frozen 43-locale corpus (every negative still passes), throughput, tokenizer and the smoke file (58 passed)
bunx vitest --run --project server lib/chat/guardrails.test.ts backend/domains/model_api/guardrails.test.ts backend/core/knowledge/pii_gate.test.ts 3 files, 75 tests passed (the scrubber's callers)
NODE_OPTIONS=--max-old-space-size=6144 bunx tsc --noEmit (CI's heap budget) exit 0
bunx oxlint --type-aware exit 0
bunx vitest --run in services/docs 38 files, 716 tests passed
bun run lint:links (repo root) every link lands
oxfmt --check on the touched files clean

New smoke tests:

  • DOB: 15/03/87, Geburtsdatum: 15.03.87, date de naissance : 15/03/87 and 생년월일: 87.03.15 become <keyword>: [DATE_OF_BIRTH], with dateOfBirth as the only category.
  • A bare 15.03.87 passes.
  • DOB: 45/13/87 passes.
  • The four-digit control is now asserted exactly: DOB: [DATE_OF_BIRTH].

Not tested: the chat, model-API and knowledge paths end to end on a running platform, and the guide rendered in a browser.

Since #1710 the numeric date-of-birth validator needs a four-digit year
(yearLooksPlausible looks for /\d{4}/), so every two-digit-year match of
the pattern knob was dropped: "DOB: 15/03/87", "Geburtsdatum: 15.03.87"
and "date de naissance : 15/03/87" reached the model unmasked.

A bare two-digit year stays unmasked, since on its own 15.03.87 reads as
well as a version or a section number. A new composed pass masks it right
after a date-of-birth context keyword of an enabled locale. The keyword
sits in a lookbehind, so the mask keeps it ("DOB: [DATE_OF_BIRTH]", as
with a four-digit year). The day and month must form a date in DMY, MDY
or YMD order. The pattern description and the guardrails guide (EN, DE,
FR) state the rule.

Closes #4776
@yannickmonney

Copy link
Copy Markdown
Contributor

The autonomous cycle now lands each task through the merge train instead of its own pull request (.agents/repo.md on train), so this pull request closes. The branch fix/pii-two-digit-year-dob stays and the task goes on with it: the Reviewer reviews the branch's head on the task and squashes accepted work onto train.

@yannickmonney
yannickmonney deleted the fix/pii-two-digit-year-dob branch October 30, 2026 10:32
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.

Bug: PII protection never masks a date of birth written with a two-digit year

2 participants