python-broken-access-control

Python security rules based on OWASP A01, the category covering broken access control. They look for routes, views, and object lookups that may not check user permissions.

In plain words
What is it for?
Reviewing Flask and Django code for login checks, permission checks, and unsafe access to records by ID.
Why use it?
They help find cases where someone could access another user’s data or a restricted action.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/abderrahimghazali/cursor-rules/python-broken-access-control
Clone the repo
git clone --depth 1 https://github.com/abderrahimghazali/cursor-rules

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,829 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01829
Opus 5 $0.00000 $0.00915
Sonnet 5 $0.00000 $0.00366
Haiku 4.5 $0.00000 $0.00183

Measured yesterday against content hash 534567c43798, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

python-broken-access-control scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/python-broken-access-control.mdc · 149 lines

How it starts

The opening of the file, as written. The whole thing — 149 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Python Broken Access Control Security Standards (OWASP A01:2021)

This rule enforces security best practices to prevent broken access control vulnerabilities in Python applications, as defined in OWASP Top 10:2021-A01.

actions:

  • type: enforce conditions:

    Pattern 1: Missing access control in Flask routes

    • pattern: "@(app|blueprint)\.route\([^)]\)\s\n\sdef\s+[a-zA-Z0-9_]+\([^)]\):\s*(?![^#]*@login_required|[^#]*current_user\.|[^#]*session\[)" message: "Flask route lacks access control. Consider using @login_required or checking user permissions within the function."

    Pattern 2: Missing access control in Django views

    • pattern: "class\s+[A-Za-z0-9_]+View\((?!LoginRequiredMixin|PermissionRequiredMixin|UserPassesTestMixin)[^)]*\):" message: "Django class-based view lacks access control mixins. Consider using LoginRequiredMixin, PermissionRequiredMixin, or UserPassesTestMixin."

    Pattern 3: Insecure direct object reference

    • pattern: "(get|filter|find)_by_id\(\srequest\.(GET|POST|args|form|json)\[['"][^'"]+['"]\]\s\)" message: "Potential insecure direct object reference (IDOR). Validate that the current user has permission to access this object."

    Pattern 4: Hardcoded role checks

    • pattern: "if\s+user\.role\s*==\s*['"]admin['"]|if\s+user\.(is_staff|is_superuser)\s*:" message: "Hardcoded role checks can be fragile. Consider using a permission system or role-based access control framework."

    Pattern 5: Missing authorization in FastAPI

    • pattern: "@(app|router)\.([a-z]+)\([^)]\)\s\n\s*(?:async\s+)?def\s+[a-zA-Z0-9_]+\([^)]\):\s(?![^#]*Depends\(|[^#]*Security\(|[^#]*HTTPBearer\()" message: "FastAPI endpoint lacks security dependencies. Consider using Depends(get_current_user) or similar security dependencies."

    Pattern 6: Bypassing access control with admin flags

    • pattern: "if\s+request\.(GET|POST|args|form|json)\[['"]admin['"]\]|if\s+request\.(GET|POST|args|form|json)\[['"]debug['"]\]" message: "Dangerous admin/debug flags in request parameters could bypass access control. Remove or secure these backdoors."

    Pattern 7: Insecure use of eval or exec with user input

    • pattern: "eval\(|exec\(.*request\." message: "Extremely dangerous use of eval() or exec() with user input can lead to code execution. Avoid these functions entirely."

    Pattern 8: Missing access control in API endpoints

    • pattern: "@api_view\(|@api\.route\(|@app\.api_route\(" message: "API endpoint may lack access control. Ensure proper authentication and authorization checks are implemented."

    Pattern 9: Insecure Flask session usage

    • pattern: "session\[['"][^'"]+['"]\]\s*=\s*request\." message: "Setting session variables directly from request data without validation can lead to session-based access control bypasses."

    Pattern 10: Missing CSRF protection

    • pattern: "class\s+[A-Za-z0-9_]+Form\((?!.csrf).\):|@csrf_exempt" message: "Form or view appears to be missing CSRF protection. Ensure CSRF tokens are properly implemented."
  • type: suggest message: | Python Access Control Best Practices:

    1. Framework-Specific Controls:
      • Django: Use built-in authentication and permission decorators/mixins
        • @login_required, LoginRequiredMixin
        • @permission_required, PermissionRequiredMixin
        • UserPassesTestMixin for custom permission logic
      • Flask: Use Flask-Login or similar extensions
        • @login_required decorator
        • current_user.is_authenticated checks
        • Role-based access control with Flask-Principal
      • FastAPI: Use dependency injection for security
        • Depends(get_current_user) pattern
        • OAuth2 with Security(oauth2_scheme)
        • JWT validation middleware

Read the full file on GitHub · 149 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 149 lines · 1,829 tokens per session scan A 534567c43798

Subscribe to this mod's changes

python-broken-access-control is a cursor rule published in the GitHub repository abderrahimghazali/cursor-rules (2 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,829 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.