Skip to content

feat(cli): prompt-injection smuggling detector and canary audit (devops scan injection) #589

Closed

Description

@dan-petty

Context & Rationale

normalize_unicode_text (src/devops_cli/ai/text_utils.py:36-41, NFKC plus a 23-entry table dropping only U+200B/U+FEFF) runs on model output (ai/review_schema.py:119-181), not reviewed input. sanitize_prompt_injection (security/sanitizer.py:296-302) and sanitize_prompt_boundary_tags (sanitizer.py:284-293, wrapping review prompts at ai/review/runner.py:1315) match tag names only; <|im_start|>, [INST], <<SYS>>, Tag-block, zero-width and bidi characters pass. Reviewed files are read errors="replace" (runner.py:1292) then redact_text (runner.py:1494), credential masking only; PR posting (commands/review.py:645-661) checks nothing outbound. write_sarif is called only at commands/scan.py:839; scan sarif (scan.py:855-901) ingests any SARIF 2.1.0 under --suppress/--fail-on, keying rule ids from bracketed titles (security/normalization.py:29-32,171-185). vibes tools/prompt_injection_scanner.py has INJ001 Tag-block decode (line 214), INJ002/INJ003/INJ005 and a CanaryTokenManager (audit_response, line 185, EGR005); vibes observations/systems/10-mcp-protocol-boundaries-and-stateless-transport-constraints.md:53,125 names tool return strings as MCP's untaggable channel.

Scope & Deliverables

  • Context & Rationale*: normalize_unicode_text (src/devops_cli/ai/text_utils.py:36-41, NFKC plus a 23-entry table dropping only U+200B/U+FEFF) runs on model output (ai/review_schema.py:119-181), not reviewed input. sanitize_prompt_injection (security/sanitizer.py:296-302) and sanitize_prompt_boundary_tags (sanitizer.py:284-293, wrapping review prompts at ai/review/runner.py:1315) match tag names only; <|im_start|>, [INST], <<SYS>>, Tag-block, zero-width and bidi characters pass. Reviewed files are read errors="replace" (runner.py:1292) then redact_text (runner.py:1494), credential masking only; PR posting (commands/review.py:645-661) checks nothing outbound. write_sarif is called only at commands/scan.py:839; scan sarif (scan.py:855-901) ingests any SARIF 2.1.0 under --suppress/--fail-on, keying rule ids from bracketed titles (security/normalization.py:29-32,171-185). vibes tools/prompt_injection_scanner.py has INJ001 Tag-block decode (line 214), INJ002/INJ003/INJ005 and a CanaryTokenManager (audit_response, line 185, EGR005); vibes observations/systems/10-mcp-protocol-boundaries-and-stateless-transport-constraints.md:53,125 names tool return strings as MCP's untaggable channel.
  • Deliverable*: PR A (additive): pure-function security/prompt_injection.py with INJ001 Tag-block decode, INJ002 format-character runs (unicodedata.category(c) == "Cf"), INJ003 delimiters (escaped, never deleted) and INJ005 exfiltration links; titles carry the bracketed rule id, so normalize_finding/write_sarif are untouched. Add devops scan injection <target> and a scan_injection MCP tool with their own --sarif/--suppress/--fail-on, calling write_sarif and _load_policy_or_exit (scan.py:758) directly since _create_default_scanners (security/registry.py:16-44) is subprocess-only (separate refactor). PR A also adds Ruff PLE2502, PLE2510, PLE2512–PLE2515, RUF001–RUF003 to pyproject.toml:76 (PLE2511 does not exist). PR B (hot path): call the module from _collect_file_blocks/_build_path_prompt and diff pages, adding findings, not normalizing; a per-run secrets.token_hex canary in the review system prompt, audit_response over every finding's title/description/fix and the comment body before pull.create_issue_comment (commands/review.py:661); a hit fails the run (EGR005). Review auto-fix/apply-patch was removed in feat(review): remove unverified auto-fix and apply-patch claims (#601) #624 (Item feat(cli): one verdict writer, cited refutations and no unverified fix claims #601), so the run generates no patches and there is no patch surface to audit. Port the rule taxonomy, decode_unicode_tags, delimiter list and canary shape; not INJ004 (flags every security test) or EGR001–EGR004 (duplicate redact_text/Gitleaks). Rejected (PyPI metadata): llm-guard 0.3.16 pulls torch/transformers/presidio-analyzer; rebuff last released 0.1.1 (2024-01-20). No maintained lightweight equivalent exists; stdlib unicodedata plus Ruff is the adopt path.
  • Constraint*: Stripping is the wrong primitive: U+200C/U+200D are load-bearing in emoji, Indic and Arabic text. The review-side detector reports and continues; only a canary leak fails. Exempt U+E0000 (category Cn) and emoji tag sequences ending U+E007F by construct and offset, not extension. Its own fixtures will contain delimiters, so scan injection honours security/suppression.py via --suppress. The canary catches only a verbatim echo: a regression tripwire, not a proof. Audit for the token, not the guard block; never log it (ai/mcp/dispatcher.py:20-31 CodeQL history). Sequence: PR A; then extend the Synthetic Prompt Adversaries corpus with Tag-block/zero-width variants; a later MCP item can import this module for _run_mcp_cmd (ai/mcp/server.py:45-77) output.
  • Measured*: .venv/bin/python walk over src, tests, docs, scripts, k8s, .github, AGENTS.md, .pre-commit-config.yaml, pyproject.toml: 1277 UTF-8 text files, none containing zero-width, Tag-block or bidi code points. Same probe: normalize_unicode_text passes 28 of 28 Tag-block characters (U+E0020–U+E003B) and both sanitizers leave <|im_start|>, [INST], <<SYS>> unchanged. grep -rn -i canary src/ tests/: 13 lines, all Argo. ruff --version 0.16.8; ruff rule confirms the listed PLE/RUF ids exist and PLE2511 does not.
  • Source*: vibes tools/prompt_injection_scanner.py, docs/ROADMAP.md (lines 167–173), observations/systems/10-mcp-protocol-boundaries-and-stateless-transport-constraints.md

Update 2026-10-08: refinement

The gap stands. RUF runs since v0.2.26 (pyproject.toml:102), so PR A adds only PLE2502, PLE2510, PLE2512-PLE2515. The detector call sites moved: ai/review/runner.py:1524-1538, :1735, :1755, :1938, :1987; ai/review/classification.py:318-330. No item exists for the MCP consumer, so it stays out of scope. The prompt-echo failure gets its own admission reason, apart from canary-failed (review/admission.py:99).

Proposed design

Problem statement

The devops-cli lacks a mechanism to detect and prevent prompt-injection smuggling attacks, which can bypass existing sanitization measures. This vulnerability allows attackers to inject malicious content through zero-width characters, tag-blocks, and other Unicode manipulations that are not currently filtered out during review or scan processes.

Acceptance criteria

  • Criterion 1: A new devops scan injection command is added that can detect prompt-injection smuggling attacks
    Verification: Running devops scan injection produces SARIF output with findings for detected injection attempts
  • Criterion 2: The injection detector identifies Tag-block characters (U+E0020-U+E003B) and reports them as INJ001 findings
    Verification: A test file containing Tag-block characters triggers an INJ001 finding in the SARIF output
  • Criterion 3: The injection detector identifies format-character runs (Unicode category Cf) and reports them as INJ002 findings
    Verification: A test file containing format characters triggers an INJ002 finding in the SARIF output
  • Criterion 4: The injection detector identifies delimiters that are escaped but not deleted and reports them as INJ003 findings
    Verification: A test file containing delimiter sequences triggers an INJ003 finding in the SARIF output
  • Criterion 5: The injection detector identifies exfiltration links and reports them as INJ005 findings
    Verification: A test file containing URL-like patterns that could be used for exfiltration triggers an INJ005 finding in the SARIF output
  • Criterion 6: The system includes a canary audit mechanism that fails the review run when injection is detected
    Verification: When a scan injection detects an attack, it returns a non-zero exit code indicating failure

Key questions

  • What are the specific Unicode character sequences that need to be detected for prompt-injection smuggling?: The detector needs to identify Tag-block characters (U+E0020-U+E003B), format-character runs (Unicode category Cf), delimiters that are escaped but not deleted, and exfiltration links. [sources: src/devops_cli/ai/text_utils.py:36-41]
  • What Ruff rules need to be added to enforce injection detection?: Ruff PLE2502, PLE2510, PLE2512-PLE2515, and RUF001-RUF003 rules need to be added to pyproject.toml [sources: pyproject.toml:76]
  • Should the injection detection also check auto-fix patches?: No, auto-fix/apply-patch was removed in feat(review): remove unverified auto-fix and apply-patch claims (#601) #624, so the run generates no patches and there is no patch surface to audit. [sources: src/devops_cli/ai/text_utils.py:36-41]
  • What should happen when an injection is detected during a review?: When an injection is detected, the review run should fail with EGR005 error code. [sources: src/devops_cli/ai/text_utils.py:36-41]

Open questions

  • How will the new injection detection be integrated into existing review processes? (missing verified source)

Fit

Needs splitting into 2 items:

  1. PR A: Add pure-function security/prompt_injection.py with injection detection rules and devops scan injection command
  2. PR B: Integrate injection detector into review hot paths and add canary audit mechanism

Suspected block

None.

Dependencies

None.

Activity

  1. added this to the v0.2.23 milestone on Sep 25, 2026
  2. added
    type/feature
    scope/cli
    priority/p2-medium
    on Sep 25, 2026
  3. modified the milestones: v0.2.23, v0.2.24 on Sep 28, 2026
  4. removed this from the v0.2.23 milestone on Oct 1, 2026
  5. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from the shipped v0.2.23 to the backlog. It is still valid (checked 2026-10-01), and P2 items don't displace P1 work in the planned releases.

  6. added
    scope/security
    and removed
    scope/cli
    on Oct 2, 2026
  7. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    More evidence for this issue from the devsecops review session 20261001-224227 (2026-10-02). Each finding below was triaged against release/v0.2.25 (c279c18), judged real and covered by this issue, and then upheld by a second agent that tried to refute it.

    • Incomplete Prompt Injection Smuggling Detector Implementation (src/devops_cli/security/sanitizer.py:284, re-rated LOW): The roadmap text accurately describes an open backlog item. The gap is real: src/devops_cli/security/prompt_injection.py doesn't exist, devops scan injection doesn't exist, and the sanitizers match tag names only, so Tag-block, zero-width and bidi characters and chat-template delimiters in reviewed (untrusted) files reach the review prompt unflagged. Open issue feat(cli): prompt-injection smuggling detector and canary audit (devops scan injection) #589 ('prompt-injection smuggling detector and canary audit (devops scan injection)') covers it.
  8. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #417. This item detects smuggled instructions; #417's adversarial corpus tests resistance and gains Tag-block and zero-width variants after this item's PR A. Found by the 2026-10-08 backlog review.

  9. modified the milestones: v0.2.39, v0.2.38 on Oct 17, 2026
  10. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Proposal needs splitting into 2 items at 3dd7fa6 (see proposed design in issue body).

  11. modified the milestones: v0.2.38, on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p2-mediumscope/securitytype/feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions