← Back to Pull requests

fix(filtering): reject basic rules with an invalid regex #4882

Open
unknown opened this pull request with 417 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 01, 2026 18:45 UTC
Author

Relates to: no issue

This is a bug I found while reading the basic sync rule code.

A basic rule that uses the regex rule is matched with re.match(self.value, ...) in BasicRule.matches, so its value is only compiled when the sync job runs it against documents. The default basic rule validators (BasicRuleAgainstSchemaValidator, BasicRuleNoMatchAllRegexValidator, BasicRulesSetSemanticValidator) never compile it. So an invalid pattern passes validation and can be activated. A glob-style value such as .pdf is an easy mistake to make here, as is an unclosed [ or (.

Reproduced on main, with a rule exclude / title / regex / .pdf:

FilteringValidator(BaseDataSource.basic_rules_validators()).validate(...)
  -> {'state': 'valid', 'errors': []}

BasicRuleEngine(parse(rules)).should_ingest({"id": "1", "title": "report.pdf"})
  -> re.error: nothing to repeat at position 0

should_ingest is called for every document in Extractor.get_docs with nothing around it to catch errors. So the first document that has the rule's field fails the whole sync with the re.error, instead of the rule being flagged as invalid when it is saved.

The fix adds BasicRuleValidRegexValidator, a BasicRuleValidator like the existing ones. For regex rules it compiles the value and returns an invalid result naming the rule and the re.error message. Other rule types are not affected (contains / .pdf is still valid). It is added to BaseDataSource.basic_rules_validators(), which no data source overrides, so it applies to every connector. With the fix the same rule is reported as:

{'state': 'invalid', 'errors': [{'ids': ['r1'], 'messages': ["Basic rule 2 (id: 'r...1') uses an invalid regular expression: nothing to repeat at position 0."]}]}

Checklists

Pre-Review Checklist


  • this PR does NOT contain credentials of any kind, such as API keys or username/passwords (double check config.yml.example)

  • this PR has a meaningful title

  • this PR links to all relevant github issues that it fixes or partially addresses

  • this PR has a thorough description

  • Covered the changes with automated tests

  • Tested the changes locally

  • Added a label for each target release version (example: v7.13.2, v7.14.0, v8.0.0)

  • Considered corresponding documentation changes

  • Contributed any configuration settings changes to the configuration reference

  • if you added or changed Rich Configurable Fields for a Native Connector, you made a corresponding PR in Kibana
  • Tests

  • libs/connectors_sdk/tests/filtering/test_validation.py: new test_basic_rule_validate_valid_regex. abc, .\.pdf$ and a contains rule with .pdf are valid. The regex values .pdf, report0-9 and (draft are invalid, and the message says "invalid regular expression".

  • libs/connectors_sdk/tests/test_source.py: test_base_class now expects the new validator in the default list.
  • All 306 tests in libs/connectors_sdk/tests/filtering and libs/connectors_sdk/tests/test_source.py pass. ruff check and ruff format --check are clean, apart from the repo-wide CPY001 notice.

    🤖 Generated with [Claude Code

    Diff: 417 lines (+312 / -105) across 5 files Reviewer: ShivamSharma43 Review duration: 30356m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 417 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.361
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4882"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.0% (MEDIUM) · Higher = larger blast radius
    45.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.0% · Safe to merge
    24.0%