

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
123456# Python Software and Data Integrity Failures Standards (OWASP A08:2021)78This rule enforces security best practices to prevent software and data integrity failures in Python applications, as defined in OWASP Top 10:2021-A08.910<rule>11name: python_integrity_failures12description: Detect and prevent software and data integrity failures in Python applications as defined in OWASP Top 10:2021-A0813filters:14 - type: file_extension15 pattern: "\\.(py|ini|cfg|yml|yaml|json|toml)$"16 - type: file_path17 pattern: ".*"1819actions:20 - type: enforce21 conditions:22 # Pattern 1: Insecure deserialization with pickle23 - pattern: "pickle\\.loads\\(|pickle\\.load\\(|cPickle\\.loads\\(|cPickle\\.load\\("24 message: "Insecure deserialization detected with pickle. Pickle is not secure against maliciously constructed data and should not be used with untrusted input."2526 # Pattern 2: Insecure deserialization with yaml.load27 - pattern: "yaml\\.load\\([^,)]+\\)|yaml\\.load\\([^,)]+,\\s*Loader=yaml\\.Loader\\)"28 message: "Insecure deserialization detected with yaml.load(). Use yaml.safe_load() instead for untrusted input."2930 # Pattern 3: Insecure deserialization with marshal31 - pattern: "marshal\\.loads\\(|marshal\\.load\\("32 message: "Insecure deserialization detected with marshal. Marshal is not secure against maliciously constructed data."3334 # Pattern 4: Insecure deserialization with shelve35 - pattern: "shelve\\.open\\("36 message: "Potentially insecure deserialization with shelve detected. Shelve uses pickle internally and is not secure against malicious data."3738 # Pattern 5: Insecure use of eval or exec39 - pattern: "eval\\(|exec\\(|compile\\([^,]+,\\s*['\"][^'\"]+['\"]\\s*,\\s*['\"]exec['\"]\\)"40 message: "Insecure use of eval() or exec() detected. These functions can execute arbitrary code and should never be used with untrusted input."4142 # Pattern 6: Missing integrity verification for downloads43 - pattern: "urllib\\.request\\.urlretrieve\\(|requests\\.get\\([^)]*\\.exe['\"]\\)|requests\\.get\\([^)]*\\.zip['\"]\\)|requests\\.get\\([^)]*\\.tar\\.gz['\"]\\)"44 message: "File download without integrity verification detected. Always verify the integrity of downloaded files using checksums or digital signatures."4546 # Pattern 7: Insecure package installation47 - pattern: "pip\\s+install\\s+[^-]|subprocess\\.(?:call|run|Popen)\\(['\"]pip\\s+install"48 message: "Insecure package installation detected. Specify package versions and consider using hash verification for pip installations."4950 # Pattern 8: Missing integrity checks for configuration51 - pattern: "config\\.read\\(|json\\.loads?\\(|yaml\\.safe_load\\(|toml\\.loads?\\("52 message: "Configuration loading detected. Ensure integrity verification for configuration files, especially in production environments."5354 # Pattern 9: Insecure temporary file creation55 - pattern: "tempfile\\.mktemp\\(|os\\.tempnam\\(|os\\.tmpnam\\("56 message: "Insecure temporary file creation detected. Use tempfile.mkstemp() or tempfile.TemporaryFile() instead to avoid race conditions."5758 # Pattern 10: Insecure file operations with untrusted paths59 - pattern: "open\\([^,)]+\\+\\s*request\\.|open\\([^,)]+\\+\\s*user_|open\\([^,)]+\\+\\s*input\\("60 message: "Potentially insecure file operation with user-controlled path detected. Validate and sanitize file paths from untrusted sources."6162 # Pattern 11: Missing integrity checks for updates63 - pattern: "auto_update|self_update|check_for_updates"64 message: "Update mechanism detected. Ensure proper integrity verification for software updates using digital signatures or secure checksums."6566 # Pattern 12: Insecure plugin or extension loading67 - pattern: "importlib\\.import_module\\(|__import__\\(|load_plugin|load_extension|load_module"68 message: "Dynamic module loading detected. Implement integrity checks and validation before loading external modules or plugins."6970 # Pattern 13: Insecure use of subprocess with shell=True71 - pattern: "subprocess\\.(?:call|run|Popen)\\([^,)]*shell\\s*=\\s*True"72 message: "Insecure subprocess execution with shell=True detected. This can lead to command injection if user input is involved."7374 # Pattern 14: Missing integrity verification for serialized data75 - pattern: "json\\.loads?\\([^,)]*request\\.|json\\.loads?\\([^,)]*user_|json\\.loads?\\([^,)]*input\\("76 message: "Deserialization of user-controlled data detected. Implement schema validation or integrity checks before processing."7778 # Pattern 15: Insecure use of globals or locals79 - pattern: "globals\\(\\)\\[|locals\\(\\)\\["80 message: "Potentially insecure modification of globals or locals detected. This can lead to unexpected behavior or security issues."8182 - type: suggest83 message: |84 **Python Software and Data Integrity Best Practices:**8586 1. **Secure Deserialization:**87 - Avoid using pickle, marshal, or shelve with untrusted data88 - Use safer alternatives like JSON with schema validation89 - Example with JSON schema validation:90```python91 import json92 import jsonschema9394 # Define a schema for validation95 schema = {96 "type": "object",97 "properties": {98 "name": {"type": "string"},99 "age": {"type": "integer", "minimum": 0}100 },101 "required": ["name", "age"]102 }103104 # Validate data against schema105 try:106 data = json.loads(user_input)107 jsonschema.validate(instance=data, schema=schema)108 # Process data safely109 except (json.JSONDecodeError, jsonschema.exceptions.ValidationError) as e:110 # Handle validation error111 print(f"Invalid data: {e}")112```113114 2. **YAML Safe Loading:**115 - Always use yaml.safe_load() instead of yaml.load()116 - Example:117```python118 import yaml119120 # Safe way to load YAML121 data = yaml.safe_load(yaml_string)122123 # Avoid this:124 # data = yaml.load(yaml_string) # Insecure!125```126127 3. **Integrity Verification for Downloads:**128 - Verify checksums or signatures for downloaded files129 - Example:130```python131 import hashlib132 import requests133134 def download_with_integrity_check(url, expected_hash):135 response = requests.get(url)136 file_data = response.content137138 # Calculate hash139 calculated_hash = hashlib.sha256(file_data).hexdigest()140141 # Verify integrity142 if calculated_hash != expected_hash:143 raise ValueError("Integrity check failed: hash mismatch")144145 return file_data146```147148 4. **Secure Package Installation:**149 - Pin dependencies to specific versions150 - Use hash verification for pip installations151 - Example requirements.txt with hashes:152```153 # requirements.txt154 requests==2.31.0 --hash=sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1155```156157 5. **Secure Configuration Management:**158 - Validate configuration file integrity159 - Use environment-specific configurations160 - Example:161```python162 import json163 import hmac164 import hashlib165166 def load_config_with_integrity(config_file, secret_key):167 with open(config_file, 'r') as f:168 content = f.read()169170 # Split content into data and signature171 data, _, signature = content.rpartition('\n')172173 # Verify integrity174 expected_signature = hmac.new(175 secret_key.encode(),176 data.encode(),177 hashlib.sha256178 ).hexdigest()179180 if not hmac.compare_digest(signature, expected_signature):181 raise ValueError("Configuration integrity check failed")182183 return json.loads(data)184```185186 6. **Secure Temporary Files:**187 - Use secure temporary file functions188 - Example:189```python190 import tempfile191 import os192193 # Secure temporary file creation194 fd, temp_path = tempfile.mkstemp()195 try:196 with os.fdopen(fd, 'w') as temp_file:197 temp_file.write('data')198 # Process the file199 finally:200 os.unlink(temp_path) # Clean up201202 # Or use context manager203 with tempfile.TemporaryFile() as temp_file:204 temp_file.write(b'data')205 temp_file.seek(0)206 # Process the file207```208209 7. **Secure Update Mechanisms:**210 - Verify signatures for updates211 - Use HTTPS for update downloads212 - Example:213```python214 import requests215 import gnupg216217 def secure_update(update_url, signature_url, gpg_key):218 # Download update and signature219 update_data = requests.get(update_url).content220 signature = requests.get(signature_url).content221222 # Verify signature223 gpg = gnupg.GPG()224 gpg.import_keys(gpg_key)225 verified = gpg.verify_data(signature, update_data)226227 if not verified:228 raise ValueError("Update signature verification failed")229230 return update_data231```232233 8. **Secure Plugin Loading:**234 - Validate plugins before loading235 - Implement allowlisting for plugins236 - Example:237```python238 import importlib239 import hashlib240241 # Allowlist of approved plugins with their hashes242 APPROVED_PLUGINS = {243 'safe_plugin': 'sha256:1234567890abcdef',244 'other_plugin': 'sha256:abcdef1234567890'245 }246247 def load_plugin_safely(plugin_name, plugin_path):248 # Check if plugin is in allowlist249 if plugin_name not in APPROVED_PLUGINS:250 raise ValueError(f"Plugin {plugin_name} is not approved")251252 # Calculate plugin file hash253 with open(plugin_path, 'rb') as f:254 plugin_hash = 'sha256:' + hashlib.sha256(f.read()).hexdigest()255256 # Verify hash matches expected value257 if plugin_hash != APPROVED_PLUGINS[plugin_name]:258 raise ValueError(f"Plugin {plugin_name} failed integrity check")259260 # Load plugin safely261 return importlib.import_module(plugin_name)262```263264 9. **Secure Subprocess Execution:**265 - Avoid shell=True266 - Use allowlists for commands267 - Example:268```python269 import subprocess270 import shlex271272 def run_command_safely(command, arguments):273 # Allowlist of safe commands274 SAFE_COMMANDS = {'ls', 'echo', 'cat'}275276 if command not in SAFE_COMMANDS:277 raise ValueError(f"Command {command} is not allowed")278279 # Build command with arguments280 cmd = [command] + arguments281282 # Execute without shell283 return subprocess.run(cmd, shell=False, capture_output=True, text=True)284```285286 10. **Input Validation and Sanitization:**287 - Validate all inputs before processing288 - Use schema validation for structured data289 - Example with Pydantic:290```python291 from pydantic import BaseModel, validator292293 class UserData(BaseModel):294 username: str295 age: int296297 @validator('username')298 def username_must_be_valid(cls, v):299 if not v.isalnum() or len(v) > 30:300 raise ValueError('Username must be alphanumeric and <= 30 chars')301 return v302303 @validator('age')304 def age_must_be_reasonable(cls, v):305 if v < 0 or v > 120:306 raise ValueError('Age must be between 0 and 120')307 return v308309 # Usage310 try:311 user = UserData(username=user_input_name, age=user_input_age)312 # Process validated data313 except ValueError as e:314 # Handle validation error315 print(f"Invalid data: {e}")316```317318 - type: validate319 conditions:320 # Check 1: Safe YAML loading321 - pattern: "yaml\\.safe_load\\("322 message: "Using safe YAML loading."323324 # Check 2: Secure temporary file usage325 - pattern: "tempfile\\.mkstemp\\(|tempfile\\.TemporaryFile\\(|tempfile\\.NamedTemporaryFile\\("326 message: "Using secure temporary file functions."327328 # Check 3: Secure subprocess usage329 - pattern: "subprocess\\.(?:call|run|Popen)\\([^,)]*shell\\s*=\\s*False"330 message: "Using subprocess with shell=False."331332 # Check 4: Input validation333 - pattern: "jsonschema\\.validate|pydantic|dataclass|@validator"334 message: "Implementing input validation."335336metadata:337 priority: high338 version: 1.0339 tags:340 - security341 - python342 - integrity343 - deserialization344 - owasp345 - language:python346 - framework:django347 - framework:flask348 - framework:fastapi349 - category:security350 - subcategory:integrity351 - standard:owasp-top10352 - risk:a08-software-data-integrity-failures353 references:354 - "https://owasp.org/Top10/A08_2021-Software_and_Data_Integrity_Failures/"355 - "https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html"356 - "https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html"357 - "https://docs.python.org/3/library/pickle.html#restricting-globals"358 - "https://pyyaml.org/wiki/PyYAMLDocumentation"359 - "https://python-security.readthedocs.io/packages.html"360 - "https://docs.python.org/3/library/tempfile.html#security"361</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-insecure-design.mdc · 86 | Cursor rules | no sections | 40/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 |
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-integrity-failures)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.
Directory