Skip to content

Allow user-defined custom regex patterns from the extension UI #459

@hanneshapke

Description

@hanneshapke

Motivation

Custom regex patterns are already supported in the backend config (regex_config.custom_patterns in src/backend/config/pii_detector_config.json), but they can only be configured by editing the JSON file on the server. End users have no way to add domain-specific patterns (employee IDs, internal ticket IDs, project codes, etc.) without filing a request or editing config directly.

We should expose custom regex management through the extension UI so users can add their own patterns at runtime.

Proposal

Add a "Custom patterns" section to the extension options page that lets users define and manage their own regex-based detectors.

UI

  • Table of custom patterns with columns: Label, Pattern, Enabled, Actions (edit / delete).
  • "Add pattern" form with:
    • Label (e.g., EMPLOYEE_ID) — uppercase, used as the entity type name.
    • Regex pattern (e.g., \\bEMP-\\d{6}\\b).
    • Optional: replacement/mask format.
  • Live validation: compile the regex client-side and reject invalid patterns before saving.
  • Preview field: paste sample text, see what matches before saving.

Backend

  • Endpoint to GET/PUT user-defined patterns, merged with regex_config.custom_patterns from the static config.
  • Server-side regex compilation + validation (reject patterns that fail to compile or are catastrophically slow — use Go's regexp which is RE2 and safe from ReDoS, but still cap pattern length).
  • User-defined labels appear in the entity-type selection menu alongside model-emitted labels (see Make detected entity types configurable in the extension #458).

Persistence

  • Custom patterns are stored per-user (extension storage) and synced to the backend on change.
  • Patterns are enabled by default when created.

Acceptance criteria

  • Options page has a "Custom patterns" section with add / edit / delete.
  • Client-side regex validation with inline error messages.
  • Sample-text preview shows matches before saving.
  • Backend accepts, validates, persists, and applies user-defined patterns.
  • Custom labels appear in the configurable entity-type list (Make detected entity types configurable in the extension #458).
  • Invalid or overly long patterns are rejected with a clear error.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Mentoring will be providedThis is a harder issue, but not too difficult with a mentoradvancedAn issue that requires major refactoring or changes to the core architecture

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions