Skip to content

fix: address critical quality-debt in sanity-check.sh (GH#2866)#2870

Merged
alex-solovyev merged 2 commits intomainfrom
bugfix/fix-sanity-check-quality-debt-2866
Mar 5, 2026
Merged

fix: address critical quality-debt in sanity-check.sh (GH#2866)#2870
alex-solovyev merged 2 commits intomainfrom
bugfix/fix-sanity-check-quality-debt-2866

Conversation

@alex-solovyev
Copy link
Collaborator

Summary

Fixes all 5 findings from the PR #2845 CodeRabbit/Gemini review on .agents/scripts/supervisor-archived/sanity-check.sh:

  • CRITICAL: Remove 2>/dev/null from db() calls (lines 487, 700, 720, 721, 865) to surface database connection failures, SQL errors, and permission problems instead of silently swallowing them
  • MEDIUM: Replace dot-only regex escaping (sed 's/\./\\./g') with a full _escape_regex() helper that escapes all BRE/ERE metacharacters (., /, [, ], *, ^, $, (, ), +, ?, {, }, |, \), preventing regex/sed injection via crafted task IDs
  • MEDIUM: Add task_id format validation (^t[0-9]+(\.[0-9]+)*$) at the entry point of _execute_sanity_action() to reject malformed IDs before they reach any regex/sed operation
  • MEDIUM: Replace grep ... 2>/dev/null on $todo_file with explicit [[ -f "$todo_file" ]] guards so file-not-found errors are visible
  • MEDIUM: Mitigate prompt injection from DB data in the AI prompt by stripping control characters, wrapping the state snapshot in DATA_START/DATA_END boundary markers, and adding an explicit anti-injection instruction

ShellCheck: zero violations.

Closes #2866

…eview (GH#2866)

- Remove 2>/dev/null from db() calls to surface database errors (critical)
- Replace dot-only regex escaping with full metacharacter _escape_regex() helper
- Add task_id format validation to reject malformed IDs before regex/sed use
- Replace grep 2>/dev/null with explicit file-existence checks
- Add prompt injection mitigation: control char stripping, DATA boundary markers,
  and anti-injection instruction for AI prompt containing DB data

Closes #2866
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

Warning

Rate limit exceeded

@marcusquinn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 13 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f843945a-e88a-480d-b212-9af42fc09044

📥 Commits

Reviewing files that changed from the base of the PR and between fcfc842 and f1c64f5.

📒 Files selected for processing (1)
  • .agents/scripts/supervisor-archived/sanity-check.sh
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/fix-sanity-check-quality-debt-2866

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 5, 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 significantly enhances the robustness and security of the sanity-check.sh script. It addresses several critical and medium-severity quality-debt items by improving error reporting, preventing potential injection vulnerabilities in regex and AI prompts, and strengthening input validation for task identifiers. The changes collectively make the script more resilient to unexpected inputs and provide clearer diagnostics when issues arise.

Highlights

  • Error Visibility: Removed 2>/dev/null from db() calls to ensure database connection failures, SQL errors, and permission issues are no longer silently suppressed.
  • Regex Injection Prevention: Introduced a comprehensive _escape_regex() helper to escape all BRE/ERE metacharacters, replacing the previous dot-only escaping, thereby preventing regex/sed injection via crafted task IDs.
  • Input Validation: Added strict task_id format validation (^t[0-9]+(\.[0-9]+)*$) at the entry point of _execute_sanity_action() to reject malformed IDs before they can be used in regex operations.
  • File Existence Checks: Replaced grep ... 2>/dev/null with explicit [[ -f "$todo_file" ]] guards to make file-not-found errors visible instead of suppressing them.
  • AI Prompt Injection Mitigation: Implemented measures to strip control characters from DB data in AI prompts, wrapped state snapshots in DATA_START/DATA_END boundary markers, and added an explicit anti-injection instruction to guide the AI.
Changelog
  • .agents/scripts/supervisor-archived/sanity-check.sh
    • Added a new _escape_regex function to safely escape all BRE/ERE metacharacters for use in grep/sed patterns.
    • Removed 2>/dev/null from multiple db command invocations to expose database errors.
    • Replaced all instances of sed 's/\./\\./g' with calls to the new _escape_regex function for improved regex safety.
    • Implemented a regular expression-based validation for task_id format at the entry point of _execute_sanity_action.
    • Introduced file existence checks ([[ -f "$todo_file" ]]) before grep operations on the $todo_file variable.
    • Modified the _build_sanity_prompt function to sanitize state snapshots by stripping control characters and wrapping the data with DATA_START/DATA_END markers, along with an explicit anti-injection instruction for the AI.
Activity
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

github-actions bot commented Mar 5, 2026

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Thu Mar 5 02:13:15 UTC 2026: Code review monitoring started
Thu Mar 5 02:13:15 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 107

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 107
  • VULNERABILITIES: 0

Generated on: Thu Mar 5 02:13:18 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 a series of excellent quality and security improvements to sanity-check.sh. The changes effectively address several potential issues, including suppressed database errors, incomplete regex escaping, missing input validation, and prompt injection vulnerabilities. Removing error suppression from db() and grep calls will significantly improve debuggability. The new _escape_regex function and task_id validation provide robust protection against injection attacks. The prompt sanitization is also a great step towards hardening the script against malicious inputs. Overall, these are high-quality fixes. I have one minor suggestion to apply the grep error handling pattern consistently throughout the file.

Note: Security Review did not run due to the size of the PR.

local escaped_oid
escaped_oid=$(printf '%s' "$oid" | sed 's/\./\\./g')
escaped_oid=$(_escape_regex "$oid")
if ! grep -qE "^[[:space:]]*- \[.\] ${escaped_oid}( |$)" "$todo_file" 2>/dev/null; then

Choose a reason for hiding this comment

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

medium

This grep call still suppresses stderr with 2>/dev/null. While other grep calls in this PR were updated to use [[ -f "$todo_file" ]] guards, this one appears to have been missed. Suppressing stderr can hide important errors like file-not-found or permission issues.

For consistency and to improve robustness, this should be updated. The correct logic for a negative check (! grep) is to use an || condition to check for file existence first.

Suggested change
if ! grep -qE "^[[:space:]]*- \[.\] ${escaped_oid}( |$)" "$todo_file" 2>/dev/null; then
if [[ ! -f "$todo_file" ]] || ! grep -qE "^[[:space:]]*- \[.[] ${escaped_oid}( |$)" "$todo_file"; then
References
  1. Avoid using 2>/dev/null for blanket suppression of command errors in shell scripts to ensure that authentication, syntax, or system issues remain visible for debugging.
  2. Avoid using 2>/dev/null to suppress errors on file operations if the file's existence has already been verified by a preceding check (e.g., [[ -f "$file" ]] or an early return). This practice is redundant for 'file not found' errors and can mask other important issues like permissions problems.

…ence guards

Address Gemini Code Assist review feedback on PR #2870: the grep at
line 342 (orphan detection) still suppressed stderr. Apply the same
[[ -f "$todo_file" ]] guard pattern consistently to all remaining
grep calls on $todo_file (lines 260, 342, 996-999) so file-not-found
and permission errors are visible.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Thu Mar 5 02:23:37 UTC 2026: Code review monitoring started
Thu Mar 5 02:23:37 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 107

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 107
  • VULNERABILITIES: 0

Generated on: Thu Mar 5 02:23:40 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 5, 2026

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

Labels

bug Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quality-debt: .agents/scripts/supervisor-archived/sanity-check.sh — PR #2845 review feedback (critical)

2 participants