Skip to content

t3219: fix PCRE2 Unicode portability in prompt-injection-patterns.yaml#4693

Closed
alex-solovyev wants to merge 1 commit intomainfrom
bugfix/t3219-homoglyph-patterns
Closed

t3219: fix PCRE2 Unicode portability in prompt-injection-patterns.yaml#4693
alex-solovyev wants to merge 1 commit intomainfrom
bugfix/t3219-homoglyph-patterns

Conversation

@alex-solovyev
Copy link
Collaborator

Summary

Addresses CodeRabbit review feedback from PR #2715 (issue #3219).

Two fixes:

  • YAML zero-width character pattern: Replace byte-level \xNN hex escapes ([\xE2\x80\x8B\xE2\x80\x8C\xE2\x80\x8D\xEF\xBB\xBF]) with literal Unicode chars (U+200B ZWSP, U+200C ZWNJ, U+200D ZWJ, U+FEFF BOM). Byte-level escapes match individual bytes, not multi-byte UTF-8 codepoints — the pattern silently failed to match zero-width characters under all grep backends.

  • _PG_YAML_PATTERNS_LOADED flag timing: Move flag assignment to after successful parse+cache in _pg_load_yaml_patterns(). Previously set after file discovery but before parsing, so a transient parse failure would permanently disable YAML loading for the session lifetime.

Verification

  • Literal Unicode chars in character classes work across rg, grep -P, and grep -E (all handle UTF-8 natively)
  • \x{...} PCRE2 code-point syntax confirmed working for \x{200B} etc. in inline patterns (separate from this fix)
  • \p{Cyrillic} and \p{Greek} in inline patterns confirmed working with both grep -P and rg
  • The homoglyph patterns at lines 332/336 already use literal Unicode chars (fixed in PR t1375.1: Add YAML pattern loading and Lasso pattern merge to prompt-guard #2715 itself)

Closes #3219

- Move _PG_YAML_PATTERNS_LOADED flag assignment to after successful
  parse+cache in _pg_load_yaml_patterns(); previously set after file
  discovery but before parsing, so a parse failure would permanently
  disable YAML loading on subsequent calls (transient failures treated
  as permanent)
- Replace byte-level \xNN hex escapes in zero-width character YAML
  pattern with literal Unicode chars (U+200B ZWSP, U+200C ZWNJ,
  U+200D ZWJ, U+FEFF BOM) for portability across rg/grep/ggrep;
  byte-level escapes match individual bytes, not multi-byte UTF-8
  codepoints

Closes #3219
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2026

Important

Review skipped

Auto reviews are limited based on label configuration.

🚫 Review skipped — only excluded labels are configured. (1)
  • no-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4eae8b6d-4f67-4fea-840c-90e3c9054931

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/t3219-homoglyph-patterns
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the bug Auto-created from TODO.md tag label Mar 14, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses two critical issues related to prompt injection pattern detection and YAML configuration loading. It enhances the robustness of zero-width character pattern matching by using native Unicode characters, ensuring consistent behavior across various regex engines. Additionally, it refines the logic for loading YAML patterns, preventing a scenario where a temporary parsing error could permanently disable the pattern loading mechanism for a session.

Highlights

  • Zero-width character pattern portability: Replaced byte-level hex escapes for zero-width characters in prompt-injection-patterns.yaml with literal Unicode characters to ensure portability and correct matching across different grep backends (rg, grep -P, grep -E).
  • YAML pattern loading flag timing: Adjusted the timing of the _PG_YAML_PATTERNS_LOADED flag assignment in prompt-guard-helper.sh to occur only after successful parsing and caching of YAML patterns, preventing transient parse failures from permanently disabling YAML loading.
Changelog
  • .agents/configs/prompt-injection-patterns.yaml
    • Replaced byte-level hex escapes for zero-width characters with literal Unicode characters in the Zero-width characters pattern.
  • .agents/scripts/prompt-guard-helper.sh
    • Removed the premature assignment of _PG_YAML_PATTERNS_LOADED before pattern parsing.
    • Moved the assignment of _PG_YAML_PATTERNS_LOADED to after successful parsing and caching of YAML patterns.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 347 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sat Mar 14 07:22:40 UTC 2026: Code review monitoring started
Sat Mar 14 07:22:40 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 347

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 347
  • VULNERABILITIES: 0

Generated on: Sat Mar 14 07:22:43 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces two important fixes. First, it corrects a faulty regex pattern in prompt-injection-patterns.yaml by replacing byte-level escapes with literal Unicode characters, ensuring zero-width characters are correctly detected across different tools. Second, it improves the robustness of the prompt-guard-helper.sh script by adjusting the logic to set a 'loaded' flag only after successfully parsing and caching YAML patterns. This prevents transient parse failures from permanently disabling the feature for a session. The changes are well-implemented and address the identified issues effectively. I have no further suggestions.

@sonarqubecloud
Copy link

@alex-solovyev
Copy link
Collaborator Author

Duplicate of #4692 which was already merged. Closing.

@marcusquinn marcusquinn added the already-fixed Already fixed by another change label Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

already-fixed Already fixed by another change bug Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quality-debt: .agents/configs/prompt-injection-patterns.yaml — PR #2715 review feedback (critical)

2 participants