code-hardcode-audit by terrylica/cc-skills
npx skills add https://github.com/terrylica/cc-skills --skill code-hardcode-audit当用户提及以下内容时使用此技能:
# 预检 — 验证所有工具已安装并配置
uv run --python 3.13 --script scripts/preflight.py -- .
# 完整审计(所有 9 个工具,预检 + 两种输出格式)
uv run --python 3.13 --script scripts/audit_hardcodes.py -- src/
# 单独运行工具(所有工具均遵循 .gitignore):
# Python 凭证检测(变量名中的密码、令牌、API 密钥)
uv run --python 3.13 --script scripts/run_bandit.py -- src/
# 基于熵的秘密检测(捕获正则表达式无法检测的秘密)
uv run --python 3.13 --script scripts/run_trufflehog.py -- src/
# 配置文件秘密检测(YAML、JSON、Dockerfile、.env、.properties)
uv run --python 3.13 --script scripts/run_whispers.py -- src/
# 基于 AST 的硬编码检测(数字参数、URL、路径、sleep)
uv run --python 3.13 --script scripts/run_ast_grep.py -- src/
# 仅检测 Python 魔法数字(最快)
uv run --python 3.13 --script scripts/run_ruff_plr.py -- src/
# 基于模式的检测(URL、端口、路径、sleep、断路器)
uv run --python 3.13 --script scripts/run_semgrep.py -- src/
# 环境变量覆盖审计(BaseSettings 交叉引用)
uv run --python 3.13 --script scripts/audit_env_coverage.py -- src/
# 复制粘贴检测
uv run --python 3.13 --script scripts/run_jscpd.py -- src/
# 基于正则表达式的秘密扫描(API 密钥、令牌、密码)
uv run --python 3.13 --script scripts/run_gitleaks.py -- src/
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 工具 | 检测重点 | 语言支持 | 速度 |
|---|---|---|---|
| Preflight | 工具可用性 + 配置验证 | 不适用 | 即时 |
| Bandit | Python 中的硬编码密码、令牌(B105-7) | Python | 快 |
| TruffleHog | 基于熵的秘密检测 + API 验证 | 任意(基于文件) | 中等 |
| Whispers | 配置文件中的秘密(YAML、JSON、Docker、.env) | 配置文件 | 中等 |
| ast-grep | 参数、sleep、URL、路径中的硬编码字面量 | 多语言 | 快 |
| Ruff PLR2004 | 魔法值比较 | Python | 快 |
| Semgrep | URL、端口、路径、凭证、重试配置 | 多语言 | 中等 |
| Env-coverage | BaseSettings 交叉引用,覆盖缺口 | Python | 快 |
| jscpd | 重复代码块 | 多语言 | 慢 |
| gitleaks | 基于正则表达式的秘密、API 密钥、密码 | 任意(基于文件) | 快 |
{
"summary": {
"total_findings": 42,
"by_tool": { "ruff": 15, "semgrep": 20, "jscpd": 7 },
"by_severity": { "high": 5, "medium": 25, "low": 12 }
},
"findings": [
{
"id": "MAGIC-001",
"tool": "ruff",
"rule": "PLR2004",
"file": "src/config.py",
"line": 42,
"column": 8,
"message": "Magic value used in comparison: 8123",
"severity": "medium",
"suggested_fix": "Extract to named constant"
}
],
"refactoring_plan": [
{
"priority": 1,
"action": "Create constants/ports.py",
"finding_ids": ["MAGIC-001", "MAGIC-003"]
}
]
}
src/config.py:42:8: PLR2004 Magic value used in comparison: 8123 [ruff]
src/probe.py:15:1: hardcoded-url Hardcoded URL detected [semgrep]
src/client.py:20-35: Clone detected (16 lines, 95% similarity) [jscpd]
Summary: 42 findings (ruff: 15, semgrep: 20, jscpd: 7)
--output {json,text,both} 输出格式(默认:both)
--tools {all,ast-grep,ruff,semgrep,jscpd,gitleaks,env-coverage,bandit,trufflehog,whispers} 要运行的工具
--severity {all,high,medium,low} 按严重性过滤(默认:all)
--exclude PATTERN 要排除的 Glob 模式(可重复)
--no-parallel 禁用并行执行
--skip-preflight 跳过工具可用性检查
code-clone-assistant - 基于 PMD CPD 的克隆检测(专注于 DRY 原则)| 问题 | 原因 | 解决方案 |
|---|---|---|
| Ruff PLR2004 无输出 | PLR2004 被全局抑制 | 运行预检:uv run --python 3.13 --script scripts/preflight.py -- . |
| Ruff PLR2004 未找到 | Ruff 未安装或版本过旧 | uv tool install ruff 或升级 |
| ast-grep 未找到 | 二进制文件未安装 | cargo install ast-grep 或 brew install ast-grep |
| Semgrep 超时 | 大型代码库扫描 | 使用 --exclude 限制范围 |
| jscpd 内存错误 | 文件过多 | 增加 Node 堆内存:NODE_OPTIONS=--max-old-space-size=4096 |
| gitleaks 误报 | 测试数据被标记 | 将模式添加到 .gitleaks.toml 允许列表 |
| Env-coverage 遗漏 | 未使用 BaseSettings | 仅检测 pydantic BaseSettings;其他配置模式被跳过 |
| 输出中无发现 | 指定了错误的目录 | 验证路径存在且包含源文件 |
| JSON 解析错误 | 工具输出格式错误 | 使用 --output text 单独运行工具 |
| PATH 中缺少工具 | 工具未全局安装 | 先运行预检,然后安装缺失的工具 |
| Bandit 误报 | 初始化中的 password = '' | 按置信度过滤 B105:--confidence HIGH |
| TruffleHog 超时 | 扫描 .venv/node_modules | 所有工具均遵循 .gitignore;确保大型目录已被 gitignore |
| TruffleHog 正则表达式错误 | .gitignore 中的 Glob 模式 | 复杂的 glob 模式(**/*.rs.bk)会自动跳过;仅使用简单名称 |
| Whispers 扫描慢 | 目录过大 | 通过 .gitignore 排除;whispers 配置会自动从中生成 |
| Whispers 无发现 | 范围内无配置文件 | Whispers 针对 YAML/JSON/Docker/INI;在项目根目录使用,而非 src/ |
| 严重性过滤器为空 | 该级别无发现 | 使用 --severity all 查看所有发现 |
每周安装次数
76
仓库
GitHub 星标数
24
首次出现时间
2026 年 1 月 24 日
安全审计
安装于
opencode71
codex67
gemini-cli66
cursor66
claude-code64
github-copilot63
Use this skill when the user mentions:
# Preflight — verify all tools installed and configured
uv run --python 3.13 --script scripts/preflight.py -- .
# Full audit (all 9 tools, preflight + both outputs)
uv run --python 3.13 --script scripts/audit_hardcodes.py -- src/
# Individual tools (all respect .gitignore):
# Python credential detection (passwords, tokens, API keys in variable names)
uv run --python 3.13 --script scripts/run_bandit.py -- src/
# Entropy-based secret detection (catches secrets regex can't)
uv run --python 3.13 --script scripts/run_trufflehog.py -- src/
# Config file secrets (YAML, JSON, Dockerfile, .env, .properties)
uv run --python 3.13 --script scripts/run_whispers.py -- src/
# AST-based hardcode detection (numeric args, URLs, paths, sleep)
uv run --python 3.13 --script scripts/run_ast_grep.py -- src/
# Python magic numbers only (fastest)
uv run --python 3.13 --script scripts/run_ruff_plr.py -- src/
# Pattern-based detection (URLs, ports, paths, sleep, circuit breaker)
uv run --python 3.13 --script scripts/run_semgrep.py -- src/
# Env-var coverage audit (BaseSettings cross-reference)
uv run --python 3.13 --script scripts/audit_env_coverage.py -- src/
# Copy-paste detection
uv run --python 3.13 --script scripts/run_jscpd.py -- src/
# Regex-based secret scanning (API keys, tokens, passwords)
uv run --python 3.13 --script scripts/run_gitleaks.py -- src/
| Tool | Detection Focus | Language Support | Speed |
|---|---|---|---|
| Preflight | Tool availability + config validation | N/A | Instant |
| Bandit | Hardcoded passwords, tokens in Python (B105-7) | Python | Fast |
| TruffleHog | Entropy-based secret + API verification | Any (file-based) | Medium |
| Whispers | Config file secrets (YAML, JSON, Docker, .env) | Config files | Medium |
| ast-grep | Hardcoded literals in args, sleep, URLs, paths | Multi-language | Fast |
| Ruff PLR2004 | Magic value comparisons | Python |
{
"summary": {
"total_findings": 42,
"by_tool": { "ruff": 15, "semgrep": 20, "jscpd": 7 },
"by_severity": { "high": 5, "medium": 25, "low": 12 }
},
"findings": [
{
"id": "MAGIC-001",
"tool": "ruff",
"rule": "PLR2004",
"file": "src/config.py",
"line": 42,
"column": 8,
"message": "Magic value used in comparison: 8123",
"severity": "medium",
"suggested_fix": "Extract to named constant"
}
],
"refactoring_plan": [
{
"priority": 1,
"action": "Create constants/ports.py",
"finding_ids": ["MAGIC-001", "MAGIC-003"]
}
]
}
src/config.py:42:8: PLR2004 Magic value used in comparison: 8123 [ruff]
src/probe.py:15:1: hardcoded-url Hardcoded URL detected [semgrep]
src/client.py:20-35: Clone detected (16 lines, 95% similarity) [jscpd]
Summary: 42 findings (ruff: 15, semgrep: 20, jscpd: 7)
--output {json,text,both} Output format (default: both)
--tools {all,ast-grep,ruff,semgrep,jscpd,gitleaks,env-coverage,bandit,trufflehog,whispers} Tools to run
--severity {all,high,medium,low} Filter by severity (default: all)
--exclude PATTERN Glob pattern to exclude (repeatable)
--no-parallel Disable parallel execution
--skip-preflight Skip tool availability check
code-clone-assistant - PMD CPD-based clone detection (DRY focus)| Issue | Cause | Solution |
|---|---|---|
| Ruff PLR2004 zero output | PLR2004 globally suppressed | Run preflight: uv run --python 3.13 --script scripts/preflight.py -- . |
| Ruff PLR2004 not found | Ruff not installed or old | uv tool install ruff or upgrade |
| ast-grep not found | Binary not installed | cargo install ast-grep or brew install ast-grep |
| Semgrep timeout | Large codebase scan | Use --exclude to limit scope |
Weekly Installs
76
Repository
GitHub Stars
24
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode71
codex67
gemini-cli66
cursor66
claude-code64
github-copilot63
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
46,600 周安装
| Fast |
| Semgrep | URLs, ports, paths, credentials, retry config | Multi-language | Medium |
| Env-coverage | BaseSettings cross-reference, coverage gaps | Python | Fast |
| jscpd | Duplicate code blocks | Multi-language | Slow |
| gitleaks | Regex-based secrets, API keys, passwords | Any (file-based) | Fast |
| jscpd memory error | Too many files | Increase Node heap: NODE_OPTIONS=--max-old-space-size=4096 |
| gitleaks false positives | Test data flagged | Add patterns to .gitleaks.toml allowlist |
| Env-coverage misses | Not using BaseSettings | Only detects pydantic BaseSettings; other config patterns skipped |
| No findings in output | Wrong directory specified | Verify path exists and contains source files |
| JSON parse error | Tool output malformed | Run tool individually with --output text |
| Missing tool in PATH | Tool not installed globally | Run preflight first, then install missing tools |
| Bandit false positives | password = '' in init | Filter B105 by confidence: --confidence HIGH |
| TruffleHog timeout | Scanning .venv/node_modules | All tools respect .gitignore; ensure large dirs are gitignored |
| TruffleHog regex error | Glob patterns in .gitignore | Complex globs (**/*.rs.bk) are auto-skipped; only simple names used |
| Whispers slow scan | Large directories | Exclude via .gitignore; whispers config auto-generated from it |
| Whispers zero findings | No config files in scope | Whispers targets YAML/JSON/Docker/INI; use on project root, not src/ |
| Severity filter empty | No findings at that level | Use --severity all to see all findings |