

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
123456 # Python Insecure Design Security Standards (OWASP A04:2021)78This rule enforces security best practices to prevent insecure design vulnerabilities in Python applications, as defined in OWASP Top 10:2021-A04.910<rule>11name: python_insecure_design12description: Detect and prevent insecure design patterns in Python applications as defined in OWASP Top 10:2021-A0413filters:14 - type: file_extension15 pattern: "\\.(py)$"16 - type: file_path17 pattern: ".*"1819actions:20 - type: enforce21 conditions:22 # Pattern 1: Lack of input validation23 - pattern: "def\\s+[a-zA-Z0-9_]+\\([^)]*\\):\\s*(?![^#]*validate|[^#]*clean|[^#]*sanitize|[^#]*check|[^#]*is_valid)"24 message: "Function lacks input validation. Consider implementing validation for all user-supplied inputs."2526 # Pattern 2: Hardcoded business rules27 - pattern: "if\\s+[a-zA-Z0-9_]+\\s*(==|!=|>|<|>=|<=)\\s*['\"][^'\"]+['\"]:"28 message: "Hardcoded business rules detected. Consider using configuration files or database-driven rules for better maintainability."2930 # Pattern 3: Lack of rate limiting31 - pattern: "@(app|api|route|blueprint)\\.(get|post|put|delete|patch)\\([^)]*\\)\\s*\\n\\s*(?![^#]*rate_limit|[^#]*throttle|[^#]*limiter)"32 message: "API endpoint lacks rate limiting. Consider implementing rate limiting to prevent abuse."3334 # Pattern 4: Insecure default configurations35 - pattern: "DEBUG\\s*=\\s*True|DEVELOPMENT\\s*=\\s*True|TESTING\\s*=\\s*True"36 message: "Insecure default configuration detected. Ensure debug/development modes are disabled in production."3738 # Pattern 5: Lack of error handling39 - pattern: "(?<!try:\\s*\\n)[^#]*\\n\\s*(?!except|finally)"40 message: "Consider implementing proper error handling with try-except blocks for operations that might fail."4142 # Pattern 6: Insecure direct object references43 - pattern: "get_object_or_404\\(\\s*[^,]+,\\s*pk\\s*=\\s*request\\.(GET|POST|args|form|json)\\[['\"][^'\"]+['\"]\\]\\s*\\)|get\\(\\s*id\\s*=\\s*request\\.(GET|POST|args|form|json)"44 message: "Potential insecure direct object reference. Validate user's permission to access the requested object."4546 # Pattern 7: Missing authentication checks47 - pattern: "@(app|api|route|blueprint)\\.(get|post|put|delete|patch)\\([^)]*\\)\\s*\\n\\s*(?!.*@login_required|.*@auth\\.login_required|.*@jwt_required|.*current_user|.*request\\.user)"48 message: "Endpoint lacks authentication checks. Consider adding authentication requirements for sensitive operations."4950 # Pattern 8: Lack of proper logging51 - pattern: "except\\s+[a-zA-Z0-9_]+\\s*(?:as\\s+[a-zA-Z0-9_]+)?:\\s*(?!.*logger\\.|.*logging\\.|.*print)"52 message: "Exception caught without proper logging. Implement proper logging for exceptions to aid in debugging and monitoring."5354 # Pattern 9: Insecure file uploads55 - pattern: "request\\.files\\[['\"][^'\"]+['\"]\\]|FileField\\(|FileStorage\\("56 message: "File upload functionality detected. Ensure proper validation of file types, sizes, and implement virus scanning if applicable."5758 # Pattern 10: Lack of security headers59 - pattern: "response\\.(headers|set_header)\\([^)]*\\)|return\\s+Response\\([^)]*\\)|return\\s+make_response\\([^)]*\\)"60 message: "Consider adding security headers (Content-Security-Policy, X-Content-Type-Options, etc.) to HTTP responses."6162 - type: suggest63 message: |64 **Python Secure Design Best Practices:**6566 1. **Implement Defense in Depth:**67 - Layer security controls throughout your application68 - Don't rely on a single security mechanism69 - Assume that each security layer can be bypassed7071 2. **Use Secure Defaults:**72 - Start with secure configurations by default73 - Require explicit opt-in for less secure options74 - Example for Flask:75```python76 app.config.update(77 SESSION_COOKIE_SECURE=True,78 SESSION_COOKIE_HTTPONLY=True,79 SESSION_COOKIE_SAMESITE='Lax',80 PERMANENT_SESSION_LIFETIME=timedelta(hours=1)81 )82```8384 3. **Implement Proper Access Control:**85 - Use role-based access control (RBAC)86 - Implement principle of least privilege87 - Validate access at the controller and service layers88 - Example:89```python90 @app.route('/admin')91 @roles_required('admin') # Using Flask-Security92 def admin_dashboard():93 return render_template('admin/dashboard.html')94```9596 4. **Use Rate Limiting:**97 - Protect against brute force and DoS attacks98 - Example with Flask-Limiter:99```python100 from flask_limiter import Limiter101 limiter = Limiter(app)102103 @app.route('/login', methods=['POST'])104 @limiter.limit("5 per minute")105 def login():106 # Login logic107```108109 5. **Implement Proper Error Handling:**110 - Catch and log exceptions appropriately111 - Return user-friendly error messages without exposing sensitive details112 - Example:113```python114 try:115 # Operation that might fail116 result = perform_operation(user_input)117 except ValidationError as e:118 logger.warning(f"Validation error: {str(e)}")119 return jsonify({"error": "Invalid input provided"}), 400120 except Exception as e:121 logger.error(f"Unexpected error: {str(e)}", exc_info=True)122 return jsonify({"error": "An unexpected error occurred"}), 500123```124125 6. **Use Configuration Management:**126 - Store configuration in environment variables or secure vaults127 - Use different configurations for development and production128 - Example:129```python130 import os131 from dotenv import load_dotenv132133 load_dotenv()134135 DEBUG = os.getenv('DEBUG', 'False') == 'True'136 SECRET_KEY = os.getenv('SECRET_KEY')137 DATABASE_URL = os.getenv('DATABASE_URL')138```139140 7. **Implement Proper Logging:**141 - Log security events and exceptions142 - Include contextual information but avoid sensitive data143 - Use structured logging144 - Example:145```python146 import logging147148 logger = logging.getLogger(__name__)149150 def user_action(user_id, action):151 logger.info("User action", extra={152 "user_id": user_id,153 "action": action,154 "timestamp": datetime.now().isoformat()155 })156```157158 8. **Use Security Headers:**159 - Implement Content-Security-Policy, X-Content-Type-Options, etc.160 - Example with Flask:161```python162 from flask_talisman import Talisman163164 talisman = Talisman(165 app,166 content_security_policy={167 'default-src': "'self'",168 'script-src': "'self'"169 }170 )171```172173 9. **Implement Secure File Handling:**174 - Validate file types, sizes, and content175 - Store files outside the web root176 - Use secure file permissions177 - Example:178```python179 import os180 from werkzeug.utils import secure_filename181182 ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg'}183 MAX_CONTENT_LENGTH = 1 * 1024 * 1024 # 1MB184185 def allowed_file(filename):186 return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS187188 @app.route('/upload', methods=['POST'])189 def upload_file():190 if 'file' not in request.files:191 return jsonify({"error": "No file part"}), 400192193 file = request.files['file']194 if file.filename == '':195 return jsonify({"error": "No selected file"}), 400196197 if file and allowed_file(file.filename):198 filename = secure_filename(file.filename)199 file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))200 return jsonify({"success": True}), 200201202 return jsonify({"error": "File type not allowed"}), 400203```204205 10. **Use Threat Modeling:**206 - Identify potential threats during design phase207 - Implement controls to mitigate identified threats208 - Regularly review and update threat models209210 - type: validate211 conditions:212 # Check 1: Proper input validation213 - pattern: "validate|clean|sanitize|check|is_valid"214 message: "Implementing input validation."215216 # Check 2: Proper error handling217 - pattern: "try:\\s*\\n[^#]*\\n\\s*(except|finally)"218 message: "Using proper error handling with try-except blocks."219220 # Check 3: Rate limiting implementation221 - pattern: "rate_limit|throttle|limiter"222 message: "Implementing rate limiting for API endpoints."223224 # Check 4: Proper logging225 - pattern: "logger\\.|logging\\."226 message: "Using proper logging mechanisms."227228metadata:229 priority: high230 version: 1.0231 tags:232 - security233 - python234 - design235 - architecture236 - owasp237 - language:python238 - framework:django239 - framework:flask240 - framework:fastapi241 - category:security242 - subcategory:design243 - standard:owasp-top10244 - risk:a04-insecure-design245 references:246 - "https://owasp.org/Top10/A04_2021-Insecure_Design/"247 - "https://cheatsheetseries.owasp.org/cheatsheets/Secure_Product_Design_Cheat_Sheet.html"248 - "https://flask.palletsprojects.com/en/latest/security/"249 - "https://docs.djangoproject.com/en/stable/topics/security/"250 - "https://fastapi.tiangolo.com/advanced/security/"251 - "https://owasp.org/www-project-proactive-controls/"252</rule>
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| ivangrynenko/cursorrules.cursor/rules/cursor-rules.mdc · 86 | Cursor rules | teststylearchgit+2 | 77/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/behat-steps.mdc · 86 | Cursor rules | lint-formatstyleperformanceagent-behaviour | 42/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/php-drupal-development-standards.mdc · 86 | Cursor rules | no sections | 34/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/python-cryptographic-failures.mdc · 86 | Cursor rules | security | 40/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/python-injection.mdc · 86 | Cursor rules | styledo-not | 51/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/node-dependencies.mdc · 86 | Cursor rules | no sections | 16/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/behat-ai-guide.mdc · 86 | Cursor rules | testtesting-strategydo-not | 45/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/new-pull-request.mdc · 86 | Cursor rules | archtesting-strategygitsecurity+3 | 58/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/accessibility-standards.mdc · 86 | Cursor rules | ui | 44/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/api-standards.mdc · 86 | Cursor rules | api | 44/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/build-optimization.mdc · 86 | Cursor rules | build | 48/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/code-generation-standards.mdc · 86 | Cursor rules | lint-formatstyletypesdocs | 52/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/confluence-editing-standards.mdc · 86 | Cursor rules | stylearchsecuritydeployment | 60/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/debugging-standards.mdc · 86 | Cursor rules | no sections | 30/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/docker-compose-standards.mdc · 86 | Cursor rules | style | 62/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-authentication-failures.mdc · 86 | Cursor rules | security | 48/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-broken-access-control.mdc · 86 | Cursor rules | stylesecurity | 52/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-cryptographic-failures.mdc · 86 | Cursor rules | security | 48/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-database-standards.mdc · 86 | Cursor rules | database | 30/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-file-permissions.mdc · 86 | Cursor rules | stylearchsecurity | 62/100 | 14 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 14 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 14 days ago | |
| skillrecordings/egghead-next.cursor/rules/gh-task-plan.mdc · 1.4k | Cursor rules | teststylearchtypes+2 | 96/100 | 14 days ago | |
| skillrecordings/egghead-next.cursor/rules/project-update-rules.mdc · 1.4k | Cursor rules | buildtestlint-formatstyle+7 | 96/100 | 14 days ago | |
| skillrecordings/egghead-next.cursor/rules/project-update-user-rules.mdc · 1.4k | Cursor rules | buildtestlint-formatstyle+7 | 96/100 | 14 days ago | |
| hiromaily/go-crypto-wallet.cursor/rules/proto.mdc · 126 | Cursor rules | buildlint-formatstylearch+3 | 96/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/ivangrynenko-cursorrules-cursor-rules-python-insecure-design)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.