跳到主内容
智客 ZICQ

技能库 智客分类:安全测试 secure-coding-practices

Secure Coding Practices

安全编码做法和防御性编程模式用于构建安全第一应用程序. 在执行认证,处理用户输入,管理敏感数据,或进行安全代码审查时使用.

100 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

建立安全第一应用程序的安全编码做法和防御性编程模式

何时用

这个技能

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Secure Coding Practices、When to Use This Skill、Core Security Principles、Defense in Depth、Fail Securely、Least Privilege。 其中含规范建议的小节:分步指令。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/input-validation.md、references/output-encoding.md、references/authentication.md、references/cryptography.md、references/dependencies.md、references/error-handling.md,属于带资源的技能包,这些文件按需再读。

官方 description(原文)

Secure coding practices and defensive programming patterns for building security-first applications. Use when implementing authentication, handling user input, managing sensitive data, or conducting secure code reviews.

Secure Coding PracticesWhen to Use This SkillCore Security PrinciplesDefense in DepthFail SecurelyLeast PrivilegeTrust NothingQuick ReferenceWorkflowSecurity ChecklistCommon MistakesHigh-Risk Code Patterns

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
secure-coding-practices
description
Secure coding practices and defensive programming patterns for building security-first applications. Use when implementing authentication, handling user input, managing sensitive data, or conducting secure code reviews.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 7
  • references/input-validation.md
  • references/output-encoding.md
  • references/authentication.md
  • references/cryptography.md
  • references/dependencies.md
  • references/error-handling.md
  • references/secure-defaults.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「secure-coding-practices」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-2b2147a48376ef15-%E5%AE%89%E5%85%A8%E7%BC%96%E7%A0%81%E5%81%9A%E6%B3%95.html
请存为 .cursor/skills/secure-coding-practices/SKILL.md 或 .claude/skills/secure-coding-practices/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/nickcrew/claude-cortex 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/nickcrew/claude-cortex' --list

npx skills add 'https://github.com/nickcrew/claude-cortex' --skill 'secure-coding-practices'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版

name: secure-coding-practices description: Secure coding practices and defensive programming patterns for building security-first applications. Use when implementing authentication, handling user input, managing sensitive data, or conducting secure code reviews. keywords:

  • code security
  • defense in depth
  • input validation
  • least privilege
  • output encoding
  • sanitization
  • secure by design
  • secure coding
  • security hardening
  • threat modeling file_patterns:
  • '**/secret.py'
  • '**/secret.ts'
  • '/auth/'
  • '/security/' confidence: 0.87

Secure Coding Practices

Comprehensive guidance for implementing security-first development patterns with defensive programming techniques and proactive threat mitigation strategies.

When to Use This Skill

  • Implementing authentication and authorization systems
  • Processing user input or external data
  • Handling sensitive data (PII, credentials, financial information)
  • Building APIs and web services
  • Managing cryptographic operations (hashing, encryption)
  • Conducting security-focused code reviews
  • Establishing secure development standards for teams
  • Evaluating third-party dependencies and libraries
  • Designing error handling and logging strategies
  • Implementing session management and token handling

Core Security Principles

Defense in Depth

Apply multiple layers of security controls - never rely on a single protection mechanism.

Fail Securely

When errors occur, default to the secure state (deny access, reject input, log event).

Least Privilege

Grant minimum necessary permissions - users, services, and databases should have only required access.

Trust Nothing

Validate all input, encode all output, verify all sources, authenticate all requests.

Quick Reference

| Task | Load reference | | --- | --- | | Input validation & sanitization | skills/secure-coding-practices/references/input-validation.md | | Output encoding & XSS prevention | skills/secure-coding-practices/references/output-encoding.md | | Authentication & sessions | skills/secure-coding-practices/references/authentication.md | | Cryptography & key management | skills/secure-coding-practices/references/cryptography.md | | Dependencies & supply chain | skills/secure-coding-practices/references/dependencies.md | | Error handling & logging | skills/secure-coding-practices/references/error-handling.md | | Secure defaults & configuration | skills/secure-coding-practices/references/secure-defaults.md |

Workflow

  1. Identify security requirements - Authentication, authorization, data protection, compliance
  2. Load relevant references - Use Quick Reference table to find specific guidance
  3. Implement security controls - Apply patterns from references with proper context
  4. Validate implementation - Test with security scanners, penetration testing, code review
  5. Monitor and maintain - Regular security audits, dependency updates, vulnerability scanning

Security Checklist

Input Validation:

  • [ ] Validate all user input server-side with allowlists
  • [ ] Use schema validation libraries (Joi, Yup, Zod)
  • [ ] Implement strict type checking
  • [ ] Sanitize file paths and prevent traversal

Output Encoding:

  • [ ] Apply context-aware encoding (HTML, JS, URL, SQL)
  • [ ] Use templating engines with auto-escaping
  • [ ] Implement Content Security Policy (CSP)
  • [ ] Set secure HTTP headers (Helmet.js)

Authentication & Authorization:

  • [ ] Hash passwords with bcrypt/Argon2 (salt rounds ≥12)
  • [ ] Implement secure session management
  • [ ] Use HTTPS-only cookies with HttpOnly and SameSite
  • [ ] Apply rate limiting on authentication endpoints
  • [ ] Verify authorization on every request

Cryptography:

  • [ ] Use AES-256-GCM for encryption
  • [ ] Generate keys with crypto.randomBytes()
  • [ ] Store secrets in environment variables or KMS
  • [ ] Never roll your own crypto

Dependencies:

  • [ ] Run npm audit regularly
  • [ ] Lock dependency versions in package.json
  • [ ] Use Snyk/Dependabot for monitoring
  • [ ] Verify package integrity (SRI for CDN)

Error Handling & Logging:

  • [ ] Return generic error messages to users
  • [ ] Log errors with correlation IDs
  • [ ] Never log passwords, tokens, or PII
  • [ ] Monitor security events and alerts

Common Mistakes

  • Using client-side validation as sole defense (always validate server-side)
  • Blocklisting instead of allowlisting (define what's allowed, not forbidden)
  • Exposing stack traces or internal errors to users
  • Hardcoding secrets in source code
  • Using Math.random() for security-critical operations
  • Not implementing rate limiting on authentication endpoints
  • Loose equality comparisons allowing type coercion attacks
  • Trusting user input in database queries (SQL injection)
  • Missing output encoding based on context (XSS vulnerabilities)
  • Insufficient password hashing (weak algorithms or low work factor)

High-Risk Code Patterns

Watch for these patterns in code reviews:

  1. String concatenation in SQL queries (injection risk)
  2. Direct file path construction from user input (traversal risk)
  3. eval(), Function(), or exec() with user input (code injection)
  4. Deserialization of untrusted data (RCE risk)
  5. Hardcoded secrets or credentials (exposure risk)
  6. Missing authentication/authorization checks (access control)
  7. Weak cryptography (MD5, SHA1, ECB mode)
  8. Verbose error messages in production (information disclosure)
  9. Missing input validation (injection, DoS)
  10. Insecure session configuration (hijacking risk)

Resources

OWASP Resources:

  • OWASP Top 10: https://owasp.org/Top10/
  • OWASP Cheat Sheet Series: https://cheatsheetseries.owasp.org/
  • OWASP ASVS: Application Security Verification Standard
  • OWASP Dependency-Check: https://owasp.org/www-project-dependency-check/

Standards & Guidelines:

  • NIST Cybersecurity Framework: https://www.nist.gov/cyberframework
  • NIST SP 800-63B: Digital Identity Guidelines (Authentication)
  • CWE Top 25: https://cwe.mitre.org/top25/

Tools:

  • SAST: SonarQube, Semgrep, CodeQL
  • DAST: OWASP ZAP, Burp Suite
  • SCA: Snyk, npm audit, Dependabot
  • Secrets Detection: TruffleHog, git-secrets

相关技能

安全测试

Skill Vetter

人工智能特工的安全第一技能审查。 在安装来自 ClawdHub, GitHub 或其他来源的任何技能之前使用 。 检查红旗,许可范围,可疑图案.

安全测试

Moltguard

MoltGuard——由OpenGuardrails担任OpenClaw保安. 安装 MoltGuard 以保护你和你的人类免受迅速注射、数据过滤和恶意命令的影响。 资料来源:https://github.com/openguardrails/openguardrails/tre…

安全测试

Security Auditor

用于审查安全漏洞代码,实施认证流,审计OWASP Top 10,配置CORS/CSP头,处理秘密,输入验证,SQL注射预防,XSS保护,或任何与安全相关的代码审查.

安全测试

Skill Vetter

安装任何AI代理技能前的安全审查协议. 红旗侦取入证盗取,疏通密码,放出. 风险分类:低/中/高/高。 编制结构化审查报告。 不先运行此功能, 绝不安装不信任的技能 .