Security patterns

From CarlosDanielDev/maestro · View interactive version

Security patterns is an AI agent skill from the GitHub repository CarlosDanielDev/maestro. Universal security patterns based on OWASP Top 10 and security best practices. Framework-agnostic security guidance.

How to use this skill

Skill file

Security Patterns

Universal security patterns and OWASP Top 10 compliance. Framework-agnostic security guidance.

Skill Usage

| Aspect | Details |

|--------|---------|

| Consumer | subagent-security-analyst (and all architects) |

| Purpose | Security vulnerability detection and remediation patterns |

| Invocation | Subagents read this skill; NOT directly invocable by users |

| Applicability | All frameworks and languages |


OWASP Top 10 (2021) - Quick Reference

| # | Vulnerability | Description | Prevention |

|---|---------------|-------------|------------|

| A01 | Broken Access Control | Missing or improper authorization | Implement proper access controls, deny by default |

| A02 | Cryptographic Failures | Weak encryption, exposed secrets | Use strong encryption, protect data at rest/transit |

| A03 | Injection | SQL, NoSQL, Command injection | Use parameterized queries, ORM, input validation |

| A04 | Insecure Design | Missing security requirements | Apply threat modeling, secure design patterns |

| A05 | Security Misconfiguration | Default configs, verbose errors | Harden configs, disable debug in production |

| A06 | Vulnerable Components | Outdated dependencies | Keep dependencies updated, scan for CVEs |

| A07 | Auth/Session Issues | Weak authentication | Use MFA, secure session management, strong passwords |

| A08 | Data Integrity Failures | Unsigned/unverified data | Implement digital signatures, integrity checks |

| A09 | Logging Failures | Insufficient logging | Log security events, monitor anomalies |

| A10 | SSRF | Server-side request forgery | Validate URLs, use allowlists, network segmentation |


Common Security Patterns

Input Validation

ALWAYS validate and sanitize user input:
1. Validate type, length, format, range
2. Use allowlist (not denylist) when possible
3. Sanitize before processing or storing
4. Encode before rendering (prevent XSS)

Authentication

Best practices:
1. Never store passwords in plaintext
2. Use bcrypt, scrypt, or Argon2 for hashing
3. Implement account lockout after failed attempts
4. Use MFA where possible
5. Secure password reset flows

Authorization

Implement principle of least privilege:
1. Check permissions on EVERY request
2. Use role-based access control (RBAC)
3. Deny by default
4. Validate on server-side (never trust client)

SQL Injection Prevention

1. Use parameterized queries/prepared statements
2. Use ORMs with proper escaping
3. Never concatenate user input into queries
4. Apply principle of least privilege to DB users

XSS Prevention

1. Escape output based on context (HTML, JS, CSS, URL)
2. Use Content Security Policy (CSP) headers
3. Sanitize HTML if allowing user HTML
4. Use frameworks that auto-escape by default

CSRF Prevention

1. Use anti-CSRF tokens
2. Validate token on state-changing requests
3. Use SameSite cookie attribute
4. Verify Origin/Referer headers

Detailed Guides

For complete implementation details, read:


Security Checklist

Authentication & Authorization

Input Validation

Data Protection

API Security

Headers & Configuration

Logging & Monitoring


Security Headers (Universal)

Content-Security-Policy: default-src 'self'
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: geolocation=(), microphone=()
Strict-Transport-Security: max-age=31536000; includeSubDomains

Common Vulnerabilities to Flag

Critical

High

Medium


Framework-Specific Security

Node.js/Express

// Helmet for security headers
const helmet = require('helmet')
app.use(helmet())

// Rate limiting
const rateLimit = require('express-rate-limit')
app.use(rateLimit({ windowMs: 15 * 60 * 1000, max: 100 }))

// Parameterized queries
db.query('SELECT * FROM users WHERE id = $1', [userId])

Python/Django

# Django has many security features built-in:
# - CSRF protection (middleware)
# - XSS protection (template auto-escaping)
# - SQL injection protection (ORM)

# Ensure these settings:
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

Java/Spring Boot

// Spring Security configuration
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().and()
            .headers()
                .contentSecurityPolicy("default-src 'self'");
    }
}

Tools for Security Testing


When to Consult This Skill

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.