Skip to main content
skill CX Codex

secure-coding-practices — Claude Code skill for secure code

secure-coding-practices is a Claude Code skill for applying defensive coding patterns to authentication, user input, and sensitive data. It also supports security-focused code reviews.

MIT 134 installs ★ 71 updated 2026-06-29

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add NickCrew/Claude-Cortex --skill secure-coding-practices -a claude-code
Open on GitHub

What secure-coding-practices does

The skill guides the agent through input checks, output encoding, and access control. Its reference files cover authentication, cryptography, dependencies, error handling, and safer configuration.

During code reviews, it flags patterns such as SQL built through string concatenation, paths derived from user input, hardcoded secrets, and weak cryptography. It also describes least-privilege access and secure handling of errors. The skill is associated with files whose names contain secret and with files under auth or security directories.

What it helps with

  • review user-input handling
  • spot unsafe SQL construction
  • assess authentication and session settings
  • find secrets embedded in source code

Example prompts for the agent

  • Review this code for security risks and list the unsafe patterns.
  • Help me validate user input in this API.
  • Check the authentication and session handling in this project.

How to install secure-coding-practices

1Skills CLI (Vercel)

npx skills add NickCrew/Claude-Cortex --skill secure-coding-practices -a claude-code

2Manually: put the files in place

~/.claude/skills/secure-coding-practices/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/secure-coding-practices/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about secure-coding-practices

How do I install secure-coding-practices in Claude Code?

Run npx skills add NickCrew/Claude-Cortex --skill secure-coding-practices -a claude-code. The skill file is at ~/.claude/skills/secure-coding-practices/SKILL.md.

What does secure-coding-practices do?

It gives the agent guidance for defensive coding and security-focused reviews, including input handling, authentication, and sensitive data.

When does secure-coding-practices activate?

It is intended for authentication work, user or external input, sensitive data, and security reviews. Its file patterns include names containing secret and the auth and security directories.

Source text

SKILL.md · MIT
---
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

© NickCrew · MIT · NickCrew/Claude-Cortex

Similar skills

All skills for Security →

From the same set21

The whole set →
helm-chart-patterns helm-chart-patterns is a Claude Code skill for developing Kubernetes Helm charts, covering template structure, values.schema.json validation, lifecycle hooks, and multi-environment setups. CX Codex +1 179installs typescript-advanced-patterns The typescript-advanced-patterns skill helps apply advanced TypeScript types to APIs and domain models. Use it when compile-time rules need to express states, constraints, or distinct identifiers. CX Codex +1 174installs code-explanation The code-explanation skill explains code, architecture, and system behavior at a depth that matches the reader. Use it for walkthroughs, teaching, and knowledge transfer. CX Codex +1 173installs security-testing-patterns security-testing-patterns guides security testing workflows across SAST, SCA, DAST, and OWASP API audits. Use it to build CI/CD scanning pipelines and triage vulnerabilities. CX Codex +1 154installs ux-review ux-review reviews a component or flow from three angles: usability heuristics, WCAG 2.1 AA accessibility and interaction design. Comes back with a prioritized report. CX Codex +1 119installs event-driven-architecture The event-driven-architecture skill guides event-driven system design with event sourcing, CQRS, sagas, and message brokers. Use it for microservices and distributed transactions. CX Codex +1 118installs dashboard-designer The dashboard-designer Claude Code skill plans dashboard KPIs, layout, and visual hierarchy. It activates for requests about monitoring dashboards or choosing a BI tool. CX Codex +1 109installs terraform-best-practices terraform-best-practices adds enterprise Terraform guidelines covering module layout, secure remote state, workspace isolation, and CI/CD security scanning. CX Codex +1 109installs

Project sponsors

Companies that keep this analytics open