test(scrub): property-based hardening of the PII scrubber - #19
Merged
Conversation
Part of nais/grafana-apm-app#90 (test-data quality): fast-check generates PII-shaped identifiers (fnr incl. D-/H-/synthetic variants, emails, NAV idents, token params) embedded in arbitrary surrounding text and asserts the scrubber's invariants: redaction wherever properly delimited, idempotence, never-throws, query/fragment dropping and path-segment masking in scrubUrl, and looksLikePii precision (UUIDs pass, identifiers do not). First run immediately surfaced a real, previously undocumented limitation: a word character glued directly onto an fnr breaks the \b boundary, so 'bruker01017012345' passes through unscrubbed. Digits-glued is the deliberate false-positive guard; letters-glued is a \b side effect. The limitation is now pinned by an explicit documenting test - tightening it is a product decision traded against false positives on letter+digit identifiers.
Starefossen
force-pushed
the
test/scrub-property-based
branch
from
July 12, 2026 18:58
6273843 to
2ba7a18
Compare
Starefossen
enabled auto-merge
July 12, 2026 18:58
There was a problem hiding this comment.
Pull request overview
This PR strengthens confidence in the PII scrubber by adding property-based tests that exercise many generated, PII-shaped inputs and assert invariants (redaction, idempotence, and “never throws”), using fast-check as a dev-only dependency.
Changes:
- Add
src/scrub.property.test.tswith property-based tests forscrubString,scrubUrl, andlooksLikePii. - Add
fast-checkas a dev dependency and lockfile entries (fast-check,pure-rand).
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/scrub.property.test.ts | Introduces fast-check properties to validate scrubber invariants across generated PII-like inputs. |
| package.json | Adds fast-check to devDependencies. |
| pnpm-lock.yaml | Locks fast-check and its transitive dependency pure-rand. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .tuple(surroundingArb, fc.oneof(fnrArb, emailArb), surroundingArb) | ||
| .map(([a, pii, b]) => `${a}${pii}${b}`); | ||
| fc.assert( | ||
| fc.property(fc.oneof(fc.string({ unit: 'binary' }), withPii), (s) => { |
|
|
||
| it('never throws and always returns a string, whatever the input', () => { | ||
| fc.assert( | ||
| fc.property(fc.string({ unit: 'binary' }), (s) => { |
|
|
||
| it('never throws on arbitrary input', () => { | ||
| fc.assert( | ||
| fc.property(fc.string({ unit: 'binary' }), (s) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the test-data quality work discussed under nais/grafana-apm-app#90.
What
Adds
fast-check(dev-only) andscrub.property.test.ts: generated PII-shaped identifiers — fnr with plausible date prefixes (incl. D-number/H-number/synthetic variants), emails, raw NAV idents, token-bearing query params — embedded in arbitrary surrounding text, asserting the scrubber's invariants rather than hand-picked examples:[fnr]/[email]/[redacted]redaction wherever the identifier is properly delimited (both fnr forms: contiguous and space-separated)scrubUrl: query/fragment always dropped; fnr/UUID/ident path segments masked wherever they sitlooksLikePii: flags every generated fnr/email/ident; passes UUIDs (opaque correlation keys) throughOn failure fast-check prints the seed + minimal counterexample — add it to
scrub.test.tswhen fixing.🔍 Finding (first run)
The properties immediately surfaced a real, previously undocumented limitation — minimal counterexample
a41810000000:A word character glued directly onto an fnr breaks the
\bboundary, so e.g.bruker01017012345passes through unscrubbed. Digits-glued is the deliberate false-positive guard (11 digits inside a longer number are not an fnr); letters-glued is a side effect of\btreating[A-Za-z0-9_]uniformly.Rather than silently tightening the regex (which trades against false positives on letter+digit identifiers like case numbers), the limitation is pinned by an explicit documenting test. Whether to tighten is a product decision — happy to open a follow-up issue if we want to pursue it.
Notes
main, independent of feat: auto-config — consume the platform channel, SSR helpers, loud misconfig failure #18.