[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CSP4E0M9R8YSKFG2P7SE0C":3,"skill-same:01M7CSP4E0M9R8YSKFG2P7SE0C":50},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":27,"commitSha":28,"skillDirectory":29,"forksCount":30,"repositoryHtmlUrl":31,"repositoryHomepageUrl":32,"ownerHtmlUrl":33,"ownerBlogUrl":6,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M7CSP4E0M9R8YSKFG2P7SE0C","python-security-pitfalls",null,"Use when reviewing Python changes - Django, Flask and FastAPI handlers, subprocess, SQL, Jinja2, format strings, and data\u002FML code that loads pickles, models, notebooks or remote model code","makifbaysal\u002Ftasktrooper","makifbaysal","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F25031940?v=4","01M7CRG3ZCSYZSSEVDMW3DEYC8","Mehmet Akif Baysal","01M7CRG401FJ8YAXH5ER730XYV",122,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fpython-security-pitfalls\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: python-security-pitfalls\ncategory: security\ndescription: Use when reviewing Python changes - Django, Flask and FastAPI handlers, subprocess, SQL, Jinja2, format strings, and data\u002FML code that loads pickles, models, notebooks or remote model code\ntech_stack: Python & data\nsource: original; informed by trailofbits\u002Fskills (CC BY-SA 4.0, ideas only, own wording); Bandit rule names, Django\u002FFlask\u002FFastAPI, PyTorch and Hugging Face security documentation cited, not reproduced\n---\n# Python Security Pitfalls (services, data and ML)\n\n## Overview\n\nPython's dangerous calls are few and well known — `pickle`, `eval`, `shell=True`, f-string SQL — but data and ML code uses them as everyday tools: models are pickles, configs are YAML, notebooks evaluate whatever they are given. The question is always where the bytes come from.\n\n## 1. Model and Data Loading (CWE-502) — the data\u002FML hot spot\n\nLoading a pickle-based file runs code chosen by whoever wrote the file.\n\n```python\n# ❌ an uploaded or downloaded model file executes code on load\nmodel = torch.load(path, weights_only=False)\nclf = joblib.load(user_upload)\ndf = pd.read_pickle(s3_key_from_request)\narr = np.load(path, allow_pickle=True)\ncfg = yaml.load(text, Loader=yaml.Loader)\n\n# ✅\nmodel.load_state_dict(safetensors.torch.load_file(path))\narr = np.load(path)                    # allow_pickle defaults to False\ncfg = yaml.safe_load(text)\n```\n\n- `torch.load` defaults to `weights_only=True` from PyTorch 2.6; on an older pinned torch the plain call is unsafe.\n- Hugging Face `from_pretrained(..., trust_remote_code=True)` runs Python from the model repository; with a user-chosen repo id it is remote code execution.\n- Keras `load_model(..., safe_mode=False)` allows Lambda-layer code.\n- Celery or Kombu with `accept_content=[\"pickle\"]`, pickled values in a shared Redis or cache, `shelve`, `dill`, `cloudpickle` on data another party writes.\n- Prefer safetensors, ONNX, skops, JSON, Parquet.\n\nA finding when the file can come from outside the trust boundary: an upload, a URL, a user-chosen hub id, a shared bucket other tenants write. A model the team trains and ships in its own artifact store is not attacker input.\n\n## 2. Code Evaluation\n\n- `eval`, `exec`, `compile`, `__import__`\u002F`importlib.import_module` with input.\n- `DataFrame.query(expr)` \u002F `pd.eval(expr)` with a user-built expression — evaluation, not filtering.\n- **Format-string injection:** a user-supplied format string can walk attributes.\n\n```python\n# ❌ template = \"{user.__class__.__init__.__globals__[SECRET_KEY]}\"\nmessage = template.format(user=user)\n# ✅ user text is the value, never the format\nmessage = \"Hello {name}\".format(name=user.name)\n```\n\n## 3. Commands (CWE-78)\n\n```python\n# ❌\nos.system(f\"zip -r {out} {folder}\")\nsubprocess.run(f\"git log {ref}\", shell=True)\n# ✅\nsubprocess.run([\"git\", \"log\", \"--\", ref], check=True)\n```\n\n`shlex.quote` is acceptable when a shell is truly required; `shell=True` with a constant string is fine.\n\n## 4. SQL (CWE-89)\n\n`cursor.execute(f\"… {x}\")`, `cursor.execute(\"… %s\" % x)`, SQLAlchemy `text(f\"…\")`, Django `.raw(f\"…\")`, `.extra(where=[…])`, `RawSQL`. Safe: `cursor.execute(\"… %s\", (x,))`, ORM filters, `text(\"… :x\").bindparams(x=x)`.\n\n## 5. Templates and XSS (CWE-79, CWE-1336)\n\n- Flask `render_template_string(f\"…{user}…\")` → server-side template injection.\n- `jinja2.Environment()` has **autoescape off by default** outside Flask\u002FDjango; rendering HTML with it is XSS unless `autoescape=select_autoescape()`.\n- Django `mark_safe`, `|safe`, `{% autoescape off %}`, `format_html` misused with pre-joined strings.\n\n## 6. Framework Specifics\n\n**Django:** `@csrf_exempt` on a cookie-authenticated view; a production settings change to `DEBUG = True` or `ALLOWED_HOSTS = [\"*\"]` with host-built absolute URLs (reset-link poisoning); `SECRET_KEY` literal in production settings; DRF `permission_classes = [AllowAny]` or a serializer with `fields = \"__all__\"` on a writable endpoint.\n\n**Flask:** `app.run(debug=True)` reachable beyond localhost — the Werkzeug debugger console executes code; `send_file(os.path.join(...))` with `\u003Cpath:…>` routes (path-traversal-and-file-handling).\n\n**FastAPI:** a new `APIRouter` included without the `dependencies=[Depends(current_user)]` its siblings carry; an endpoint returning the ORM object with no `response_model`, leaking every column; a Pydantic request model that includes `role`\u002F`is_admin`.\n\n## 7. Files, XML, Crypto, Transport\n\n- `tarfile.extractall()` without `filter=\"data\"` (default only on Python 3.14+); `os.path.join(base, user)` with absolute input.\n- `lxml` parsing untrusted XML with entity resolution; prefer `defusedxml`.\n- `random` for tokens → `secrets`; `hashlib.md5\u002Fsha256` for passwords → argon2\u002Fbcrypt.\n- `requests.get(..., verify=False)`, `ssl._create_unverified_context()`.\n- `tempfile.mktemp()` (race) → `mkstemp`\u002F`NamedTemporaryFile`.\n- `assert user.is_admin` as an access check — removed under `python -O` (CWE-617).\n\n## 8. Notebooks and Pipelines\n\n- Notebook injection is reported only with a concrete untrusted-input path (a papermill parameter from a request, a cell that evals fetched text).\n- Committed notebook **outputs** that print tokens, connection strings or customer rows are leaked secrets\u002Fdata — check outputs, not only code cells.\n- Orchestrator templates (Airflow `params`\u002F`dag_run.conf` in `bash_command`, dbt Jinja with run-time vars) → injection-and-dangerous-sinks.\n\n## Common Mistakes\n\n- Flagging `pickle.load` on an artifact the pipeline itself produced and stores privately.\n- Flagging `subprocess.run([...])` lists as shell injection.\n- Flagging Flask\u002FDjango templates that autoescape by default.\n- Treating `.ipynb` exploration code as production without an input path.\n\n## Red Flags\n\n- `torch.load(` with `weights_only=False`, `trust_remote_code=True`, `allow_pickle=True`, `yaml.load(` without `SafeLoader`.\n- `shell=True` with an f-string; `os.system(f\"`.\n- `.format(` or `%` on a string that came from a user or a database row.\n- `render_template_string(` with interpolation.\n- A model or dataset path or hub id taken from a request.\n\n## References (names and links only)\n\n[Bandit](https:\u002F\u002Fbandit.readthedocs.io\u002F) · [PyTorch torch.load security note](https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.load.html) · [Hugging Face security](https:\u002F\u002Fhuggingface.co\u002Fdocs\u002Fhub\u002Fsecurity) · [Django security](https:\u002F\u002Fdocs.djangoproject.com\u002Fen\u002Fstable\u002Ftopics\u002Fsecurity\u002F) · CWE-78, 79, 89, 502, 617, 1336 · [OWASP Top 10:2025](https:\u002F\u002Fowasp.org\u002FTop10\u002F2025\u002F) A08\n","# Python Security Pitfalls (services, data and ML)\n\n## Overview\n\nPython's dangerous calls are few and well known — `pickle`, `eval`, `shell=True`, f-string SQL — but data and ML code uses them as everyday tools: models are pickles, configs are YAML, notebooks evaluate whatever they are given. The question is always where the bytes come from.\n\n## 1. Model and Data Loading (CWE-502) — the data\u002FML hot spot\n\nLoading a pickle-based file runs code chosen by whoever wrote the file.\n\n```python\n# ❌ an uploaded or downloaded model file executes code on load\nmodel = torch.load(path, weights_only=False)\nclf = joblib.load(user_upload)\ndf = pd.read_pickle(s3_key_from_request)\narr = np.load(path, allow_pickle=True)\ncfg = yaml.load(text, Loader=yaml.Loader)\n\n# ✅\nmodel.load_state_dict(safetensors.torch.load_file(path))\narr = np.load(path)                    # allow_pickle defaults to False\ncfg = yaml.safe_load(text)\n```\n\n- `torch.load` defaults to `weights_only=True` from PyTorch 2.6; on an older pinned torch the plain call is unsafe.\n- Hugging Face `from_pretrained(..., trust_remote_code=True)` runs Python from the model repository; with a user-chosen repo id it is remote code execution.\n- Keras `load_model(..., safe_mode=False)` allows Lambda-layer code.\n- Celery or Kombu with `accept_content=[\"pickle\"]`, pickled values in a shared Redis or cache, `shelve`, `dill`, `cloudpickle` on data another party writes.\n- Prefer safetensors, ONNX, skops, JSON, Parquet.\n\nA finding when the file can come from outside the trust boundary: an upload, a URL, a user-chosen hub id, a shared bucket other tenants write. A model the team trains and ships in its own artifact store is not attacker input.\n\n## 2. Code Evaluation\n\n- `eval`, `exec`, `compile`, `__import__`\u002F`importlib.import_module` with input.\n- `DataFrame.query(expr)` \u002F `pd.eval(expr)` with a user-built expression — evaluation, not filtering.\n- **Format-string injection:** a user-supplied format string can walk attributes.\n\n```python\n# ❌ template = \"{user.__class__.__init__.__globals__[SECRET_KEY]}\"\nmessage = template.format(user=user)\n# ✅ user text is the value, never the format\nmessage = \"Hello {name}\".format(name=user.name)\n```\n\n## 3. Commands (CWE-78)\n\n```python\n# ❌\nos.system(f\"zip -r {out} {folder}\")\nsubprocess.run(f\"git log {ref}\", shell=True)\n# ✅\nsubprocess.run([\"git\", \"log\", \"--\", ref], check=True)\n```\n\n`shlex.quote` is acceptable when a shell is truly required; `shell=True` with a constant string is fine.\n\n## 4. SQL (CWE-89)\n\n`cursor.execute(f\"… {x}\")`, `cursor.execute(\"… %s\" % x)`, SQLAlchemy `text(f\"…\")`, Django `.raw(f\"…\")`, `.extra(where=[…])`, `RawSQL`. Safe: `cursor.execute(\"… %s\", (x,))`, ORM filters, `text(\"… :x\").bindparams(x=x)`.\n\n## 5. Templates and XSS (CWE-79, CWE-1336)\n\n- Flask `render_template_string(f\"…{user}…\")` → server-side template injection.\n- `jinja2.Environment()` has **autoescape off by default** outside Flask\u002FDjango; rendering HTML with it is XSS unless `autoescape=select_autoescape()`.\n- Django `mark_safe`, `|safe`, `{% autoescape off %}`, `format_html` misused with pre-joined strings.\n\n## 6. Framework Specifics\n\n**Django:** `@csrf_exempt` on a cookie-authenticated view; a production settings change to `DEBUG = True` or `ALLOWED_HOSTS = [\"*\"]` with host-built absolute URLs (reset-link poisoning); `SECRET_KEY` literal in production settings; DRF `permission_classes = [AllowAny]` or a serializer with `fields = \"__all__\"` on a writable endpoint.\n\n**Flask:** `app.run(debug=True)` reachable beyond localhost — the Werkzeug debugger console executes code; `send_file(os.path.join(...))` with `\u003Cpath:…>` routes (path-traversal-and-file-handling).\n\n**FastAPI:** a new `APIRouter` included without the `dependencies=[Depends(current_user)]` its siblings carry; an endpoint returning the ORM object with no `response_model`, leaking every column; a Pydantic request model that includes `role`\u002F`is_admin`.\n\n## 7. Files, XML, Crypto, Transport\n\n- `tarfile.extractall()` without `filter=\"data\"` (default only on Python 3.14+); `os.path.join(base, user)` with absolute input.\n- `lxml` parsing untrusted XML with entity resolution; prefer `defusedxml`.\n- `random` for tokens → `secrets`; `hashlib.md5\u002Fsha256` for passwords → argon2\u002Fbcrypt.\n- `requests.get(..., verify=False)`, `ssl._create_unverified_context()`.\n- `tempfile.mktemp()` (race) → `mkstemp`\u002F`NamedTemporaryFile`.\n- `assert user.is_admin` as an access check — removed under `python -O` (CWE-617).\n\n## 8. Notebooks and Pipelines\n\n- Notebook injection is reported only with a concrete untrusted-input path (a papermill parameter from a request, a cell that evals fetched text).\n- Committed notebook **outputs** that print tokens, connection strings or customer rows are leaked secrets\u002Fdata — check outputs, not only code cells.\n- Orchestrator templates (Airflow `params`\u002F`dag_run.conf` in `bash_command`, dbt Jinja with run-time vars) → injection-and-dangerous-sinks.\n\n## Common Mistakes\n\n- Flagging `pickle.load` on an artifact the pipeline itself produced and stores privately.\n- Flagging `subprocess.run([...])` lists as shell injection.\n- Flagging Flask\u002FDjango templates that autoescape by default.\n- Treating `.ipynb` exploration code as production without an input path.\n\n## Red Flags\n\n- `torch.load(` with `weights_only=False`, `trust_remote_code=True`, `allow_pickle=True`, `yaml.load(` without `SafeLoader`.\n- `shell=True` with an f-string; `os.system(f\"`.\n- `.format(` or `%` on a string that came from a user or a database row.\n- `render_template_string(` with interpolation.\n- A model or dataset path or hub id taken from a request.\n\n## References (names and links only)\n\n[Bandit](https:\u002F\u002Fbandit.readthedocs.io\u002F) · [PyTorch torch.load security note](https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.load.html) · [Hugging Face security](https:\u002F\u002Fhuggingface.co\u002Fdocs\u002Fhub\u002Fsecurity) · [Django security](https:\u002F\u002Fdocs.djangoproject.com\u002Fen\u002Fstable\u002Ftopics\u002Fsecurity\u002F) · CWE-78, 79, 89, 502, 617, 1336 · [OWASP Top 10:2025](https:\u002F\u002Fowasp.org\u002FTop10\u002F2025\u002F) A08\n",{"name":5,"source":24,"category":25,"tech_stack":26,"description":7},"original; informed by trailofbits\u002Fskills (CC BY-SA 4.0, ideas only, own wording); Bandit rule names, Django\u002FFlask\u002FFastAPI, PyTorch and Hugging Face security documentation cited, not reproduced","security","Python & data","main","910394a0b6db9fc8c9a8f36328ec421d3ebd8b38","catalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fpython-security-pitfalls",18,"https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper","https:\u002F\u002Ftasktrooper.ai","https:\u002F\u002Fgithub.com\u002Fmakifbaysal","Senior Software Developer","2026-11-15 04:50:29",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add makifbaysal\u002Ftasktrooper --skill python-security-pitfalls",{"tool":42,"command":43},"bunx","bunx skills add makifbaysal\u002Ftasktrooper --skill python-security-pitfalls",{"tool":45,"command":46},"pnpm","pnpm dlx skills add makifbaysal\u002Ftasktrooper --skill python-security-pitfalls","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fpython-security-pitfalls\u002FSKILL.md",true,[],[51,57,64,71,78,85],{"skillNo":52,"name":53,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":19},"01M7CSVEPQW6J6TD6CS2T5FPNZ","visual-craft","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fvisual-craft\u002FSKILL.md",[],[],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M7CSVAQG91ETHQ0HBNZDG5FR","ux-copy","Use when you write any words a user reads in a mockup or a hand-off - content language and voice, buttons, labels, errors, empty states, confirmations, numbers and dates, and the longest-string check","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fux-copy\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M7CSV6H0J38659NDXHJQ8396","screen-mockup-html","Use when you draw screens as the design task's HTML mockup - ONE canvas document holding every screen and every variant side by side, the sanitizer-safe recipe, phone and wide frames, the states grid, static control states, and the loopback self-check with screenshots at 375, 768 and 1440 attached to the task","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fscreen-mockup-html\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M7CSV3JFRF3BM3XK52M7YEYR","performance-awareness","How the performance score moves for your role. Use when the score context shows a declining trend, or before handing off work you have not self-checked against every criterion.","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fperformance-awareness\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":19},"01M7CSTZDH00YRF5SCT7BRT9QD","design-variants","Use when a screen design needs variants - how many, variants as side-by-side rows on the one canvas, what makes two variants genuinely different, recommending one, how the human's choice is read, and narrowing to the chosen one in revision","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-variants\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":19},"01M7CSTV6P3SM3PAE28DB0RF77","design-system-authoring","Use when you derive, change or extend a design system - where tokens live per stack, the DTCG token tree, role-based names for both themes, base vs layer vs drift, the DESIGN.md section order, the inventory format, the contrast check and the lint every proposal returns","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-system-authoring\u002FSKILL.md",[],[]]