Skip to content

fix(maintainability): keep --policy-file inside the --repo directory - #886

Merged
magrhino merged 2 commits into
mainfrom
claude/failing-ci-main-041775
Oct 16, 2026
Merged

magrhino merged 2 commits into
mainfrom
claude/failing-ci-main-041775

Conversation

@magrhino

Copy link
Copy Markdown
Owner

Summary

The SonarCloud quality gate on main has failed on every commit since #792 (2026-09-30). Its only open finding is pythonsecurity:S8707, a path traversal through LLM-supplied CLI arguments: read_policy() in scripts/check_maintainability.py opens any --policy-file path. That code has not changed since #733. SonarCloud began reporting this rule after #733 merged, and PR analysis looks only at changed lines, so every PR passed the required Sonar check while main stayed red.

  • read_policy() now resolves --policy-file and the --repo root with realpath, which follows symlinks. If the policy file is outside the repository, the checker stops with a plain-language error and exit code 2.
  • A new test checks that the checker rejects both a policy file outside the repository and a symlink inside it that points outside.
  • docs/DEVELOPMENT.md now says where the external policy file must be.

Scope

  • This PR has one reviewable objective
  • Follow-up work, stacked PRs, or intentionally deferred changes are called out here: the main gate stays red until SonarCloud analyzes main after this merges and closes the issue. Nothing alerts anyone when the main gate fails, so that is worth a separate follow-up.

Checklist

  • Tests added or updated
  • README.md or docs/ updated if install, deployment, config, or user-facing behavior changed
  • N/A - no environment variables or example config changed
  • Release Please/changelog impact considered; no manual CHANGELOG.md edit needed outside release prep

Test plan

  • tests/run-all.sh: N/A - change is confined to the maintainability checker

  • Focused test(s):

    • python -m pytest tests/test_python_maintainability*.py (158 passed)
    • python -m py_compile scripts/check_maintainability.py
    • New test fails against the previous checker and passes with this change
    • ruff check on touched files
  • Docker or Compose validation, if container behavior changed: N/A

@sourcery-ai

sourcery-ai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Sorry @magrhino, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 16 hours and 59 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4e4a2dce-b87e-4f91-b57a-dfe18f7cc53c
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@sourcery-ai

sourcery-ai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

The checker now prevents path traversal through --policy-file by resolving symlinks and requiring the final path to remain under --repo, with regression tests for direct and symlinked external files and updated developer documentation.

File-Level Changes

Change Details Files
Constrain externally supplied policy paths to the repository after resolving symlinks.
  • Resolve both repository and policy paths with realpath.
  • Reject paths outside the repository with exit code 2 and an actionable error.
  • Read the validated policy path with the existing size limit.
scripts/check_maintainability.py
Add regression coverage for direct and symlink-based path traversal.
  • Create a policy outside the repository and a repository symlink pointing to it.
  • Assert both report-only invocations fail with the expected error and status.
tests/test_python_maintainability.py
Document the new location requirement for report-only policy files.
  • State that --policy-file must resolve inside --repo and that symlinks are followed.
docs/DEVELOPMENT.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@magrhino
magrhino force-pushed the claude/failing-ci-main-041775 branch from 26d0094 to dcb3a6d Compare October 16, 2026 01:47
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Oct 16, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@sonarqubecloud

Copy link
Copy Markdown

@magrhino
magrhino enabled auto-merge (squash) October 16, 2026 01:52
@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@magrhino
magrhino merged commit f6201db into main Oct 16, 2026
25 checks passed
@magrhino magrhino mentioned this pull request Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant