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

PR
5mo ago
+9-14

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 F401 → All checks passed
  • python -m compileall → clean 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 #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.


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.