commit 71de01dd9fe874b3aa365251d33112aedc351a57 Author: Agam More Date: Thu Jan 29 21:11:01 2026 -0600 Add OWASP Security Skill for Claude Code - OWASP Top 10:2025 quick reference and mitigations - OWASP ASVS 5.0.0 key requirements - OWASP Top 10 for Agentic Applications 2026 - Security code review checklists - Language-specific security quirks for 20+ languages - Comprehensive research report Co-Authored-By: Claude Opus 4.5 diff --git a/.claude/skills/owasp-security/SKILL.md b/.claude/skills/owasp-security/SKILL.md new file mode 100644 index 0000000..24a922d --- /dev/null +++ b/.claude/skills/owasp-security/SKILL.md @@ -0,0 +1,535 @@ +--- +name: owasp-security +description: Use when reviewing code for security vulnerabilities, implementing authentication/authorization, handling user input, or discussing web application security. Covers OWASP Top 10:2025, ASVS 5.0, and Agentic AI security (2026). +--- + +# OWASP Security Best Practices Skill + +Apply these security standards when writing or reviewing code. + +## Quick Reference: OWASP Top 10:2025 + +| # | Vulnerability | Key Prevention | +|---|---------------|----------------| +| A01 | Broken Access Control | Deny by default, enforce server-side, verify ownership | +| A02 | Security Misconfiguration | Harden configs, disable defaults, minimize features | +| A03 | Supply Chain Failures | Lock versions, verify integrity, audit dependencies | +| A04 | Cryptographic Failures | TLS 1.2+, AES-256-GCM, Argon2/bcrypt for passwords | +| A05 | Injection | Parameterized queries, input validation, safe APIs | +| A06 | Insecure Design | Threat model, rate limit, design security controls | +| A07 | Auth Failures | MFA, check breached passwords, secure sessions | +| A08 | Integrity Failures | Sign packages, SRI for CDN, safe serialization | +| A09 | Logging Failures | Log security events, structured format, alerting | +| A10 | Exception Handling | Fail-closed, hide internals, log with context | + +## Security Code Review Checklist + +When reviewing code, check for these issues: + +### Input Handling +- [ ] All user input validated server-side +- [ ] Using parameterized queries (not string concatenation) +- [ ] Input length limits enforced +- [ ] Allowlist validation preferred over denylist + +### Authentication & Sessions +- [ ] Passwords hashed with Argon2/bcrypt (not MD5/SHA1) +- [ ] Session tokens have sufficient entropy (128+ bits) +- [ ] Sessions invalidated on logout +- [ ] MFA available for sensitive operations + +### Access Control +- [ ] Authorization checked on every request +- [ ] Using object references user cannot manipulate +- [ ] Deny by default policy +- [ ] Privilege escalation paths reviewed + +### Data Protection +- [ ] Sensitive data encrypted at rest +- [ ] TLS for all data in transit +- [ ] No sensitive data in URLs/logs +- [ ] Secrets in environment/vault (not code) + +### Error Handling +- [ ] No stack traces exposed to users +- [ ] Fail-closed on errors (deny, not allow) +- [ ] All exceptions logged with context +- [ ] Consistent error responses (no enumeration) + +## Secure Code Patterns + +### SQL Injection Prevention +```python +# UNSAFE +cursor.execute(f"SELECT * FROM users WHERE id = {user_id}") + +# SAFE +cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,)) +``` + +### Command Injection Prevention +```python +# UNSAFE +os.system(f"convert {filename} output.png") + +# SAFE +subprocess.run(["convert", filename, "output.png"], shell=False) +``` + +### Password Storage +```python +# UNSAFE +hashlib.md5(password.encode()).hexdigest() + +# SAFE +from argon2 import PasswordHasher +PasswordHasher().hash(password) +``` + +### Access Control +```python +# UNSAFE - No authorization check +@app.route('/api/user/') +def get_user(user_id): + return db.get_user(user_id) + +# SAFE - Authorization enforced +@app.route('/api/user/') +@login_required +def get_user(user_id): + if current_user.id != user_id and not current_user.is_admin: + abort(403) + return db.get_user(user_id) +``` + +### Error Handling +```python +# UNSAFE - Exposes internals +@app.errorhandler(Exception) +def handle_error(e): + return str(e), 500 + +# SAFE - Fail-closed, log context +@app.errorhandler(Exception) +def handle_error(e): + error_id = uuid.uuid4() + logger.exception(f"Error {error_id}: {e}") + return {"error": "An error occurred", "id": str(error_id)}, 500 +``` + +### Fail-Closed Pattern +```python +# UNSAFE - Fail-open +def check_permission(user, resource): + try: + return auth_service.check(user, resource) + except Exception: + return True # DANGEROUS! + +# SAFE - Fail-closed +def check_permission(user, resource): + try: + return auth_service.check(user, resource) + except Exception as e: + logger.error(f"Auth check failed: {e}") + return False # Deny on error +``` + +## Agentic AI Security (OWASP 2026) + +When building or reviewing AI agent systems, check for: + +| Risk | Description | Mitigation | +|------|-------------|------------| +| ASI01: Goal Hijack | Prompt injection alters agent objectives | Input sanitization, goal boundaries, behavioral monitoring | +| ASI02: Tool Misuse | Tools used in unintended ways | Least privilege, fine-grained permissions, validate I/O | +| ASI03: Privilege Abuse | Credential escalation across agents | Short-lived scoped tokens, identity verification | +| ASI04: Supply Chain | Compromised plugins/MCP servers | Verify signatures, sandbox, allowlist plugins | +| ASI05: Code Execution | Unsafe code generation/execution | Sandbox execution, static analysis, human approval | +| ASI06: Memory Poisoning | Corrupted RAG/context data | Validate stored content, segment by trust level | +| ASI07: Agent Comms | Spoofing between agents | Authenticate, encrypt, verify message integrity | +| ASI08: Cascading Failures | Errors propagate across systems | Circuit breakers, graceful degradation, isolation | +| ASI09: Trust Exploitation | Social engineering via AI | Label AI content, user education, verification steps | +| ASI10: Rogue Agents | Compromised agents acting maliciously | Behavior monitoring, kill switches, anomaly detection | + +### Agent Security Checklist + +- [ ] All agent inputs sanitized and validated +- [ ] Tools operate with minimum required permissions +- [ ] Credentials are short-lived and scoped +- [ ] Third-party plugins verified and sandboxed +- [ ] Code execution happens in isolated environments +- [ ] Agent communications authenticated and encrypted +- [ ] Circuit breakers between agent components +- [ ] Human approval for sensitive operations +- [ ] Behavior monitoring for anomaly detection +- [ ] Kill switch available for agent systems + +## ASVS 5.0 Key Requirements + +### Level 1 (All Applications) +- Passwords minimum 12 characters +- Check against breached password lists +- Rate limiting on authentication +- Session tokens 128+ bits entropy +- HTTPS everywhere + +### Level 2 (Sensitive Data) +- All L1 requirements plus: +- MFA for sensitive operations +- Cryptographic key management +- Comprehensive security logging +- Input validation on all parameters + +### Level 3 (Critical Systems) +- All L1/L2 requirements plus: +- Hardware security modules for keys +- Threat modeling documentation +- Advanced monitoring and alerting +- Penetration testing validation + +## Language-Specific Security Quirks + +> **Important:** The examples below are illustrative starting points, not exhaustive. When reviewing code, think like a senior security researcher: consider the language's memory model, type system, standard library pitfalls, ecosystem-specific attack vectors, and historical CVE patterns. Each language has deeper quirks beyond what's listed here. + +Different languages have unique security pitfalls. Here are the top 20 languages with key security considerations. **Go deeper for the specific language you're working in:** + +--- + +### JavaScript / TypeScript +**Main Risks:** Prototype pollution, XSS, eval injection +```javascript +// UNSAFE: Prototype pollution +Object.assign(target, userInput) +// SAFE: Use null prototype or validate keys +Object.assign(Object.create(null), validated) + +// UNSAFE: eval injection +eval(userCode) +// SAFE: Never use eval with user input +``` +**Watch for:** `eval()`, `innerHTML`, `document.write()`, prototype chain manipulation, `__proto__` + +--- + +### Python +**Main Risks:** Pickle deserialization, format string injection, shell injection +```python +# UNSAFE: Pickle RCE +pickle.loads(user_data) +# SAFE: Use JSON or validate source +json.loads(user_data) + +# UNSAFE: Format string injection +query = "SELECT * FROM users WHERE name = '%s'" % user_input +# SAFE: Parameterized +cursor.execute("SELECT * FROM users WHERE name = %s", (user_input,)) +``` +**Watch for:** `pickle`, `eval()`, `exec()`, `os.system()`, `subprocess` with `shell=True` + +--- + +### Java +**Main Risks:** Deserialization RCE, XXE, JNDI injection +```java +// UNSAFE: Arbitrary deserialization +ObjectInputStream ois = new ObjectInputStream(userStream); +Object obj = ois.readObject(); + +// SAFE: Use allowlist or JSON +ObjectMapper mapper = new ObjectMapper(); +mapper.readValue(json, SafeClass.class); +``` +**Watch for:** `ObjectInputStream`, `Runtime.exec()`, XML parsers without XXE protection, JNDI lookups + +--- + +### C# +**Main Risks:** Deserialization, SQL injection, path traversal +```csharp +// UNSAFE: BinaryFormatter RCE +BinaryFormatter bf = new BinaryFormatter(); +object obj = bf.Deserialize(stream); + +// SAFE: Use System.Text.Json +var obj = JsonSerializer.Deserialize(json); +``` +**Watch for:** `BinaryFormatter`, `JavaScriptSerializer`, `TypeNameHandling.All`, raw SQL strings + +--- + +### PHP +**Main Risks:** Type juggling, file inclusion, object injection +```php +// UNSAFE: Type juggling in auth +if ($password == $stored_hash) { ... } +// SAFE: Use strict comparison +if (hash_equals($stored_hash, $password)) { ... } + +// UNSAFE: File inclusion +include($_GET['page'] . '.php'); +// SAFE: Allowlist pages +$allowed = ['home', 'about']; include(in_array($page, $allowed) ? "$page.php" : 'home.php'); +``` +**Watch for:** `==` vs `===`, `include/require`, `unserialize()`, `preg_replace` with `/e`, `extract()` + +--- + +### Go +**Main Risks:** Race conditions, template injection, slice bounds +```go +// UNSAFE: Race condition +go func() { counter++ }() +// SAFE: Use sync primitives +atomic.AddInt64(&counter, 1) + +// UNSAFE: Template injection +template.HTML(userInput) +// SAFE: Let template escape +{{.UserInput}} +``` +**Watch for:** Goroutine data races, `template.HTML()`, `unsafe` package, unchecked slice access + +--- + +### Ruby +**Main Risks:** Mass assignment, YAML deserialization, regex DoS +```ruby +# UNSAFE: Mass assignment +User.new(params[:user]) +# SAFE: Strong parameters +User.new(params.require(:user).permit(:name, :email)) + +# UNSAFE: YAML RCE +YAML.load(user_input) +# SAFE: Use safe_load +YAML.safe_load(user_input) +``` +**Watch for:** `YAML.load`, `Marshal.load`, `eval`, `send` with user input, `.permit!` + +--- + +### Rust +**Main Risks:** Unsafe blocks, FFI boundary issues, integer overflow in release +```rust +// CAUTION: Unsafe bypasses safety +unsafe { ptr::read(user_ptr) } + +// CAUTION: Release integer overflow +let x: u8 = 255; +let y = x + 1; // Wraps to 0 in release! +// SAFE: Use checked arithmetic +let y = x.checked_add(1).unwrap_or(255); +``` +**Watch for:** `unsafe` blocks, FFI calls, integer overflow in release builds, `.unwrap()` on untrusted input + +--- + +### Swift +**Main Risks:** Force unwrapping crashes, Objective-C interop +```swift +// UNSAFE: Force unwrap on untrusted data +let value = jsonDict["key"]! +// SAFE: Safe unwrapping +guard let value = jsonDict["key"] else { return } + +// UNSAFE: Format string +String(format: userInput, args) +// SAFE: Don't use user input as format +``` +**Watch for:** `!` force unwrap, `try!`, ObjC bridging, `NSSecureCoding` misuse + +--- + +### Kotlin +**Main Risks:** Null safety bypass, Java interop, serialization +```kotlin +// UNSAFE: Platform type from Java +val len = javaString.length // NPE if null +// SAFE: Explicit null check +val len = javaString?.length ?: 0 + +// UNSAFE: Reflection +clazz.getDeclaredMethod(userInput) +// SAFE: Allowlist methods +``` +**Watch for:** Java interop nulls (`!`), reflection, serialization, platform types + +--- + +### C / C++ +**Main Risks:** Buffer overflow, use-after-free, format string +```c +// UNSAFE: Buffer overflow +char buf[10]; strcpy(buf, userInput); +// SAFE: Bounds checking +strncpy(buf, userInput, sizeof(buf) - 1); + +// UNSAFE: Format string +printf(userInput); +// SAFE: Always use format specifier +printf("%s", userInput); +``` +**Watch for:** `strcpy`, `sprintf`, `gets`, pointer arithmetic, manual memory management, integer overflow + +--- + +### Scala +**Main Risks:** XML external entities, serialization, pattern matching exhaustiveness +```scala +// UNSAFE: XXE +val xml = XML.loadString(userInput) +// SAFE: Disable external entities +val factory = SAXParserFactory.newInstance() +factory.setFeature("http://xml.org/sax/features/external-general-entities", false) +``` +**Watch for:** Java interop issues, XML parsing, `Serializable`, exhaustive pattern matching + +--- + +### R +**Main Risks:** Code injection, file path manipulation +```r +# UNSAFE: eval injection +eval(parse(text = user_input)) +# SAFE: Never parse user input as code + +# UNSAFE: Path traversal +read.csv(paste0("data/", user_file)) +# SAFE: Validate filename +if (grepl("^[a-zA-Z0-9]+\\.csv$", user_file)) read.csv(...) +``` +**Watch for:** `eval()`, `parse()`, `source()`, `system()`, file path manipulation + +--- + +### Perl +**Main Risks:** Regex injection, open() injection, taint mode bypass +```perl +# UNSAFE: Regex DoS +$input =~ /$user_pattern/; +# SAFE: Use quotemeta +$input =~ /\Q$user_pattern\E/; + +# UNSAFE: open() command injection +open(FILE, $user_file); +# SAFE: Three-argument open +open(my $fh, '<', $user_file); +``` +**Watch for:** Two-arg `open()`, regex from user input, backticks, `eval`, disabled taint mode + +--- + +### Shell (Bash) +**Main Risks:** Command injection, word splitting, globbing +```bash +# UNSAFE: Unquoted variables +rm $user_file +# SAFE: Always quote +rm "$user_file" + +# UNSAFE: eval +eval "$user_command" +# SAFE: Never eval user input +``` +**Watch for:** Unquoted variables, `eval`, backticks, `$(...)` with user input, missing `set -euo pipefail` + +--- + +### Lua +**Main Risks:** Sandbox escape, loadstring injection +```lua +-- UNSAFE: Code injection +loadstring(user_code)() +-- SAFE: Use sandboxed environment with restricted functions +``` +**Watch for:** `loadstring`, `loadfile`, `dofile`, `os.execute`, `io` library, debug library + +--- + +### Elixir +**Main Risks:** Atom exhaustion, code injection, ETS access +```elixir +# UNSAFE: Atom exhaustion DoS +String.to_atom(user_input) +# SAFE: Use existing atoms only +String.to_existing_atom(user_input) + +# UNSAFE: Code injection +Code.eval_string(user_input) +# SAFE: Never eval user input +``` +**Watch for:** `String.to_atom`, `Code.eval_string`, `:erlang.binary_to_term`, ETS public tables + +--- + +### Dart / Flutter +**Main Risks:** Platform channel injection, insecure storage +```dart +// UNSAFE: Storing secrets in SharedPreferences +prefs.setString('auth_token', token); +// SAFE: Use flutter_secure_storage +secureStorage.write(key: 'auth_token', value: token); +``` +**Watch for:** Platform channel data, `dart:mirrors`, `Function.apply`, insecure local storage + +--- + +### PowerShell +**Main Risks:** Command injection, execution policy bypass +```powershell +# UNSAFE: Injection +Invoke-Expression $userInput +# SAFE: Avoid Invoke-Expression with user data + +# UNSAFE: Unvalidated path +Get-Content $userPath +# SAFE: Validate path is within allowed directory +``` +**Watch for:** `Invoke-Expression`, `& $userVar`, `Start-Process` with user args, `-ExecutionPolicy Bypass` + +--- + +### SQL (All Dialects) +**Main Risks:** Injection, privilege escalation, data exfiltration +```sql +-- UNSAFE: String concatenation +"SELECT * FROM users WHERE id = " + userId + +-- SAFE: Parameterized query (language-specific) +-- Use prepared statements in ALL cases +``` +**Watch for:** Dynamic SQL, `EXECUTE IMMEDIATE`, stored procedures with dynamic queries, privilege grants + +--- + +## Deep Security Analysis Mindset + +When reviewing any language, think like a senior security researcher: + +1. **Memory Model:** How does the language handle memory? Managed vs manual? GC pauses exploitable? +2. **Type System:** Weak typing = type confusion attacks. Look for coercion exploits. +3. **Serialization:** Every language has its pickle/Marshal equivalent. All are dangerous. +4. **Concurrency:** Race conditions, TOCTOU, atomicity failures specific to the threading model. +5. **FFI Boundaries:** Native interop is where type safety breaks down. +6. **Standard Library:** Historic CVEs in std libs (Python urllib, Java XML, Ruby OpenSSL). +7. **Package Ecosystem:** Typosquatting, dependency confusion, malicious packages. +8. **Build System:** Makefile/gradle/npm script injection during builds. +9. **Runtime Behavior:** Debug vs release differences (Rust overflow, C++ assertions). +10. **Error Handling:** How does the language fail? Silently? With stack traces? Fail-open? + +**For any language not listed:** Research its specific CWE patterns, CVE history, and known footguns. The examples above are entry points, not complete coverage. + +## When to Apply This Skill + +Use this skill when: +- Writing authentication or authorization code +- Handling user input or external data +- Implementing cryptography or password storage +- Reviewing code for security vulnerabilities +- Designing API endpoints +- Building AI agent systems +- Configuring application security settings +- Handling errors and exceptions +- Working with third-party dependencies +- **Working in any language** - apply the deep analysis mindset above diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..14fac91 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/OWASP-2025-2026-Report.md b/OWASP-2025-2026-Report.md new file mode 100644 index 0000000..ad61592 --- /dev/null +++ b/OWASP-2025-2026-Report.md @@ -0,0 +1,792 @@ +# OWASP Security Best Practices 2025-2026 + +A comprehensive guide to the latest OWASP security standards for developers building secure applications. + +--- + +## Table of Contents + +1. [OWASP Top 10:2025](#owasp-top-102025) +2. [OWASP ASVS 5.0.0](#owasp-asvs-500) +3. [OWASP Top 10 for Agentic Applications 2026](#owasp-top-10-for-agentic-applications-2026) +4. [Key Security Principles](#key-security-principles) +5. [Sources and References](#sources-and-references) + +--- + +## OWASP Top 10:2025 + +Released at OWASP Global AppSec EU Barcelona 2025, based on analysis of 175,000+ CVEs and 2.8 million applications tested. + +### Summary Table + +| Rank | Category | Change from 2021 | +|------|----------|------------------| +| A01 | Broken Access Control | Unchanged #1 | +| A02 | Security Misconfiguration | Up from #5 | +| A03 | Software Supply Chain Failures | **NEW** (expanded from A06:2021) | +| A04 | Cryptographic Failures | Down from #2 | +| A05 | Injection | Down from #3 | +| A06 | Insecure Design | Down from #4 | +| A07 | Identification and Authentication Failures | Unchanged #7 | +| A08 | Software and Data Integrity Failures | Unchanged #8 | +| A09 | Security Logging and Monitoring Failures | Unchanged #9 | +| A10 | Mishandling of Exceptional Conditions | **NEW** | + +--- + +### A01:2025 – Broken Access Control + +**Description:** Access control enforces policies that prevent users from acting outside their intended permissions. Failures lead to unauthorized data disclosure, modification, or destruction. + +**Common Vulnerabilities:** +- Bypassing access control by modifying URLs, application state, or HTML pages +- Allowing primary key changes to access others' records (IDOR) +- Privilege escalation (acting as admin while logged in as user) +- Missing access control for POST, PUT, DELETE APIs +- CORS misconfiguration allowing unauthorized API access + +**Prevention:** +```python +# BAD: No authorization check +@app.route('/api/user/') +def get_user(user_id): + return db.get_user(user_id) + +# GOOD: Authorization enforced +@app.route('/api/user/') +@login_required +def get_user(user_id): + if current_user.id != user_id and not current_user.is_admin: + abort(403) + return db.get_user(user_id) +``` + +**Mitigation Strategies:** +1. Deny access by default (allowlist approach) +2. Implement access control once, reuse throughout application +3. Enforce record ownership instead of accepting user-supplied IDs +4. Disable directory listing and remove sensitive files from web roots +5. Log access control failures and alert on repeated attempts +6. Rate limit API access to minimize automated attack damage + +--- + +### A02:2025 – Security Misconfiguration + +**Description:** Applications are vulnerable when security hardening is missing, cloud permissions are improperly configured, unnecessary features are enabled, or default accounts remain active. + +**Common Vulnerabilities:** +- Missing security hardening across the application stack +- Unnecessary features enabled (ports, services, pages, accounts) +- Default credentials unchanged +- Error handling revealing stack traces +- Outdated or vulnerable software components +- Insecure cloud storage permissions (S3 buckets public) + +**Prevention:** +```yaml +# BAD: Debug mode in production +DEBUG=True +SECRET_KEY="development-key" + +# GOOD: Production hardened +DEBUG=False +SECRET_KEY="${RANDOM_SECRET_FROM_VAULT}" +ALLOWED_HOSTS=["app.example.com"] +SECURE_SSL_REDIRECT=True +SESSION_COOKIE_SECURE=True +CSRF_COOKIE_SECURE=True +``` + +**Mitigation Strategies:** +1. Automated, repeatable hardening process across environments +2. Minimal platform without unnecessary features or frameworks +3. Regularly review and update configurations (cloud permissions, patches) +4. Segmented application architecture with secure separation +5. Send security directives (CSP, HSTS, X-Frame-Options) +6. Automated verification of configurations in all environments + +--- + +### A03:2025 – Software Supply Chain Failures + +**Description:** NEW category highlighting risks from third-party dependencies, compromised build pipelines, and insecure package management. Expanded from 2021's component vulnerabilities focus. + +**Common Vulnerabilities:** +- Using components with known vulnerabilities +- Dependency confusion attacks +- Typosquatting in package registries +- Compromised CI/CD pipelines +- Unsigned or unverified packages +- Lack of software bill of materials (SBOM) + +**Prevention:** +```bash +# BAD: Installing without verification +npm install some-package + +# GOOD: Lock versions, verify integrity, audit +npm install some-package@1.2.3 --save-exact +npm audit +npm audit signatures +``` + +```json +// package-lock.json with integrity hashes +{ + "dependencies": { + "lodash": { + "version": "4.17.21", + "integrity": "sha512-v2kDEe57lecT..." + } + } +} +``` + +**Mitigation Strategies:** +1. Maintain inventory of all components (SBOM) +2. Remove unused dependencies and features +3. Continuously monitor for vulnerabilities (Dependabot, Snyk) +4. Obtain components from official sources over secure links +5. Sign packages and verify signatures +6. Ensure CI/CD pipelines have proper access controls and audit logs +7. Use lock files and verify integrity hashes + +--- + +### A04:2025 – Cryptographic Failures + +**Description:** Failures related to cryptography that lead to exposure of sensitive data. Includes weak algorithms, improper key management, and missing encryption. + +**Common Vulnerabilities:** +- Transmitting data in clear text (HTTP, SMTP, FTP) +- Using deprecated algorithms (MD5, SHA1, DES) +- Weak or default cryptographic keys +- Missing certificate validation +- Using encryption without authenticated modes +- Insufficient entropy for random number generation + +**Prevention:** +```python +# BAD: Weak hashing +import hashlib +password_hash = hashlib.md5(password.encode()).hexdigest() + +# GOOD: Modern password hashing +from argon2 import PasswordHasher +ph = PasswordHasher() +password_hash = ph.hash(password) + +# BAD: ECB mode +from Crypto.Cipher import AES +cipher = AES.new(key, AES.MODE_ECB) + +# GOOD: Authenticated encryption +from cryptography.fernet import Fernet +cipher = Fernet(key) +``` + +**Mitigation Strategies:** +1. Classify data by sensitivity; apply controls accordingly +2. Don't store sensitive data unnecessarily +3. Encrypt all data in transit (TLS 1.2+) and at rest +4. Use strong, current algorithms (AES-256-GCM, Argon2, bcrypt) +5. Encrypt with authenticated modes (GCM, CCM) +6. Generate keys randomly; store securely (HSM, vault) +7. Disable caching for sensitive responses + +--- + +### A05:2025 – Injection + +**Description:** Injection occurs when untrusted data is sent to an interpreter as part of a command or query. Includes SQL, NoSQL, OS, LDAP, and expression language injection. + +**Common Vulnerabilities:** +- User input not validated, filtered, or sanitized +- Dynamic queries without parameterization +- Hostile data used in ORM search parameters +- Direct concatenation of user input in commands + +**Prevention:** +```python +# BAD: SQL Injection vulnerable +query = f"SELECT * FROM users WHERE id = {user_id}" +cursor.execute(query) + +# GOOD: Parameterized query +cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,)) + +# BAD: Command injection +os.system(f"convert {filename} output.png") + +# GOOD: Use safe APIs, avoid shell +subprocess.run(["convert", filename, "output.png"], shell=False) +``` + +```javascript +// BAD: NoSQL injection +db.users.find({ username: req.body.username }) + +// GOOD: Validate type +if (typeof req.body.username !== 'string') throw new Error(); +db.users.find({ username: req.body.username }) +``` + +**Mitigation Strategies:** +1. Use safe APIs with parameterized interfaces +2. Validate all input using allowlists +3. Escape special characters for specific interpreters +4. Use LIMIT and pagination to prevent mass disclosure +5. Implement positive server-side input validation + +--- + +### A06:2025 – Insecure Design + +**Description:** Flaws in design and architecture that cannot be fixed by perfect implementation. Represents missing or ineffective security controls at the design phase. + +**Common Vulnerabilities:** +- Missing rate limiting on sensitive operations +- No account lockout for failed authentication +- Lack of tenant isolation in multi-tenant systems +- Missing fraud detection controls +- Insufficient trust boundaries + +**Prevention:** +```python +# BAD: No rate limiting on password reset +@app.route('/password-reset', methods=['POST']) +def password_reset(): + send_reset_email(request.form['email']) + return "Email sent" + +# GOOD: Rate limiting and verification +from flask_limiter import Limiter +limiter = Limiter(app) + +@app.route('/password-reset', methods=['POST']) +@limiter.limit("3 per hour") +def password_reset(): + email = request.form['email'] + if not is_valid_email_format(email): + abort(400) + # Use consistent timing to prevent enumeration + send_reset_email_async(email) + return "If account exists, email was sent" +``` + +**Mitigation Strategies:** +1. Establish secure development lifecycle with security experts +2. Create and use secure design patterns library +3. Threat modeling for authentication, access control, business logic +4. Integrate security language in user stories +5. Implement tenant isolation and resource limits +6. Limit resource consumption per user/service + +--- + +### A07:2025 – Identification and Authentication Failures + +**Description:** Confirmation of user identity, authentication, and session management is critical. Weaknesses allow attackers to compromise passwords, keys, or session tokens. + +**Common Vulnerabilities:** +- Permitting weak or well-known passwords +- Using weak credential recovery (knowledge-based answers) +- Plain text or weakly hashed passwords +- Missing or ineffective MFA +- Exposing session IDs in URLs +- Not properly invalidating sessions on logout + +**Prevention:** +```python +# Password strength requirements +import re +def validate_password(password): + if len(password) < 12: + return False + if password in COMMON_PASSWORDS: # Check against breach lists + return False + return True + +# Session management +@app.route('/logout') +@login_required +def logout(): + session.clear() # Clear server-side session + response = redirect('/') + response.delete_cookie('session') + return response +``` + +**Mitigation Strategies:** +1. Implement MFA to prevent automated attacks +2. Avoid shipping with default credentials +3. Check passwords against known breached password lists +4. Align password policies with NIST 800-63b +5. Harden against enumeration attacks (consistent responses) +6. Limit failed login attempts with exponential backoff +7. Use server-side, secure session manager; regenerate IDs after login + +--- + +### A08:2025 – Software and Data Integrity Failures + +**Description:** Code and infrastructure that doesn't protect against integrity violations. Includes insecure deserialization, trusting unsigned updates, and CI/CD without verification. + +**Common Vulnerabilities:** +- Applications relying on untrusted CDNs or repositories +- Auto-update without integrity verification +- Insecure deserialization of untrusted data +- CI/CD pipelines without proper access controls +- Unsigned or unverified code deployments + +**Prevention:** +```html + + + + + +``` + +```python +# BAD: Unsafe deserialization +import pickle +data = pickle.loads(user_input) + +# GOOD: Safe serialization with validation +import json +data = json.loads(user_input) +validate_schema(data) +``` + +**Mitigation Strategies:** +1. Use digital signatures to verify software/data from expected source +2. Ensure dependencies are from trusted repositories +3. Use software supply chain security tools (OWASP Dependency-Check) +4. Review code and configuration changes +5. Ensure CI/CD has proper segregation, configuration, and access control +6. Don't send unsigned/unencrypted serialized data to untrusted clients + +--- + +### A09:2025 – Security Logging and Monitoring Failures + +**Description:** Without logging and monitoring, breaches cannot be detected. Insufficient logging, detection, monitoring, and response allows attackers to persist. + +**Common Vulnerabilities:** +- Auditable events not logged (logins, failed logins, transactions) +- Warnings and errors generate unclear log messages +- Logs only stored locally +- Alerting thresholds not set or ineffective +- Penetration tests don't trigger alerts +- Application can't detect active attacks in real-time + +**Prevention:** +```python +import logging +from datetime import datetime + +# Configure structured logging +logging.basicConfig( + format='%(asctime)s %(levelname)s %(name)s %(message)s', + level=logging.INFO +) +logger = logging.getLogger('security') + +@app.route('/login', methods=['POST']) +def login(): + user = authenticate(request.form['username'], request.form['password']) + if user: + logger.info(f"LOGIN_SUCCESS user={user.id} ip={request.remote_addr}") + return redirect('/dashboard') + else: + logger.warning(f"LOGIN_FAILURE username={request.form['username']} ip={request.remote_addr}") + return "Invalid credentials", 401 +``` + +**Mitigation Strategies:** +1. Log all login, access control, and server-side validation failures +2. Generate logs in format consumable by log management solutions +3. Encode log data correctly to prevent injection attacks +4. Ensure high-value transactions have audit trail with integrity controls +5. Establish effective monitoring and alerting +6. Create incident response and recovery plan (NIST 800-61r2) + +--- + +### A10:2025 – Mishandling of Exceptional Conditions + +**Description:** NEW category addressing failures in handling errors, edge cases, and unexpected states. Poor exception handling can leak information or cause security failures. + +**Common Vulnerabilities:** +- Exposing stack traces to users +- Inconsistent error handling between components +- Fail-open behavior (allowing access on error) +- Resource exhaustion without graceful degradation +- Race conditions in error paths +- Incomplete transaction rollbacks + +**Prevention:** +```python +# BAD: Leaking information +@app.errorhandler(Exception) +def handle_error(e): + return str(e), 500 # Exposes internal details + +# GOOD: Secure error handling +@app.errorhandler(Exception) +def handle_error(e): + error_id = uuid.uuid4() + logger.exception(f"Error {error_id}: {e}") + return {"error": "An error occurred", "id": str(error_id)}, 500 +``` + +```python +# BAD: Fail-open +def check_permission(user, resource): + try: + return authorization_service.check(user, resource) + except Exception: + return True # Fail-open! + +# GOOD: Fail-closed +def check_permission(user, resource): + try: + return authorization_service.check(user, resource) + except Exception as e: + logger.error(f"Auth check failed: {e}") + return False # Fail-closed +``` + +**Mitigation Strategies:** +1. Design for failure: expect and handle all error conditions +2. Implement fail-closed (deny by default) on errors +3. Use structured exception handling with appropriate granularity +4. Never expose internal errors to end users +5. Log all exceptions with context for debugging +6. Test error handling paths as thoroughly as happy paths +7. Implement circuit breakers for external dependencies + +--- + +## OWASP ASVS 5.0.0 + +The Application Security Verification Standard (ASVS) 5.0.0 was released May 30, 2025. It provides ~350 security requirements across 17 categories with three verification levels. + +### Verification Levels + +| Level | Use Case | Description | +|-------|----------|-------------| +| L1 | All applications | Basic security controls for low-risk applications | +| L2 | Most applications | Standard security for applications handling sensitive data | +| L3 | High-value targets | Advanced security for critical infrastructure, healthcare, finance | + +### ASVS Categories + +1. **V1: Architecture, Design & Threat Modeling** +2. **V2: Authentication** +3. **V3: Session Management** +4. **V4: Access Control** +5. **V5: Input Validation** +6. **V6: Stored Cryptography** +7. **V7: Error Handling & Logging** +8. **V8: Data Protection** +9. **V9: Communication** +10. **V10: Malicious Code** +11. **V11: Business Logic** +12. **V12: Files and Resources** +13. **V13: API and Web Services** +14. **V14: Configuration** +15. **V15: OAuth and OIDC** (New in 5.0) +16. **V16: Self-Contained Tokens** (New in 5.0) +17. **V17: WebSockets** (New in 5.0) + +### Key Requirements Examples + +**Authentication (V2):** +- V2.1.1: User passwords SHALL be at least 12 characters +- V2.1.6: Passwords SHALL be checked against breached password lists +- V2.2.1: Anti-automation controls SHALL prevent credential stuffing +- V2.5.2: Password recovery SHALL NOT reveal if account exists + +**Session Management (V3):** +- V3.2.1: Session tokens SHALL have at least 128 bits of entropy +- V3.3.1: Sessions SHALL be invalidated on logout +- V3.4.1: Cookie-based tokens SHALL have Secure attribute set + +**Access Control (V4):** +- V4.1.1: Access control SHALL be enforced server-side +- V4.2.1: Sensitive data SHALL only be accessible to authorized users +- V4.3.1: Directory browsing SHALL be disabled + +**Cryptography (V6):** +- V6.2.1: All cryptographic modules SHALL fail securely +- V6.4.1: Keys SHALL be generated using approved random generators +- V6.4.2: Keys SHALL be stored securely (HSM, vault) + +--- + +## OWASP Top 10 for Agentic Applications 2026 + +Released December 2025, this framework addresses security risks specific to AI agents, multi-agent systems, and autonomous applications. + +### Summary Table + +| ID | Risk | Description | +|----|------|-------------| +| ASI01 | Agent Goal Hijack | Prompt injection alters agent's core objectives | +| ASI02 | Tool Misuse | Legitimate tools used in unintended/unsafe ways | +| ASI03 | Identity & Privilege Abuse | Credential escalation across agent interactions | +| ASI04 | Supply Chain Vulnerabilities | Compromised plugins, MCP servers, or dependencies | +| ASI05 | Unexpected Code Execution | Unsafe code generation or execution by agents | +| ASI06 | Memory & Context Poisoning | Manipulation of RAG systems or agent memory | +| ASI07 | Insecure Inter-Agent Communication | Spoofing or tampering between agent systems | +| ASI08 | Cascading Failures | Error propagation across interconnected systems | +| ASI09 | Human-Agent Trust Exploitation | Social engineering through AI-generated content | +| ASI10 | Rogue Agents | Compromised or malicious agents within systems | + +--- + +### ASI01: Agent Goal Hijack + +**Description:** Attackers use prompt injection to alter an agent's intended goals, making it serve malicious purposes while appearing to function normally. + +**Attack Vectors:** +- Direct prompt injection in user inputs +- Indirect injection via compromised data sources +- Hidden instructions in documents, websites, or emails +- Multi-turn conversation manipulation + +**Prevention:** +- Implement strict input sanitization and filtering +- Use structured output formats to limit agent responses +- Establish clear goal boundaries with system prompts +- Monitor for goal deviation through behavioral analysis +- Implement human-in-the-loop for sensitive operations + +--- + +### ASI02: Tool Misuse + +**Description:** Agents with access to tools (APIs, databases, file systems) may use them in unintended ways due to malicious instructions or flawed reasoning. + +**Attack Vectors:** +- Tricking agents into executing harmful commands +- Using tools with elevated privileges +- Chaining tool calls to achieve unauthorized outcomes +- Exploiting ambiguous tool descriptions + +**Prevention:** +- Apply principle of least privilege to all tool access +- Implement fine-grained permissions per tool +- Validate all tool inputs and outputs +- Create tool usage policies and enforce them +- Log all tool invocations for audit + +--- + +### ASI03: Identity & Privilege Abuse + +**Description:** Agents may inherit, accumulate, or escalate privileges beyond what's appropriate, especially in multi-agent or long-running contexts. + +**Attack Vectors:** +- Credential theft through prompt injection +- Session token exposure +- Privilege escalation through tool chaining +- Identity confusion in multi-agent systems + +**Prevention:** +- Use short-lived, scoped credentials +- Implement identity verification between agents +- Don't pass raw credentials through agent context +- Audit privilege usage patterns +- Implement credential rotation + +--- + +### ASI04: Supply Chain Vulnerabilities + +**Description:** Compromised plugins, MCP servers, or third-party integrations introduce vulnerabilities into agent systems. + +**Attack Vectors:** +- Malicious MCP server implementations +- Typosquatting in plugin registries +- Compromised update mechanisms +- Backdoored agent frameworks + +**Prevention:** +- Verify plugin/server authenticity and signatures +- Maintain inventory of all integrations +- Sandbox third-party components +- Monitor for anomalous behavior from integrations +- Use allowlists for permitted plugins + +--- + +### ASI05: Unexpected Code Execution + +**Description:** Agents that generate or execute code may be tricked into running malicious code. + +**Attack Vectors:** +- Code injection through prompts +- Malicious code in retrieved context +- Unsafe code execution environments +- Bypassing code review through obfuscation + +**Prevention:** +- Execute generated code in sandboxed environments +- Implement static analysis before execution +- Limit code execution capabilities +- Require human approval for sensitive operations +- Use allowlists for permitted operations + +--- + +### ASI06: Memory & Context Poisoning + +**Description:** Attackers corrupt agent memory, RAG databases, or context to influence future behavior. + +**Attack Vectors:** +- Injecting malicious content into vector databases +- Manipulating conversation history +- Poisoning knowledge bases +- Exploiting context window limitations + +**Prevention:** +- Validate and sanitize all stored content +- Implement content integrity verification +- Segment memory by trust level +- Regular audits of stored knowledge +- Implement memory decay/expiration + +--- + +### ASI07: Insecure Inter-Agent Communication + +**Description:** Communication between agents may be vulnerable to interception, spoofing, or tampering. + +**Attack Vectors:** +- Man-in-the-middle attacks on agent communication +- Agent identity spoofing +- Message tampering +- Replay attacks + +**Prevention:** +- Authenticate all agent communications +- Encrypt inter-agent messages +- Implement message integrity verification +- Use secure channels for agent orchestration +- Validate agent identities cryptographically + +--- + +### ASI08: Cascading Failures + +**Description:** Errors in one agent or component propagate through interconnected systems, causing widespread failures. + +**Attack Vectors:** +- Triggering errors that cascade through agent chains +- Resource exhaustion in one agent affecting others +- Error handling that exposes sensitive information +- Retry storms from failed operations + +**Prevention:** +- Implement circuit breakers between agents +- Design for graceful degradation +- Isolate agent failures +- Rate limit inter-agent calls +- Monitor for cascade patterns + +--- + +### ASI09: Human-Agent Trust Exploitation + +**Description:** Attackers leverage the trust humans place in AI agents to conduct social engineering attacks. + +**Attack Vectors:** +- AI-generated phishing content +- Impersonation through agent responses +- Trust exploitation via helpful-seeming agents +- Deceptive multi-turn conversations + +**Prevention:** +- Clear labeling of AI-generated content +- User education on AI limitations +- Verification steps for sensitive actions +- Maintain human oversight for critical decisions +- Implement suspicious behavior detection + +--- + +### ASI10: Rogue Agents + +**Description:** Agents that have been compromised or are acting maliciously, either through external attack or flawed design. + +**Attack Vectors:** +- Agent compromise through injection attacks +- Malicious agent deployment +- Agent behavior modification +- Insider threats via agent systems + +**Prevention:** +- Monitor agent behavior for anomalies +- Implement agent authentication and authorization +- Regular security audits of agent systems +- Kill switches for agent operations +- Behavioral baselines and deviation detection + +--- + +## Key Security Principles + +### Defense in Depth +Layer multiple security controls so that if one fails, others provide protection. + +### Least Privilege +Grant minimum permissions necessary for functionality. Regularly review and revoke unnecessary access. + +### Fail Secure +When errors occur, default to a secure state. Deny access rather than allow it when uncertain. + +### Zero Trust +Never trust, always verify. Authenticate and authorize every request regardless of source. + +### Secure by Default +Ship products with secure defaults. Require explicit action to reduce security. + +### Input Validation +Validate all input on the server side. Use allowlists over denylists. + +### Output Encoding +Encode output based on context (HTML, JavaScript, SQL, etc.) to prevent injection. + +### Keep Security Simple +Complex security is often bypassed. Prefer simple, understandable controls. + +--- + +## Sources and References + +### Official OWASP Resources +- [OWASP Top 10:2025](https://owasp.org/Top10/) +- [OWASP ASVS 5.0](https://github.com/OWASP/ASVS) +- [OWASP Top 10 for Agentic Applications 2026](https://genai.owasp.org/) +- [OWASP Cheat Sheet Series](https://cheatsheetseries.owasp.org/) + +### Industry Analysis +- [GitLab: OWASP Top 10 2025 - What's Changed and Why It Matters](https://about.gitlab.com/blog/) +- [Aikido: OWASP Top 10 for Agentic Applications Guide](https://www.aikido.dev/blog/) +- [Security Boulevard: OWASP 2025 Analysis](https://securityboulevard.com/) + +### Standards and Guidelines +- [NIST SP 800-63b: Digital Identity Guidelines](https://pages.nist.gov/800-63-3/) +- [NIST SP 800-61r2: Incident Handling Guide](https://csrc.nist.gov/publications/detail/sp/800-61/rev-2/final) +- [CWE/SANS Top 25 Software Errors](https://cwe.mitre.org/top25/) + +--- + +*Last updated: January 2026* diff --git a/README.md b/README.md new file mode 100644 index 0000000..c1c837f --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +# OWASP Security Skill for Claude Code + +A Claude Code skill providing the latest OWASP security best practices (2025-2026) for developers building secure applications. + +## Quick Install (One Line) + +Add this skill to any project with a single command: + +```bash +curl -sL https://raw.githubusercontent.com/agam/claude-code-owasp/main/.claude/skills/owasp-security/SKILL.md -o .claude/skills/owasp-security/SKILL.md --create-dirs +``` + +Or install globally for all projects: + +```bash +curl -sL https://raw.githubusercontent.com/agam/claude-code-owasp/main/.claude/skills/owasp-security/SKILL.md -o ~/.claude/skills/owasp-security/SKILL.md --create-dirs +``` + +## What's Included + +### Claude Code Skill +Location: `.claude/skills/owasp-security/SKILL.md` + +- **OWASP Top 10:2025** quick reference table +- **Security code review checklists** for input handling, auth, access control, data protection, and error handling +- **Secure code patterns** with unsafe/safe examples +- **OWASP Agentic AI Security (2026)** - ASI01-ASI10 risks for AI agent systems +- **ASVS 5.0** key requirements by verification level +- **Language-specific security quirks** for 20+ languages with deep analysis guidance + +### Research Report +Location: `OWASP-2025-2026-Report.md` + +Comprehensive documentation covering all OWASP 2025-2026 standards. + +## Usage + +Once installed, Claude Code automatically activates this skill when you: +- Review code for security vulnerabilities +- Implement authentication or authorization +- Handle user input or external data +- Work with cryptography or password storage +- Design API endpoints +- Build AI agent systems + +### Example Prompts +``` +"Review this code for security issues" +"Is this authentication implementation secure?" +"What are the security risks in this Python code?" +"Help me implement secure session management" +"Check this AI agent for OWASP agentic risks" +``` + +## Covered Standards + +| Standard | Version | Focus | +|----------|---------|-------| +| OWASP Top 10 | 2025 | Web application vulnerabilities | +| OWASP ASVS | 5.0.0 | Security verification requirements | +| OWASP Agentic | 2026 | AI agent security risks | + +## Language Coverage + +Security quirks for 20+ languages including: + +| Web | Systems | Mobile | Scripting | +|-----|---------|--------|-----------| +| JavaScript/TypeScript | C/C++ | Swift | Python | +| PHP | Rust | Kotlin | Ruby | +| Java | Go | Dart | Perl | +| C# | | | Shell | + +Each language section includes common vulnerabilities, unsafe/safe code patterns, and key functions to watch for. + +## Alternative Installation + +### Clone Full Repository +```bash +git clone https://github.com/agam/claude-code-owasp.git +cp -r claude-code-owasp/.claude/skills/owasp-security YOUR_PROJECT/.claude/skills/ +``` + +## Contributing + +Contributions welcome! Please: +1. Fork the repository +2. Create a feature branch +3. Submit a pull request + +## Sources + +- [OWASP Top 10:2025](https://owasp.org/Top10/) +- [OWASP ASVS 5.0](https://owasp.org/www-project-application-security-verification-standard/) +- [OWASP Top 10 for Agentic Applications 2026](https://genai.owasp.org/) +- [OWASP Cheat Sheet Series](https://cheatsheetseries.owasp.org/) + +## License + +MIT License - See LICENSE file for details. + +--- + +**Keywords:** OWASP, security, Claude Code, AI security, application security, ASVS, secure coding, vulnerability, injection, XSS, CSRF, authentication, authorization