Skip to content

Harden SecurityPolicy risk detection and fix git -C false positive - #852

Draft
yacosta738 wants to merge 1 commit into
mainfrom
jules-2145600012477397089-031a5a91
Draft

Harden SecurityPolicy risk detection and fix git -C false positive#852
yacosta738 wants to merge 1 commit into
mainfrom
jules-2145600012477397089-031a5a91

Conversation

@yacosta738

Copy link
Copy Markdown
Contributor

This PR hardens the SecurityPolicy in the agent-runtime to prevent several classes of security bypasses while simultaneously fixing a common false positive.

Key Changes

  1. Verb Detection Hardening: In is_medium_risk_command, changed .first().is_some_and() to .iter().any(). This ensures that subcommands like commit or install are detected even when preceded by global flags (e.g., git -C . commit or npm --loglevel=silent install).
  2. Quote-based Bypass Prevention: In command_risk_level, arguments are now de-quoted using strip_all_quotes before being checked against risk-bearing verbs. This prevents bypasses like git "commit".
  3. Case-Sensitive Flag Handling:
    • Updated is_segment_valid to pass original-case arguments to is_args_safe.
    • Implemented case-sensitive matching for git -c (blocked) and git -C (allowed). This fixes the false positive where git -C was incorrectly blocked while hardening against git -ccore.editor=cat.
    • Maintained case-insensitive behavior for other tools (npm, pnpm, yarn, find) by explicitly lowercasing within their respective check logic.
  4. Regression Testing: Added a comprehensive test case test_git_security_hardening_and_false_positives to verify these improvements.

Impact Summary

  • Security: Closes bypasses in the risk classification engine and hardens configuration injection checks.
  • Performance: Reduces redundant string allocations in the validation path by deferring lowercasing to tool-specific logic.
  • Usability: Resolves an issue where valid git commands with directory flags were being incorrectly blocked.

PR created automatically by Jules for task 2145600012477397089 started by @yacosta738

…lse positive

- Update `is_medium_risk_command` to detect verbs anywhere in the argument list, preventing bypasses where global flags precede the verb (e.g., `git -C . commit`).
- Update `command_risk_level` to de-quote arguments before risk classification, preventing bypasses like `git "commit"`.
- Refine `is_args_safe` to use case-preserving arguments for `git`, implementing case-sensitive matching for the `-c` flag (detecting configuration injection) while allowing the safe, case-sensitive `-C` directory flag.
- Add regression test `test_git_security_hardening_and_false_positives` to `policy.rs`.
- Apply automated formatting to GitHub workflows.

Security Impact:
- Risk reduced: Prevents bypasses of risk-based approval gates using global flags or quotes.
- Attack surface: Narrowed by blocking configuration injection via `git -c` and similar flags across package managers.
- Why safe: Maintains existing allowlists and adds specific, low-regret hardening to known bypass vectors.

Performance Impact:
- Metric: Argument processing.
- Before: $O(N)$ lowercasing of all arguments in `is_segment_valid`.
- After: Case-preserving arguments are used directly, avoiding unnecessary allocations in `is_args_safe` for the common path of safe commands.
- Expected: Negligible change in CPU usage, reduced allocation pressure in the validation hot path.
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

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: ASSERTIVE

Plan: Pro

Run ID: 104c93c6-cb4e-46a2-93af-3a917428cd8f

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
  • Commit unit tests in branch jules-2145600012477397089-031a5a91

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 size/s Denotes a small change size label Jun 20, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying corvus with  Cloudflare Pages  Cloudflare Pages

Latest commit: d8879d6
Status: ✅  Deploy successful!
Preview URL: https://df906b1b.corvus-42x.pages.dev
Branch Preview URL: https://jules-2145600012477397089-03.corvus-42x.pages.dev

View logs

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

Labels

size/s Denotes a small change size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant