Skip to content

feat(pii): custom user-supplied regex patterns for redaction#5732

Merged
TheodoreSpeaks merged 6 commits into
stagingfrom
feat/pii-custom-regex
Jul 17, 2026
Merged

feat(pii): custom user-supplied regex patterns for redaction#5732
TheodoreSpeaks merged 6 commits into
stagingfrom
feat/pii-custom-regex

Conversation

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator

Summary

  • Add user-supplied custom regex patterns to PII redaction — { name, regex, replacement }, matched and redacted everywhere PII runs: block input, block outputs, logs, and the guardrails block/tool
  • Per-stage inline storage on PiiStagePolicy (no DB migration — data_retention_settings is a schemaless JSON column); bounds enforced at the contract boundary (name ≤100, regex 1–512, replacement ≤100, ≤20 patterns/stage)
  • Presidio service builds per-request ad-hoc recognizers + replace-operators; a bad regex fails fast as 400; the spaCy-skip fast path stays intact (custom entities are non-NER). Custom-only requests never widen to detect-all
  • ReDoS backstop: REGEX_TIMEOUT_SECONDS=2 (Presidio parses it with int()) + client-side safe-regex2 validation in the shared Custom Patterns editor
  • UI: Custom Patterns section in Data retention (per stage) + a Custom Patterns table on the Guardrails block (Validation Type = PII)

Type of Change

  • New feature

Testing

  • Built the PII image and validated live: custom-only redaction, custom + built-in together, block-mode detection, 400 on invalid regex, nlp=skip fast path intact
  • 43 TS/TSX unit tests (schema/contract/resolver/normalize/editor), type-check, check:api-validation:strict, check:migrations, py_compile all green
  • Note: Presidio isn't installable in CI, so the server paths are validated via the local image build

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 17, 2026 5:29pm

Request Review

@cursor

cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes PII/data-retention behavior across execution and logging with user-supplied regex; mitigations include boundary validation, Presidio compile/timeout, and existing fail-closed scrub/throw paths on mask failures.

Overview
Adds user-defined regex patterns (name, regex, replacement) to PII redaction across workflow input, block outputs, logs, guardrails validate/mask-batch, and the Guardrails block.

The Presidio service accepts optional patterns on analyze/anonymize/redact routes: ad-hoc recognizers with score 1.0, per-pattern replace operators (tokens wrapped in angle brackets), invalid regex → 400, and entity resolution so guardrails “empty = detect all” still runs custom patterns while data-retention “empty entity list + patterns” means custom-only.

App layer: customPatternSchema on API contracts (syntax + safe-regex2), sanitizeCustomPatterns, retention resolution/UI (CustomPatternsEditor), executor and log redaction paths pass customPatterns through to maskPIIBatch; guardrails tool maps table rows and coerces null entity lists. Docker: REGEX_TIMEOUT_SECONDS=2 on the PII image.

Reviewed by Cursor Bugbot for commit b6ed40d. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread apps/sim/lib/api/contracts/primitives.ts
@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds user-defined regex patterns to PII redaction across the application. The main changes are:

  • Adds bounded custom-pattern contracts and shared regex safety validation.
  • Applies custom patterns to inputs, block outputs, logs, and guardrails.
  • Builds per-request Presidio recognizers and replacement operators.
  • Adds custom-pattern editors for data retention and guardrails.
  • Preserves custom-only policies and regex-only processing paths.

Confidence Score: 5/5

This looks safe to merge.

  • The updated contract rejects malformed and known unsafe regexes before persistence or execution.
  • Custom patterns are carried through the main redaction paths without a confirmed blocking failure.
  • No distinct production issue remains within the follow-up scope.

Important Files Changed

Filename Overview
apps/sim/lib/api/contracts/primitives.ts Adds bounded custom-pattern schemas with syntax and unsafe-backtracking validation.
apps/sim/lib/guardrails/validate_regex.ts Provides shared regex validation for API contracts and the editor.
apps/pii/server.py Adds per-request custom recognizers, entity resolution, and replacement operators.
apps/sim/lib/guardrails/validate_pii.ts Carries custom patterns through PII analysis and masking requests.
apps/sim/lib/billing/retention.ts Resolves custom patterns into effective per-stage redaction policies.
apps/sim/components/pii/custom-patterns-editor.tsx Adds the shared editor for creating and validating custom patterns.

Reviews (5): Last reviewed commit: "fix(pii): keep detect-all when a custom ..." | Re-trigger Greptile

Comment thread apps/pii/server.py
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

Comment thread apps/pii/server.py
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

Comment thread apps/sim/lib/guardrails/validate_pii.ts
Comment thread docker/pii.Dockerfile
Comment thread apps/sim/lib/guardrails/validate_regex.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 4 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5e86c7d. Configure here.

Comment thread apps/pii/server.py
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

@TheodoreSpeaks
TheodoreSpeaks merged commit 61de0b5 into staging Jul 17, 2026
20 checks passed
@TheodoreSpeaks
TheodoreSpeaks deleted the feat/pii-custom-regex branch July 17, 2026 19:21
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