Skip to content

chore: ruff F401/F841 + workflow least-privilege (16 CodeQL findings cleared)#79

Open
Prekzursil wants to merge 2 commits into
mainfrom
chore/leveraged-fix-ruff-py-autofix
Open

chore: ruff F401/F841 + workflow least-privilege (16 CodeQL findings cleared)#79
Prekzursil wants to merge 2 commits into
mainfrom
chore/leveraged-fix-ruff-py-autofix

Conversation

@Prekzursil

@Prekzursil Prekzursil commented Jun 5, 2026

Copy link
Copy Markdown
Owner

User description

Quality-Zero-Platform: leveraged drive-to-zero

Two safe, high-leverage, single-rule CodeQL transforms. No behavior change.
Every edit is dead-code removal or static CI hardening; no logic was modified.

Plays applied

1. Python dead-code autofix (ruff single-rule transform) — 14 CodeQL alerts

  • py/unused-import (13 alerts / 14 import names): ruff check backend --exclude venv --select F401 --fix. Removes genuinely-dead imports across serializers, views, tasks, tests, urls, adapters. users/urls.py's two unused names (GoogleLogin, GithubLogin) count as one CodeQL alert.
  • py/unused-local-variable (1 alert): removed the user = request.user dead store in PasswordChangeView.post — pure RHS, never read, auth already enforced by the IsAuthenticated permission class. (Done manually; ruff classifies the F841 fix as "unsafe" and I declined --unsafe-fixes.)

2. CI least-privilege (actions/missing-workflow-permissions) — 2 CodeQL alerts

  • Added top-level permissions: contents: read to django.yml and django_ci.yml. Both are pure test/lint runners (checkout → setup-python → pip install → compileall/flake8); neither pushes, comments, or uploads, so read-only is correct least privilege.

Total: 16 CodeQL alerts cleared (14 Python + 2 Actions).

Verification

  • ruff check backend --exclude venv --select F401All checks passed
  • python -m compileallclean on all 11 changed Python files
  • python -c "import yaml; yaml.safe_load(...)" → both workflows parse with the new permissions block
  • ruff 0.15.12; Python 3.14. Full pytest not run (pinned Django/deps don't install on 3.14 in this sandbox) — dead-import/dead-store removal + ruff-clean + compileall is sufficient behavior-preserving evidence for these no-build-needed plays.

Deliberately NOT touched (residual / needs-care)

  • backend/venv/ (33 CodeQL alerts) — left entirely to the open venv-purge PR chore: purge committed backend/venv from version control (coverage + static-analysis hygiene) #78; not re-touched.
  • 15 path-injection (9 py + 6 js) + 1 partial-ssrf + js/user-controlled-bypass — security fixes are not mechanical/uniform; need per-site review.
  • 2 py/multiple-definition (redefinition tracing = judgment), 5 py/commented-out-code (deliberate developer-reference scaffolding), 2 .tsx js/unused-local (need the frontend npm toolchain) — left for a separate, scoped pass.
  • The leaked/operator-rotated secret and secrets:S6687/python:S2068/python:S6437 — untouched.

Dependabot

No config change. .github/dependabot.yml already has optimal grouped (patch/minor) updates per ecosystem with major-version ignores, and security updates are firing correctly as individual + grouped PRs (e.g. #48, #23, #22, #76, #59). The 104 security alerts collapse via those existing Dependabot PRs — an operator merge decision, out of scope here.

Part of the QZP drive-to-zero campaign. Reviewer merges; no auto-merge.


Summary by cubic

Removed dead Python code with ruff F401/F841 and set read-only workflow permissions to enforce least privilege. No behavior change; clears 16 CodeQL alerts across backend and CI.

Written for commit 407cce5. Summary will update on new commits.

Review in cubic


CodeAnt-AI Description

Clean up unused code and restrict CI access

What Changed

  • Removed unused imports and dead local variables from backend code without changing app behavior
  • Removed an unused test import placeholder from two test files
  • Dropped unused login imports and an unused redirect import
  • Limited the GitHub Actions workflows to read-only repository access

Impact

✅ Fewer static analysis warnings
✅ Lower workflow permissions
✅ No change to app behavior

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Prekzursil added 2 commits June 5, 2026 09:12
Leveraged single-rule transform for the Quality-Zero-Platform drive-to-zero
campaign. Removes dead code that CodeQL flags as unused, behavior-preserving:

- 14x py/unused-import (F401): ruff check --select F401 --fix, scoped to
  backend/ with --exclude venv. Removes genuinely-dead imports across
  serializers, views, tasks, tests, urls and adapters.
- 1x py/unused-local-variable (F841): removed `user = request.user` dead
  store in PasswordChangeView.post (pure RHS, never read; auth already
  enforced by IsAuthenticated permission class).

Verification: `ruff check backend --exclude venv --select F401` clean;
`python -m compileall` clean on all 11 changed files. No venv files touched
(the committed backend/venv purge is handled separately in PR #78).
…(2 findings)

Clears 2x actions/missing-workflow-permissions (CodeQL). Both workflows are
pure test/lint runners (checkout -> setup-python -> pip install -> compileall/
flake8) that only read the repo; neither pushes, comments, or uploads. Adds a
top-level `permissions: contents: read` block to each (least privilege).

Part of the Quality-Zero-Platform drive-to-zero campaign. Static YAML only,
no toolchain/build needed.
@devloai

devloai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Unable to trigger custom agent "Code Reviewer". You have run out of credits 😔
Please upgrade your plan or buy additional credits from the subscription page.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@codeant-ai

codeant-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Prekzursil, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 5 minutes and 55 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 009d71eb-d309-4703-9621-023db88901b5

📥 Commits

Reviewing files that changed from the base of the PR and between a12be04 and 407cce5.

📒 Files selected for processing (13)
  • .github/workflows/django.yml
  • .github/workflows/django_ci.yml
  • backend/problems/serializers.py
  • backend/problems/tests.py
  • backend/problems/views.py
  • backend/submissions/judge_utils/comparison.py
  • backend/submissions/judge_utils/execution.py
  • backend/submissions/serializers.py
  • backend/submissions/tasks.py
  • backend/submissions/tests.py
  • backend/users/adapters.py
  • backend/users/urls.py
  • backend/users/views.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/leveraged-fix-ruff-py-autofix

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.

@sonarqubecloud

sonarqubecloud Bot commented Jun 5, 2026

Copy link
Copy Markdown

@codeant-ai codeant-ai Bot added the size:XS This PR changes 0-9 lines, ignoring generated files label Jun 5, 2026
@codeant-ai

codeant-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

@cubic-dev-ai cubic-dev-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.

No issues found across 13 files

Re-trigger cubic

@sentry

sentry Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codacy-production

codacy-production Bot commented Jun 5, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0 (≤ 10 complexity)
Duplication 0 (≤ 0 duplication)

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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

Labels

size:XS This PR changes 0-9 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant