cursorrules / rules
Cursor rule88 starsChanged 13 months agoMITView on GitHub
Detect and prevent broken access control vulnerabilities in Python applications as defined in OWASP Top 10:2021-A01
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository70 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/accessibility-standards.mdcCursor rule
- .cursor/rules/api-standards.mdcCursor rule
- .cursor/rules/behat-ai-guide.mdcCursor rule
- .cursor/rules/behat-steps.mdcCursor rule
- .cursor/rules/build-optimization.mdcCursor rule
- .cursor/rules/code-generation-standards.mdcCursor rule
- .cursor/rules/confluence-editing-standards.mdcCursor rule
- .cursor/rules/cursor-rules.mdcCursor rule
- .cursor/rules/debugging-standards.mdcCursor rule
- .cursor/rules/docker-compose-standards.mdcCursor rule
- .cursor/rules/drupal-authentication-failures.mdcCursor rule
- .cursor/rules/drupal-broken-access-control.mdcCursor rule
- .cursor/rules/drupal-cryptographic-failures.mdcCursor rule
- .cursor/rules/drupal-database-standards.mdcCursor rule
- .cursor/rules/drupal-file-permissions.mdcCursor rule
- .cursor/rules/drupal-injection.mdcCursor rule
- .cursor/rules/drupal-insecure-design.mdcCursor rule
- .cursor/rules/drupal-integrity-failures.mdcCursor rule
- .cursor/rules/drupal-logging-failures.mdcCursor rule
- .cursor/rules/drupal-security-misconfiguration.mdcCursor rule
- .cursor/rules/drupal-ssrf.mdcCursor rule
- .cursor/rules/drupal-vulnerable-components.mdcCursor rule
- .cursor/rules/generic_bash_style.mdcCursor rule
- .cursor/rules/git-commit-standards.mdcCursor rule
- .cursor/rules/github-actions-standards.mdcCursor rule
- .cursor/rules/improve-cursorrules-efficiency.mdcCursor rule
- .cursor/rules/javascript-broken-access-control.mdcCursor rule
- .cursor/rules/javascript-cryptographic-failures.mdcCursor rule
- .cursor/rules/javascript-identification-authentication-failures.mdcCursor rule
- .cursor/rules/javascript-injection.mdcCursor rule
- .cursor/rules/javascript-insecure-design.mdcCursor rule
- .cursor/rules/javascript-performance.mdcCursor rule
- .cursor/rules/javascript-security-logging-monitoring-failures.mdcCursor rule
- .cursor/rules/javascript-security-misconfiguration.mdcCursor rule
- .cursor/rules/javascript-server-side-request-forgery.mdcCursor rule
- .cursor/rules/javascript-software-data-integrity-failures.mdcCursor rule
- .cursor/rules/javascript-standards.mdcCursor rule
- .cursor/rules/javascript-vulnerable-outdated-components.mdcCursor rule
- .cursor/rules/lagoon-docker-compose-standards.mdcCursor rule
- .cursor/rules/lagoon-yml-standards.mdcCursor rule
- .cursor/rules/multi-agent-coordination.mdcCursor rule
- .cursor/rules/new-pull-request.mdcCursor rule
- .cursor/rules/node-dependencies.mdcCursor rule
- .cursor/rules/php-drupal-best-practices.mdcCursor rule
- .cursor/rules/php-drupal-development-standards.mdcCursor rule
- .cursor/rules/php-memory-optimisation.mdcCursor rule
- .cursor/rules/project-definition-template.mdcCursor rule
- .cursor/rules/pull-request-changelist-instructions.mdcCursor rule
- .cursor/rules/python-authentication-failures.mdcCursor rule
- .cursor/rules/python-cryptographic-failures.mdcCursor rule
- .cursor/rules/python-injection.mdcCursor rule
- .cursor/rules/python-insecure-design.mdcCursor rule
- .cursor/rules/python-integrity-failures.mdcCursor rule
- .cursor/rules/python-logging-monitoring-failures.mdcCursor rule
- .cursor/rules/python-security-misconfiguration.mdcCursor rule
- .cursor/rules/python-ssrf.mdcCursor rule
- .cursor/rules/python-vulnerable-outdated-components.mdcCursor rule
- .cursor/rules/react-patterns.mdcCursor rule
- The first 60 shown.
The file
We split this python-broken-access-control.mdc into the rules it gives an agent
12 rules. About 0 are common, 12 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈12
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 67
Django: Use built-in authentication and permission decorators/mixins
- Distinctive: line 71
Flask: Use Flask-Login or similar extensions
- Distinctive: line 75
FastAPI: Use dependency injection for security
- Distinctive: line 82
Use deny-by-default approach (whitelist vs blacklist)
- Distinctive: line 85
Use contextual access control (time, location, device-based restrictions when appropriate)
- Distinctive: line 90
Use UUIDs instead of sequential IDs when possible
- Distinctive: line 91
Always verify ownership or permission before allowing operations on objects
- Distinctive: line 95
Use token-based authentication with proper validation
- Distinctive: line 101
Write tests specifically for authorization logic
- Distinctive: line 102
Test vertical access control (different permission levels)
- Distinctive: line 103
Test horizontal access control (same permission level, different users)
- Distinctive: line 104
Verify access control works after session timeout/expiration
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: Detect and prevent broken access control vulnerabilities in Python applications as defined in OWASP Top 10:2021-A01
globs: *.py
alwaysApply: false
---
# 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.
<rule>
name: python_broken_access_control
description: Detect and prevent broken access control vulnerabilities in Python applications as defined in OWASP Top 10:2021-A01
filters:
- type: file_extension
pattern: "\\.(py)$"
- type: file_path
pattern: ".*"
actions:
- type: enforce
conditions:
# Pattern 1: Missing access control in Flask routes
- pattern: "@(app|blueprint)\\.route\\([^)]*\\)\\s*\\n\\s*def\\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\\(\\s*request\\.(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
2. **General Access Control Principles:**
- Implement access control at the server side, never rely on client-side checks
- Use deny-by-default approach (whitelist vs blacklist)
- Implement proper session management
- Apply principle of least privilege
- Use contextual access control (time, location, device-based restrictions when appropriate)
3. **Object-Level Authorization:**
- Validate user has permission to access specific resources
- Implement row-level security for database access
- Use UUIDs instead of sequential IDs when possible
- Always verify ownership or permission before allowing operations on objects
4. **API Security:**
- Implement proper authentication for all API endpoints
- Use token-based authentication with proper validation
- Apply rate limiting to prevent brute force attacks
- Implement proper CORS configuration
- Log and monitor access control failures
5. **Testing Access Control:**
- Write tests specifically for authorization logic
- Test vertical access control (different permission levels)
- Test horizontal access control (same permission level, different users)
- Verify access control works after session timeout/expiration
- type: validate
conditions:
# Check 1: Proper Django permission usage
- pattern: "@login_required|@permission_required|LoginRequiredMixin|PermissionRequiredMixin"
message: "Using Django's built-in access control mechanisms."
# Check 2: Proper Flask authentication
- pattern: "@login_required|current_user\\.is_authenticated|@auth\\.login_required"
message: "Implementing proper Flask authentication checks."
# Check 3: Object-level permission checks
- pattern: "\\.has_permission\\(|has_object_permission\\(|can_view\\(|can_edit\\("
message: "Implementing object-level permission checks."
# Check 4: FastAPI security dependencies
- pattern: "Depends\\(get_current_user\\)|Security\\(|HTTPBearer\\("
message: "Using FastAPI's security dependency injection."
metadata:
priority: 90
version: "1.0"
tags:
- python
- security
- access_control
- owasp
- language:python
- category:security
- subcategory:authorisation
- subcategory:access-control
- standard:owasp-top10
- risk:a01-broken-access-control
- framework:django
- framework:flask
- framework:fastapi
references:
- https://owasp.org/Top10/A01_2021-Broken_Access_Control/
- https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html
- https://cheatsheetseries.owasp.org/cheatsheets/Access_Control_Cheat_Sheet.html
- https://docs.djangoproject.com/en/stable/topics/auth/default/
- https://flask-login.readthedocs.io/en/latest/
- https://fastapi.tiangolo.com/tutorial/security/
- https://cheatsheetseries.owasp.org/cheatsheets/Access_Control_Cheat_Sheet.html
</rule> Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

