烟雾报警器
- 作者仓库星标 0
- 作者仓库 skills-registry
- 领域
- 安全
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @tomevault-io · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部接口密钥
- 需要 · Vendor-specific
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- Python
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 读取环境变量
- 网络行为
- 允许外网请求
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
如果工作存储库包含工作树或生成/供应商文件夹,则切勿判断其原始扫描仪计数。至少排除:如果使用`djangoSecurityHunter`,则更喜欢干净的临时副本和仅扫描环境值:如果扫描仪无法导入设置,请保留静态结果,但明确说明跳过了哪些设置支持的检查。
按风险面对结果进行分组:生产设置 — `DEBUG`、`SECRET_KEY`、`ALLOWED_HOSTS`、HTTPS 重定向、HSTS、安全 cookie、CSRF 可信来源、CORS。 DRF/API 滥用 — 默认身份验证、权限、限制、分页、类似身份验证的路由、上传限制。不安全的 HTML — `mark_safe`、`|safe`、XML/Markdown 渲染器、管理预览、模板标签、富文本块。持久性竞争 - `exists/get + create`、多重保存工作流程、循环中的`save()`、没有`F()`的算术更新、缺少唯一性/幂等性。
对于每个噪声规则,在做出决定之前检查代表性代码。
报告紧凑表:查找·分类·证据·推荐举措缺少HSTS·REAL·`settings.py`在`DEBUG=False`下没有`SECURE_HSTS_SECONDS`·添加生产安全块或环境控制设置管理员`mark_safe`预览·HYGIENE·URL被转义,否则恒定HTML·转换为`format_html`AI管道多次保存· FALSE POSITIVE/HYGIENE · 在长时间外部调用之前/之后保存状态 · 不要包装整个函数;也许添加评论/测试
如果同样的问题可能再次出现,请添加项目本地护栏:`settings.py`生产安全块并进行测试。 auth/OAuth/API-key 端点的 DRF 节流默认值和每路由节流。 HTML 渲染器助手,默认转义文本并仅将已知标签标记为安全。代码审查注释:“没有带有插值的`mark_safe`;使用`format_html`。”
# Django Smoke Alarm
Use this when a Django or DRF project needs a fast security/reliability sweep, especially after a tool such as `djangoSecurityHunter`, Bandit, Semgrep, or a custom grep pass reports many findings.
Third-order stance: the goal is not “make the scanner green.” The goal is to find the few boring Django foot-guns that become production incidents, while teaching the project a repeatable preflight. Smoke alarms should be loud, cheap, and easy to silence only with evidence.
## When to Use
- The project is Django/DRF and you need obvious security or reliability issues.
- A scanner reports many findings and you need a grounded triage.
- Before launch, deploy, CI hardening, or exposing new auth/API/upload/HTML surfaces.
- When adding or reviewing settings, DRF auth, OAuth/API keys, XML/Markdown/HTML rendering, import jobs, or admin previews.
## Core Rule
Always classify scanner output before fixing:
- **REAL** — plausible exploit/data-loss/abuse path or broken production posture.
- **HYGIENE** — low-risk but worth making safer/clearer, often to reduce future mistakes.
- **FALSE POSITIVE** — scanner pattern is misleading; document why with code evidence.
Do not create a giant undifferentiated fix list. The dragon is usually three lizards in a trench coat.
---
<process>
## Phase 1: Prepare a Clean Scan
Never judge raw scanner counts from a working repo if it contains worktrees or generated/vendor folders.
Exclude at minimum:
```text
.git .hg .svn .venv venv node_modules dist build .tox .eggs
.mypy_cache .pytest_cache htmlcov coverage
.worktrees .claude/worktrees
.env .env.*
```
If using `djangoSecurityHunter`, prefer a clean temp copy and scan-only env values:
```bash
python3 skills/django-smoke-alarm/scripts/django_smoke_alarm.py \
--project . \
--settings myproject.settings \
--project-python .venv/bin/python \
--scanner-source /tmp/djangoSecurityHunter/src \
--env SECRET_KEY=dummy-scan-only-not-production-40-plus-chars \
--env DEBUG=False \
--env ALLOWED_HOSTS=localhost,127.0.0.1 \
--env DATABASE_URL=sqlite:////tmp/django-smoke.sqlite3
```
If the scanner cannot import settings, keep static findings but explicitly say which settings-backed checks were skipped.
## Phase 2: Read the Rule Buckets, Not Just Counts
Group findings by risk surface:
1. **Production settings** — `DEBUG`, `SECRET_KEY`, `ALLOWED_HOSTS`, HTTPS redirect, HSTS, secure cookies, CSRF trusted origins, CORS.
2. **DRF/API abuse** — default authentication, permissions, throttles, pagination, auth-like routes, upload limits.
3. **Unsafe HTML** — `mark_safe`, `|safe`, XML/Markdown renderers, admin previews, template tags, rich text blocks.
4. **Persistence races** — `exists/get + create`, multi-save workflows, `save()` in loops, arithmetic updates without `F()`, missing uniqueness/idempotency.
5. **Model integrity** — natural-key slugs, nullable unique-ish fields, risky cascade deletes, missing constraints.
6. **Secrets/logging** — token-looking defaults, exception logs near OAuth/API keys, local `.env*` accidentally tracked.
7. **Dependencies and external scanners** — pip-audit, Bandit, Semgrep, only after the clean project scan is understood.
## Phase 3: Sample Before Fixing
For each noisy rule, inspect representative code before deciding.
### Unsafe HTML triage
Classify as **REAL** if untrusted or external content is inserted into safe HTML without escaping:
- XML or Markdown source from outside the team
- user profile/team/org/bill/client fields
- uploaded file metadata
- admin preview fields backed by user content
Classify as **HYGIENE** if the string is constant or all interpolated variables are escaped, but the code would be safer with `format_html()` / `format_html_join()`.
Classify as **FALSE POSITIVE** only when the full data path is safe and future edits are unlikely to reintroduce unsafe interpolation.
### Transaction/race triage
Do not blindly wrap long-running workflows in `transaction.atomic()`. Multi-save progress markers around external API calls, Celery jobs, or imports may be intentional.
Prefer:
- DB uniqueness constraints for idempotency.
- `get_or_create()` / `update_or_create()` where appropriate.
- `select_for_update()` for concurrent mutation of existing rows.
- `F()` expressions for arithmetic updates.
- Small atomic sections around related DB writes, not around network calls or long LLM/image work.
## Phase 4: Produce a Triage Table
Report a compact table:
| Finding | Classification | Evidence | Recommended move |
|---|---|---|---|
| Missing HSTS | REAL | `settings.py` has no `SECURE_HSTS_SECONDS` under `DEBUG=False` | Add production security block or env-controlled settings |
| Admin `mark_safe` preview | HYGIENE | URL is escaped, constant HTML otherwise | Convert to `format_html` |
| AI pipeline multiple saves | FALSE POSITIVE/HYGIENE | Saves status before/after long external calls | Do not wrap whole function; maybe add comment/tests |
Then list only the **top 3-7 REAL fixes**. Put hygiene work behind those.
## Phase 5: Turn Findings into Project Policy
If the same issue could recur, add a project-local guardrail:
- `settings.py` production security block and test.
- DRF throttle defaults and per-route throttles for auth/OAuth/API-key endpoints.
- HTML renderer helper that escapes text by default and marks only known tags safe.
- Code-review note: “no `mark_safe` with interpolation; use `format_html`.”
- Import/idempotency tests with duplicate input and repeated runs.
- CI smoke-alarm job that runs on a clean copy and stores JSON/SARIF artifacts.
</process>
<tooling>
`scripts/django_smoke_alarm.py` creates a clean temp copy, runs `djangoSecurityHunter` if available, writes JSON, and prints a grouped summary. It is intentionally a wrapper, not the source of truth: the agent still must read code and classify findings.
Useful flags:
- `--project` — Django repo root.
- `--settings` — Django settings module.
- `--project-python` — project venv Python, recommended for settings import.
- `--scanner-source` — local `djangoSecurityHunter/src` checkout to add to `PYTHONPATH`.
- `--env KEY=VALUE` — scan-only env overrides.
- `--output-dir` — report destination.
</tooling>
<interlocks>
- Use `trust-audit` for user-facing permission, privacy, billing, and unsafe-feeling AI/data flows found during the scan.
- Use `kindness-check` after fixes to catch developer/support burden from noisy scanner-driven changes.
- Use `release-operator` if this creates a CI/release gate.
- Use `decision-log` if choosing to accept a scanner false positive or defer a real risk.
</interlocks>
---
> Source: [carlkibler/agent-skills](https://github.com/carlkibler/agent-skills) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->
按说明文件中的顺序排列。
何时使用
核心规则
第 1 阶段:准备干净扫描
第 2 阶段:阅读规则桶,而不仅仅是计数
第 3 阶段:固定前取样
文件/命令 -> djangoSecurityHunter · DEBUG · SECRET_KEY · ALLOWED_HOSTS · mark_safe · |safe · exists/get + create · save()
内容校验值 -> 7ae7c88cd60c
当前原文的自动摘译,尚未人工审校。
何时使用
该项目是 Django/DRF,您需要明显的安全性或可靠性问题。扫描仪会报告许多发现,您需要进行接地分类。在启动、部署、CI 强化或公开新的身份验证/API/上传/HTML 界面之前。添加或查看设置、DRF 身份验证、OAuth/API 密钥、XML/Markdown/HTML 渲染、导入作业或管理预览时。
核心规则
在修复之前始终对扫描仪输出进行分类:真实 - 合理的利用/数据丢失/滥用路径或损坏的生产状态。卫生——风险低,但值得变得更安全/更清晰,通常是为了减少未来的错误。假阳性 — 扫描仪模式具有误导性;用代码证据记录原因。不要创建一个巨大的、无差别的修复列表。龙通常是三只穿着风衣的蜥蜴。
第 2 阶段:阅读规则桶,而不仅仅是计数
按风险面对结果进行分组:生产设置 —
DEBUG、SECRET_KEY、ALLOWED_HOSTS、HTTPS 重定向、HSTS、安全 cookie、CSRF 可信来源、CORS。 DRF/API 滥用 — 默认身份验证、权限、限制、分页、类似身份验证的路由、上传限制。不安全的 HTML —mark_safe、|safe、XML/Markdown 渲染器、管理预览、模板标签、富文本块。持久性竞争 —exists/get + create、多重保存工作流程、循环中的save()、没有F()的算术更新、缺少唯一性/幂等性。