Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add skills/wade-devcode/awesome-coding-skills-cn/secrets-handlingnpx skills add Wade-DevCode/awesome-coding-skills-cn --skill secrets-handlinggit clone --depth 1 https://github.com/Wade-DevCode/awesome-coding-skills-cnWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/secrets-handling)<a href="https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/secrets-handling"><img src="https://agentmods.dev/badge/skills/wade-devcode/awesome-coding-skills-cn/secrets-handling.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00027 | $0.02558 |
| Opus 5 | $0.00014 | $0.01279 |
| Sonnet 5 | $0.00005 | $0.00512 |
| Haiku 4.5 | $0.00003 | $0.00256 |
Grade A, and why
secrets-handling scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 213 lines — stays where its author put it; the contents beside it link to each section on GitHub.
密钥处理
何时用
- 代码中需要使用 API key、数据库密码、JWT secret、OAuth 凭据等任何形式的密钥。
- 部署配置、CI/CD pipeline 涉及凭据传递时。
- 接到密钥泄露告警,需要评估影响并响应时。
- 代码审查发现任何疑似硬编码凭据时。
核心规则
1. 密钥不进代码库:用环境变量或 secret manager
规则: 任何密钥、token、密码都不允许出现在代码文件、配置文件、注释里;通过环境变量或专用 secret 管理工具(AWS Secrets Manager、HashiCorp Vault、GCP Secret Manager)在运行时注入;.env 文件本地使用但必须加入 .gitignore。
为什么: AI 生成示例代码时最常见的陷阱就是把真实密钥硬编码进代码并提交。GitHub 的安全研究表明,每天有数万个 API key 被意外推送到公开仓库,其中大量来自"我只是先写死方便测试,待会改"的侥幸心态,但改了代码、历史记录里的密钥仍然存在。GitGuardian 报告显示 AI 生成的代码中密钥硬编码比例显著高于人类开发者。
怎么做:
# 反例:硬编码
OPENAI_API_KEY = "sk-proj-abc123xyz..." # ❌ 直接写死在代码里
# 正例:从环境变量读取
import os
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"] # ✅ 启动时不存在则报错
# .gitignore
.env
.env.local
.env.production
*.pem
*_rsa
*_rsa.pub
credentials.json
- 提供
.env.example(只含变量名,无值)作为文档,不提供含真实值的.env。
2. 已泄露的密钥立即轮换,不只是删除提交
规则: 发现密钥被提交进 git 后,第一步是立即在对应服务撤销/轮换该密钥,而不是先删除提交或 rebase;历史记录里的密钥通过 git filter-repo 清除只是事后补救,不能替代密钥轮换。
为什么: AI 有时建议"删掉那次提交然后 force push 就好了",这是错误的响应姿势。在发现密钥泄露到 force push 完成之间的时间窗口内,密钥仍然有效;更重要的是,GitHub 等平台会镜像 push 事件,第三方爬虫可能在秒级内就已经抓取并存档了该密钥。2022 年 Samsung 源码泄露事件中,即便代码被删除,密钥早已被利用。
怎么做:
密钥泄露响应流程:
1. [立即] 在服务控制台撤销/轮换该密钥(AWS IAM、GitHub Settings、Stripe Dashboard 等)
2. [立即] 审计该密钥从泄露到轮换期间的访问日志,确认是否被滥用
3. [之后] 用 git filter-repo 清理历史(需要团队所有人重新 clone)
4. [之后] 复盘:补充 pre-commit 扫描防止再次发生
- 不要因为仓库是私有的就认为安全——内部人员、协作工具的 webhook、泄露的 deploy key 都可能导致私有仓库内容外泄。
3. 日志、报错、前端不输出密钥
规则: 日志输出、异常信息、HTTP 响应、前端 JavaScript(包括注释和 source map)都不能包含密钥或完整 token;脱敏展示时只显示前4后4位,中间用 **** 替代。
为什么: AI 生成的调试日志和错误处理代码里频繁出现 logger.error(f"API调用失败,key={api_key}, error={e}"),这行日志把完整 API key 写进日志文件。日志文件通常被运维、开发、监控系统等多人访问,远比代码库传播面广。前端 bundle 里的密钥更危险,任何访问网页的用户打开开发者工具即可获取。
怎么做:
def mask_secret(secret: str) -> str:
"""只保留前4后4位,其余脱敏"""
if not secret or len(secret) <= 8:
return "****"
return f"{secret[:4]}****{secret[-4:]}"
# 反例
logger.error(f"调用失败: key={api_key}") # ❌ 完整 key 进日志
# 正例
logger.error(f"调用失败: key={mask_secret(api_key)}, error={type(e).__name__}") # ✅
- 前端只能持有"无权限到后台直接用的"公开配置,如 Google Maps 的
clientId(受域名限制),不能有任何后端密钥。 - Node.js 项目禁止把
.env内容打包进 webpack bundle(检查DefinePlugin的使用)。
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 4d ago First seen · 213 lines · 27 tokens per session scan A 12aca6f479bb
secrets-handling is a skill published in the GitHub repository Wade-DevCode/awesome-coding-skills-cn (6 stars, last pushed 2mo ago), licensed MIT. It adds 27 tokens to every session and 2,558 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other skills, from other repositories
chinese-documentation
中文文档排版参考——中英文空格、全半角标点、术语保留、链接格式、中文文案排版指北约定。仅在用户显式 /chinese-documentation 时调用,不要根据上下文自动触发。.
chinese-git-workflow
国内 Git 平台配置参考——Gitee、Coding.net、极狐 GitLab、CNB 的 SSH/HTTPS/凭据/CI 接入差异与镜像同步配置。仅在用户显式 /chinese-git-workflow 时调用,不要根据上下文自动触发。.
brainstorming
在任何创造性工作之前必须使用此技能——创建功能、构建组件、添加功能或修改行为。在实现之前先探索用户意图、需求和设计。.
chinese-code-review
中文 review 沟通参考——话术模板、分级标注(必须修复/建议修改/仅供参考)、国内团队常见反模式应对。仅在用户显式 /chinese-code-review 时调用,不要根据上下文自动触发。.
chinese-commit-conventions
中文 commit 与 changelog 配置参考——Conventional Commits 中文适配、commitlint/husky/commitizen 中文模板、conventional-changelog 中文配置。仅在用户显式 /chinese-commit-conventions 时调用,不要根据上下文自动触发。.
mcp-builder
MCP 服务器构建方法论 — 系统化构建生产级 MCP 工具,让 AI 助手连接外部能力.