Skip to content

[Avo v2] Add regex pattern validation for Inspector v2#3663

Open
aleks-tpom6oh wants to merge 5 commits intosegmentio:mainfrom
avohq:segment/avo-regex-validation-clean
Open

[Avo v2] Add regex pattern validation for Inspector v2#3663
aleks-tpom6oh wants to merge 5 commits intosegmentio:mainfrom
avohq:segment/avo-regex-validation-clean

Conversation

@aleks-tpom6oh
Copy link
Copy Markdown
Contributor

@aleks-tpom6oh aleks-tpom6oh commented Mar 11, 2026

Summary

  • Adds regex pattern validation support to Avo Inspector v2 property value validation
  • Uses RE2 (via re2-wasm) for safe regex evaluation, preventing catastrophic backtracking (ReDoS)
  • Supports both legacy string format (rx: "^pattern$") and new object-map format (rx: { "^pattern$": ["evt_1"] })
  • Gracefully skips invalid or unsupported regex patterns without failing the event

Test plan

  • Unit tests for regex pattern matching (pass/fail cases)
  • Unit tests for ReDoS safety with catastrophic backtracking patterns
  • Unit tests for unsupported RE2 patterns (e.g., lookaheads) — gracefully skipped
  • Unit tests for invalid regex patterns — gracefully skipped
  • Unit tests for non-string values with regex constraints
  • Integration tests for both legacy string and object-map rx wire formats
  • All existing tests continue to pass

🤖 Generated with Claude Code

Add support for regex pattern validation in the Avo Inspector v2 destination's
property value validation. This enables validating string property values
against regex patterns defined in the Avo Tracking Plan.

Changes:
- Add regex pattern constraint support (regexPatterns) to property validation
- Use RE2 (via re2-wasm) for safe regex evaluation, preventing catastrophic backtracking
- Support both legacy string format and new object-map format for regex patterns
- Gracefully handle invalid or unsupported regex patterns by skipping them
- Simplify encryption to per-value approach (remove session-based encryption)
- Add comprehensive tests for regex validation, ReDoS safety, and edge cases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
aleks-tpom6oh and others added 2 commits March 11, 2026 19:12
Keep the pre-computed EncryptionSession approach where EC key generation
and ECDH happen once per batch rather than once per property value.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aleks-tpom6oh aleks-tpom6oh changed the title [Avo] Add regex pattern validation for Inspector v2 [Avo Inspector v2] Add regex pattern validation for Inspector v2 Mar 11, 2026
@aleks-tpom6oh aleks-tpom6oh changed the title [Avo Inspector v2] Add regex pattern validation for Inspector v2 [Avo v2] Add regex pattern validation for Inspector v2 Mar 11, 2026
aleks-tpom6oh and others added 2 commits March 11, 2026 20:08
Keep PR focused on regex validation only:
- Remove validatedBranchId field from EventSchemaBody and event payload
- Restore MAX_WIRE_DEPTH=2 guard for nested property constraint conversion
- Remove related test assertions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover well-known catastrophic backtracking patterns:
- Overlapping alternation (a|a)*
- Nested repetition with wildcard (.*a){x}
- Quantified group with character classes ([a-zA-Z]+)*
- Email-like pattern with nested quantifiers

All complete in linear time with RE2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds regex-based property value validation to the Avo Inspector v2 “send schema” flow, extending the existing constraint validator (pinned/allowed/min-max) to support rx constraints from the event spec wire format.

Changes:

  • Extends wire/internal constraint types to include regex constraints (rxregexPatterns).
  • Updates wire-to-constraint conversion and constraint merging/validation to evaluate regex patterns using RE2 (via re2-wasm) with per-invocation caching.
  • Adds/updates unit and integration tests covering legacy + object-map wire formats, invalid/unsupported patterns, and ReDoS-style patterns.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/destination-actions/src/destinations/avo-v2/sendSchemaToInspector/types.ts Adds rx to the wire constraint type and regexPatterns to internal constraints.
packages/destination-actions/src/destinations/avo-v2/sendSchemaToInspector/functions/functions.ts Converts rx (legacy string or object-map) into regexPatterns on constraints.
packages/destination-actions/src/destinations/avo-v2/sendSchemaToInspector/functions/event-validator-functions.ts Implements regex validation using RE2 + cache; merges/copies regex constraints across events.
packages/destination-actions/src/destinations/avo-v2/sendSchemaToInspector/tests/schema-functions.test.ts Adds edge-case tests for non-string values and invalid regex patterns.
packages/destination-actions/src/destinations/avo-v2/sendSchemaToInspector/tests/avo.test.ts Adds integration coverage for both rx wire formats.
packages/destination-actions/src/destinations/avo-v2/sendSchemaToInspector/tests/EventValidator.test.ts Updates/adds validator tests for regex behavior, unsupported patterns, and ReDoS cases.
packages/destination-actions/src/destinations/avo-v2/index.ts Updates setting description to mention regex validation support.
packages/destination-actions/src/destinations/avo-v2/generated-types.ts Regenerates settings docstring reflecting regex support.

RuntimePropertyValue,
RuntimeProperties
} from '../types'
import { RE2 } from 're2-wasm'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hi @varadarajan-tw - can you take a look at this package to see if it's something we can allow please?
import { RE2 } from 're2-wasm'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hello @varadarajan-tw, have you had a chance to look at this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @joe-ayoub-segment @varadarajan-tw, could you please take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants