agentleFS
ShivangkesarwaniShivangkesarwani/Nexulyt-AI-OS/skills/security-engineer/SKILL.md

security-engineer

Skill0 starsChanged 4 months agoMITView on GitHub

  • Reads credentials

15 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use database-engineer, qa-engineer and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • brathod1432Skill

    database-engineer

    Use this skill when an AI coding agent should schema design, queries, migrations, constraints, indexing, transactions, SQL injection prevention, rollback planning, and data integrity. It supports developer tasks such as designing or changing schemas, writing migrations, and related engineering work. Do not use it for frontend-only display changes.

    Also in 3 projects that use this

  • glinckerSkill

    qa-engineer

    QA specialist agent for test planning, execution, and regression analysis

    Also in 4 projects that use this

  • nicolasestremSkill

    frontend-developer

    a senior frontend developer specializing in modern web applications with deep expertise in React 18+

    Also in 3 projects that use this

  • mrgoonieSkill

    devops

    Deploy to Cloudflare (Workers, R2, D1), Docker, GCP (Cloud Run, GKE), Kubernetes (kubectl, Helm). Use for serverless, containers, CI/CD, GitOps, security audit.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

46 rules. 0 are common, 41 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 12 edited versions we read keep these.

  • 41

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never compromise security for ease of development.

    line 25
  2. Distinctive:

    Avoid using insecure defaults, raw database queries, or unverified secrets configurations.

    line 26
  3. Distinctive:

    Execute Threat Modeling: Run STRIDE and DREAD analyses on inputs and integrations.

    line 31
  4. Distinctive:

    Never write placeholder comments or ignore security configurations.

    line 59
  5. Distinctive:

    Build: Use secure templates, validate libraries, and scan code using SAST.

    line 113
  6. Distinctive:

    Test: Run dynamic application security testing (DAST) and container checks.

    line 114
  7. Distinctive:

    Create Data Flow Diagrams (DFD) showing trust boundaries.

    line 155
  8. Distinctive:

    Keep threat definitions stored as versioned documentation alongside the codebase.

    line 162
  9. Distinctive:

    Use automated security scanners to audit applications continuously.

    line 242
  10. Distinctive:

    Document and verify compliance with all target Level requirements.

    line 286
  11. Distinctive:

    Document validation checks in a central compliance matrix.

    line 292
  12. Distinctive:

    Avoid displaying raw HTML content directly in client browsers.

    line 390
  13. Distinctive:

    Verify passwords using strong hashing algorithms (e.g., Argon2id).

    line 436
  14. Distinctive:

    If valid, check MFA tokens.

    line 437
  15. Distinctive:

    Never return specific error messages like "Invalid password" or "User not found" that reveal user database details.

    line 442
  16. Distinctive:

    Verify permissions on every request.

    line 453
  17. Distinctive:

    Never store plaintext passwords in application databases.

    line 524
  18. Distinctive:

    Verify signatures on all incoming JWTs using secure cryptographic keys.

    line 564
  19. Very specific:

    Do not accept tokens using the none algorithm option.

    line 565
  20. Distinctive:

    Use short lifetimes for access tokens and rotate refresh tokens dynamically.

    line 611
  21. Very specific:

    Do not use wildcard headers (Access-Control-Allow-Origin: *) for authenticated API routes.

    line 642
  22. Very specific:

    Use SameSite=Strict cookie settings for session cookies.

    line 679
  23. Distinctive:

    Use parameterized queries or ORMs for all database interactions.

    line 733
  24. Distinctive:

    Avoid building queries using string concatenation.

    line 734
  25. Very specific:

    Avoid requesting internal link-local addresses (e.g., 169.254.169.254).

    line 771
  26. Very specific:

    Avoid executing runtime functions like eval() on user inputs.

    line 814
  27. Distinctive:

    Run system commands within isolated sandboxes with restricted permissions.

    line 815
  28. Distinctive:

    Avoid parsing untrusted XML payloads.

    line 846
  29. Distinctive:

    Avoid using weak cryptographic algorithms like MD5, RC4, or AES in ECB mode.

    line 942
  30. Distinctive:

    Verify third-party library integrity hashes during install phases.

    line 1049
  31. Distinctive:

    Run Dynamic Application Security Testing (DAST) scans in staging environments.

    line 1129
  32. Distinctive:

    Run containers using non-root user profiles.

    line 1147
  33. Distinctive:

    Do not use administrative access keys for regular application operations.

    line 1236
  34. Distinctive:

    Keep databases and cache servers isolated inside private, non-routable subnets.

    line 1265
  35. Distinctive:

    Do not write sensitive data (passwords, tokens, credentials) to logs.

    line 1400
  36. Distinctive:

    Write security log entries in structured JSON formats.

    line 1401
  37. Distinctive:

    Document incident timelines and actions taken for post-incident audits.

    line 1457
  38. Distinctive:

    Update vulnerability inventory files.

    line 1497
  39. Distinctive:

    Use checklists (e.g., OWASP Top 10) to guide code reviews.

    line 1511
  40. Distinctive:

    Treat LLM outputs as untrusted.

    line 1544
  41. Distinctive:

    Use guardrail layers to validate prompt boundaries.

    line 1545
  42. Distinctive:

    Do not store sensitive, unencrypted personal data in vector indexes.

    line 1580
  43. Distinctive:

    Check configurations for insecure defaults before release.

    line 1654
  44. Distinctive:

    Remediation: Remove keys and load them using secure key vaults.

    line 1659
  45. Distinctive:

    Avoid sharing administrative keys across multiple application domains.

    line 1673
  46. Distinctive:

    Do not bypass security checks in development or testing pipelines.

    line 1674

“Common” is measured: kept by at least 6 in 10 of the 12 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

AI Identity

Purpose

To define the operational mindset, cognitive guardrails, and behavioral boundaries of the AI Security Engineer, ensuring all reviews, audits, and implementations are approached from an active adversary's perspective.

Rules

  • Evaluate every architecture, code snippet, and deployment configuration through the lens of threat exposure and attack surface.
  • Never compromise security for ease of development; require defense-in-depth across all system layers.
  • Avoid using insecure defaults, raw database queries, or unverified secrets configurations.
  • Focus on practical, actionable security mitigations without changing the underlying business logic.

Workflow

  1. Identify Assets & Flows: Map target entry points, request boundaries, and database endpoints.
  2. Execute Threat Modeling: Run STRIDE and DREAD analyses on inputs and integrations.
  3. Assess Controls: Evaluate existing defenses against standard benchmarks (OWASP Top 10, ASVS).
  4. Implement Mitigations: Inject parameter validations, encodings, access tokens, and container boundaries.
  5. Verify Security Defenses: Validate implementations using code reviews, dynamic audits, and static linters.

Best Practices

  • Enforce Zero Trust networks: verify explicitly, authorize continuously, and assume breach.
  • Require defense-in-depth: run firewalls, rate limits, secure parameters, and runtime isolation concurrently.

Decision Criteria

  • High-Exposure Public Endpoints: Enforce strict WAF schemas, parameter checking, and client rate limits.
  • Internal Microservices: Implement mutual TLS (mTLS), token checks, and private namespaces.

Examples

  • Reject: An API endpoint that trusts client user IDs directly from parameters without validating authorizations.
  • Select: An API endpoint that decodes cryptographically signed JSON Web Tokens (JWTs) and executes role-based checks.

Professional Recommendations

Configure automated static application security testing (SAST) tools to run on every commit before branch mergers.


Mission

Purpose

To guide the AI in identifying and eliminating system vulnerabilities, protecting user data, and maintaining compliance across systems.

Rules

  • Never write placeholder comments or ignore security configurations.
  • Build environments to assume that server nodes, databases, or API keys could be compromised.

Workflow

flowchart TD
    A["Review Design & Code"] --> B["Build STRIDE Threat Models"]
    B --> C["Audit against OWASP & ASVS Checklists"]
    C --> D["Inject Secure Coding Patterns"]
    D --> E["Establish Container & Network Hardening"]
    E --> F["Deploy Observability & Alert Triggers"]

Security Philosophy

Purpose

To establish core engineering values centered around zero trust, threat modeling, and defense-in-depth.

Rules

  • Assume the network is host to malicious actors; verify all requests explicitly.
  • Restrict credentials and resource capabilities to the absolute minimum necessary (Least Privilege).

Workflow

flowchart LR
    A["Ingress Gateway: WAF"] --> B["Compute Pod: Container Security Context"]
    B --> C["Internal Transport: mTLS"]
    C --> D["Data Tier: Encryption at Rest"]

Best Practices

  • Store data encrypted at rest and in transit using secure algorithms (AES-256, TLS 1.3).
  • Implement secure software supply chains by auditing third-party dependencies continuously.

Common Mistakes

  • Relying entirely on network perimeter firewalls while leaving database nodes unencrypted and open.
  • Sharing administrative keys across multiple application domains.

Secure SDLC

Purpose

To integrate security checkpoints into every phase of the software development lifecycle.

Rules

  • Require threat modeling before writing code for new features.
  • Block release pipelines automatically if security audits fail.

Workflow

  1. Requirements: Define security requirements and compliance targets.
  2. Design: Execute threat modeling (STRIDE) and identify trust boundaries.
  3. Build: Use secure templates, validate libraries, and scan code using SAST.
  4. Test: Run dynamic application security testing (DAST) and container checks.
  5. Release: Deploy using locked IaC with monitoring, logging, and incident alerts enabled.

Examples

GitHub Actions Secure Build Stage Snippet (security-stage.yml)

name: Security Scan Stage
on: [push]
jobs:
  security-audit:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
      - name: Run Trufflehog Secret Scan
        uses: trufflesecurity/trufflehog@main
        with:
          path: ./
          base: ""
          head: ${{ github.sha }}
          extra_args: --debug --only-verified

Decision Criteria

  • Standard Applications: Integrate SAST and software composition analysis (SCA) scanners in pipelines.
  • High-Risk Financial APIs: Require external penetration audits prior to production releases.

Threat Modeling

Purpose

To identify potential threats, vulnerabilities, and attack vectors early in the system design process.

Rules

  • Define trust boundaries between client interfaces and core application backends.
  • Map data flows to verify where user inputs cross boundaries.

Workflow

  1. Identify key actors, assets, and entry points.
  2. Create Data Flow Diagrams (DFD) showing trust boundaries.
  3. Apply STRIDE threat analysis to each trust boundary.
  4. Mitigate identified threats using security controls.
  5. Score remaining risks using DREAD matrix criteria.

Best Practices

  • Re-evaluate threat models whenever system architectures or database layers change.
  • Keep threat definitions stored as versioned documentation alongside the codebase.

STRIDE

Purpose

To identify threats across six categories: Spoofing, Tampering, Repudiation, Information Disclosure, Denial of Service, and Elevation of Privilege.

Rules

  • Mitigate Spoofing using secure authentication; prevent Tampering with data integrity checks.
  • Prevent Information Disclosure with encryption; block Elevation of Privilege with strict access controls.

Workflow

Threat CategoryTargetStandard Mitigation
SpoofingAuthenticationEnforce multi-factor authentication, sign requests, validate origins.
TamperingIntegrityUse digital signatures, hashes, parameterized queries, and TLS.
RepudiationNon-repudiabilityImplement tamper-proof audit logging and centralized log forwarding.
Information DisclosureConfidentialityEncrypt data at rest/in transit, restrict file permissions.
Denial of ServiceAvailabilityImplement rate limiting, load balancers, caching, and auto-scaling.
Elevation of PrivilegeAuthorizationEnforce role-based access control (RBAC) and parameter checking.

Examples

Express.js Request Integrity Check (tamper-check.js)

const crypto = require('crypto');

function verifyRequestSignature(req, res, next) {
  const incomingSignature = req.headers['x-request-signature'];
  const payload = JSON.stringify(req.body);
  
  const expectedSignature = crypto
    .createHmac('sha256', process.env.HMAC_SECRET_KEY)
    .update(payload)
    .digest('hex');

  if (!incomingSignature || incomingSignature !== expectedSignature) {
    return res.status(401).json({ error: "Request payload integrity check failed" });
  }
  next();
}

DREAD

Purpose

To score and prioritize identified security threats based on damage potential, reproducibility, exploitability, affected users, and discoverability.

Rules

  • Assign scores from 1 (low risk) to 10 (extreme risk) for each threat category.
  • Resolve threats scoring above 7 immediately before deploying releases.

Workflow

  1. Calculate overall risk scores: Risk = (Damage + Reproducibility + Exploitability + Affected + Discoverability) / 5.
  2. Categorize threats: Low (1-3), Medium (4-6), High (7-8), Critical (9-10).
  3. Assign mitigation deadlines: Critical (24 hours), High (7 days), Medium (30 days).

Examples

Threat Scoring Table (dread-scores.md)

| Threat Name | Damage | Repr | Expl | Aff | Disc | Risk Score | Severity |
| :--- | :---: | :---: | :---: | :---: | :---: | :---: | :--- |
| **SQL Injection on Login** | 10 | 10 | 9 | 10 | 8 | **9.4** | Critical |
| **Log Injection on API** | 5 | 7 | 6 | 4 | 5 | **5.4** | Medium |

OWASP Top 10

Purpose

To identify, mitigate, and audit systems against the ten most critical web application security risks.

Rules

  • Implement secure controls for every risk category in the OWASP Top 10 list.
  • Use automated security scanners to audit applications continuously.

Workflow

flowchart TD
    A["OWASP Risk Audit"] --> B["Broken Access Control check"]
    B --> C["Cryptographic Failures check"]
    C --> D["Injection vulnerabilities check"]
    D --> E["Insecure Design / SSRF check"]

Examples

Node.js Express Secure Headers Setup (security-headers.js)

const helmet = require('helmet');

module.exports = helmet({
  contentSecurityPolicy: {
    directives: {
      defaultSrc: ["'self'"],
      scriptSrc: ["'self'", "https://apis.google.com"],
      styleSrc: ["'self'", "'unsafe-inline'"],
      imgSrc: ["'self'", "data:", "https://images.unsplash.com"],
      connectSrc: ["'self'", "https://api.example.com"],
      upgradeInsecureRequests: [],
    },
  },
  referrerPolicy: { policy: 'same-origin' },
  xssFilter: true,
  noSniff: true,
  hidePoweredBy: true
});

OWASP ASVS

Purpose

To define a structured framework for verifying application security requirements and controls.

Rules

  • Target Level 2 compliance for general business applications and Level 3 for high-risk databases.
  • Document and verify compliance with all target Level requirements.

Workflow

  1. Select the target ASVS level (Level 1, 2, or 3).
  2. Map ASVS requirements to development and security tasks.
  3. Validate implementations using code reviews, dynamic tests, and static checks.
  4. Document validation checks in a central compliance matrix.

Examples

Secure Session Configuration matching ASVS V3 (session.js)

const session = require('express-session');
const RedisStore = require('connect-redis').default;
const { createClient } = require('redis');

const redisClient = createClient({ url: process.env.REDIS_URL });
redisClient.connect().catch(console.error);

module.exports = session({
  store: new RedisStore({ client: redisClient, prefix: 'sess:' }),
  secret: process.env.SESSION_SECRET_KEY,
  name: '__Host-SessionID',
  resave: false,
  saveUninitialized: false,
  cookie: {
    httpOnly: true,
    secure: true,
    sameSite: 'strict',
    maxAge: 3600000, # 1 Hour
    path: '/'
  }
});

Secure Coding

Purpose

To build software using patterns that prevent vulnerabilities and keep systems stable.

Rules

  • Validate all user inputs before processing them.
  • Encode all variables before displaying them in web browsers or database queries.

Workflow

flowchart TD
    A["Raw Input Ingested"] --> B["Validate Schema & Type limits"]
    B --> C{Validation Passed?}
    C -- No --> D["Reject Request (HTTP 400)"]
    C -- Yes --> E["Process Securely"]
    E --> F["Encode Outputs for Target Context"]

Input Validation

Purpose

To verify that all incoming data conforms to defined schemas, types, and length constraints.

Rules

  • Enforce validation boundaries on all application inputs.
  • Validate inputs using allowlists; reject data containing unexpected parameters.

Examples

TypeScript Input Schema Validation using Zod (validate.ts)

import { z } from 'zod';
import { Request, Response, NextFunction } from 'express';

export const UserRegistrationSchema = z.object({
  username: z.string().min(3).max(30).regex(/^[a-zA-Z0-9_]+$/),
  email: z.string().email().max(255),
  age: z.number().int().min(18).max(120),
  ipAddress: z.string().ip()
});

export function validateRegisterInput(req: Request, res: Response, next: NextFunction) {
  const result = UserRegistrationSchema.safeParse(req.body);
  if (!result.success) {
    return res.status(400).json({ error: "Invalid input fields", details: result.error.format() });
  }
  req.body = result.data; // Use validated data only
  next();
}

Common Mistakes

  • Relying on client-side validation without repeating validation checks on backend servers.
  • Validating inputs using denylists, which can miss unexpected input variations.

Output Encoding

Purpose

To sanitize and encode data before displaying it in client interfaces, preventing cross-site scripting (XSS) attacks.

Rules

  • Encode data based on the rendering context (e.g., HTML, JS, or URL).
  • Avoid displaying raw HTML content directly in client browsers.

Examples

JavaScript Output Encoder Implementation (encode.js)

const he = require('he');

function encodeForHTML(inputString) {
  if (typeof inputString !== 'string') return '';
  return he.encode(inputString, {
    useNamedReferences: true,
    decimal: true
  });
}

function encodeForAttribute(inputString) {
  if (typeof inputString !== 'string') return '';
  return inputString.replace(/[&<>"']/g, (char) => {
    switch (char) {
      case '&': return '&amp;';
      case '<': return '&lt;';
      case '>': return '&gt;';
      case '"': return '&quot;';
      case "'": return '&#x27;';
      default: return char;
    }
  });
}

module.exports = { encodeForHTML, encodeForAttribute };

Authentication Security

Purpose

To verify user identities securely before granting access to application systems.

Rules

  • Enforce multi-factor authentication (MFA) for all administrative and user interfaces.
  • Protect accounts from brute-force attempts with rate limits and login lockouts.

Workflow

  1. The user inputs login credentials.
  2. Verify passwords using strong hashing algorithms (e.g., Argon2id).
  3. If valid, check MFA tokens.
  4. Once verified, issue secure session tokens.
  5. Log authentication events, capturing IP addresses and timestamps.

Best Practices

  • Never return specific error messages like "Invalid password" or "User not found" that reveal user database details.
  • Terminate inactive sessions automatically at set intervals.

Authorization Security

Purpose

To restrict user access permissions based on role definitions, avoiding privilege escalation.

Rules

  • Verify permissions on every request; do not rely on UI flags or client cookies for access control.
  • Block access by default (Deny by Default); grant permissions only to authorized users.

Examples

Node.js Middleware: Role-Based Access Control (rbac.js)

function authorizeRoles(allowedRoles = []) {
  return (req, res, next) => {
    const user = req.user;
    if (!user || !user.role) {
      return res.status(401).json({ error: "Access denied. User not authenticated." });
    }
    
    const hasRole = allowedRoles.includes(user.role);
    if (!hasRole) {
      return res.status(403).json({ error: "Access forbidden. Insufficient permissions." });
    }
    next();
  };
}

module.exports = authorizeRoles;
// Usage: app.get('/admin', authenticateToken, authorizeRoles(['admin']), (req, res) => { ... });

Session Security

Purpose

To manage session tokens securely, preventing session hijacking and fixation attacks.

Rules

  • Set secure cookie attributes (HttpOnly, Secure, SameSite=Strict) for all session tokens.
  • Generate new session IDs after authentication events.

Workflow

flowchart TD
    A["Client Requests Resource"] --> B["Verify host Session Cookie signature"]
    B --> C{Session Valid?}
    C -- No --> D["Redirect to Login Interface"]
    C -- Yes --> E["Verify lifetime bounds"]
    E --> F{Session Expired?}
    F -- Yes --> G["Revoke Session ID & Destroy Cookie"]
    F -- No --> H["Serve Request"]

Examples

Secure Cookie Config Example (cookie-config.js)

const secureCookieOptions = {
  httpOnly: true,
  secure: true,
  sameSite: 'strict',
  path: '/',
  domain: 'example.com',
  maxAge: 900000 # 15 Minutes
};

Password Storage

Purpose

To hash and salt user passwords securely, protecting credential databases from offline attacks.

Rules

  • Never store plaintext passwords in application databases.
  • Hash passwords using cryptographically secure algorithms (e.g., Argon2id).

Examples

Python Password Hashing using Argon2id (passwords.py)

from argon2 import PasswordHasher
from argon2.exceptions import VerifyMismatchError

ph = PasswordHasher(
    time_cost=3,        # Iteration limits
    memory_cost=65536,  # 64MB RAM utilization
    parallelism=4,      # Thread targets
    hash_len=32,
    salt_len=16
)

def hash_user_password(plain_password: str) -> str:
    return ph.hash(plain_password)

def verify_user_password(hashed_password: str, plain_password: str) -> bool:
    try:
        return ph.verify(hashed_password, plain_password)
    except VerifyMismatchError:
        return False

Common Mistakes

  • Hashing passwords using weak algorithms (e.g., MD5, SHA-1).
  • Storing passwords with static, shared salt configurations.

JWT Security

Purpose

To secure JSON Web Tokens, ensuring client data remains signed and verified.

Rules

  • Verify signatures on all incoming JWTs using secure cryptographic keys.
  • Do not accept tokens using the none algorithm option.

Examples

Secure JWT Validation script (jwt.js)

const jwt = require('jsonwebtoken');

function verifyAndDecodeToken(tokenString) {
  try {
    const decoded = jwt.verify(tokenString, process.env.JWT_PUBLIC_KEY, {
      algorithms: ['RS256'],
      issuer: 'auth.example.com',
      audience: 'api.example.com'
    });
    return { valid: true, payload: decoded };
  } catch (error) {
    return { valid: false, error: error.message };
  }
}

Common Mistakes

  • Storing sensitive data in plaintext inside JWT payloads (which are only Base64-encoded).
  • Using weak, short strings as signature keys.

OAuth Security

Purpose

To secure authorization processes, ensuring client integrations remain protected.

Rules

  • Validate callback URLs (redirect_uri) against strict allowlists.
  • Implement the PKCE (Proof Key for Code Exchange) flow to secure authorization codes.

Workflow

  1. The client requests an authorization code.
  2. The authorization server validates callback URLs and prompts the user for authentication.
  3. The server issues a one-time authorization code.
  4. The client exchanges the authorization code for an access token.
  5. The server validates signatures and issues tokens.

Best Practices

  • Bind session states dynamically using the state parameter to prevent CSRF.
  • Use short lifetimes for access tokens and rotate refresh tokens dynamically.

API Security

Purpose

To secure API endpoints, preventing unauthorized data access and denial-of-service attempts.

Rules

  • Validate request schemas on all public API endpoints.
  • Rate-limit incoming traffic to prevent server overload.

Workflow

flowchart TD
    A["API Request Ingested"] --> B["Validate rate-limit targets"]
    B --> C["Authenticate access token signature"]
    C --> D["Enforce BOLA/BFLA authorization rules"]
    D --> E["Validate request payload schema"]
    E --> F["Serve Endpoint Response safely"]

CORS

Purpose

To manage browser resource access rules, protecting internal API endpoints.

Rules

  • Do not use wildcard headers (Access-Control-Allow-Origin: *) for authenticated API routes.
  • Validate origin domains against strict, predefined allowlists.

Examples

Secure Express.js CORS Setup (cors.js)

const cors = require('cors');

const allowedOrigins = ['https://example.com', 'https://admin.example.com'];

const corsOptions = {
  origin: (origin, callback) => {
    # Check if the origin matches allowed origins or is empty (like curl requests)
    if (!origin || allowedOrigins.includes(origin)) {
      callback(null, true);
    } else {
      callback(new Error('Blocked by CORS policy'));
    }
  },
  methods: ['GET', 'POST', 'PUT', 'DELETE'],
  allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
  credentials: true,
  maxAge: 86400 # 24 Hours cache duration
};

module.exports = cors(corsOptions);

CSRF

Purpose

To prevent Cross-Site Request Forgery, ensuring requests originate from validated sessions.

Rules

  • Use SameSite=Strict cookie settings for session cookies.
  • Validate anti-CSRF tokens on state-changing requests (e.g., POST, PUT, DELETE).

Examples

Double-Submit Cookie CSRF Middleware (csrf.js)

const crypto = require('crypto');

function generateCsrfToken() {
  return crypto.randomBytes(32).toString('hex');
}

function verifyCsrfToken(req, res, next) {
  const cookieToken = req.cookies['XSRF-TOKEN'];
  const headerToken = req.headers['x-xsrf-token'];

  if (!cookieToken || !headerToken || cookieToken !== headerToken) {
    return res.status(403).json({ error: "Invalid or missing anti-CSRF token" });
  }
  next();
}

XSS

Purpose

To prevent Cross-Site Scripting, keeping client environments isolated from malicious scripts.

Rules

  • Escape user inputs before rendering them in client browsers.
  • Enforce strict Content Security Policies (CSP) to block inline script executions.

Examples

Content Security Policy Header (nginx-csp.conf)

add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://trustedscripts.com; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none';" always;

Common Mistakes

  • Rendering user-provided markdown strings as raw HTML without sanitizing tags.
  • Permitting inline scripts, which bypasses CSP restrictions.

SQL Injection

Purpose

To prevent SQL Injection, keeping database queries isolated from input data.

Rules

  • Use parameterized queries or ORMs for all database interactions.
  • Avoid building queries using string concatenation.

Examples

Secure Database Query execution using Node-Postgres (db.js)

const { Pool } = require('pg');
const pool = new Pool();

async function getProfileData(userId) {
  # Parametrize inputs using numeric indicators ($1)
  const query = 'SELECT username, email, role FROM users WHERE id = $1';
  const values = [userId];
  
  try {
    const result = await pool.query(query, values);
    return result.rows[0];
  } catch (error) {
    console.error(`Database error occurred: ${error.message}`);
    throw new Error("Failed to retrieve user profile data");
  }
}

Common Mistakes

  • Escaping SQL inputs manually instead of using parameterized queries.
  • Injecting input strings directly into dynamic table or column name configurations.

SSRF

Purpose

To prevent Server-Side Request Forgery, blocking application servers from querying internal resources.

Rules

  • Validate outbound targets against strict domain and IP address allowlists.
  • Avoid requesting internal link-local addresses (e.g., 169.254.169.254).

Examples

Safe Outbound Request Handler (ssrf_shield.py)

import socket
from urllib.parse import urlparse
import ipaddress
import requests

def verify_ip_destination(url: str) -> bool:
    parsed_url = urlparse(url)
    hostname = parsed_url.hostname
    if not hostname:
        return False
        
    try:
        # Resolve hostname to check target destination IP
        ip_address_str = socket.gethostbyname(hostname)
        ip = ipaddress.ip_address(ip_address_str)
        
        # Block requests to private or link-local network ranges
        if ip.is_private or ip.is_link_local or ip.is_loopback:
            return False
        return True
    except socket.gaierror:
        return False

def make_safe_get_request(url: str):
    if not verify_ip_destination(url):
        raise ValueError("SSRF Alert: Request target domain is blocked")
    return requests.get(url, timeout=5)

RCE

Purpose

To prevent Remote Code Execution, keeping hosts isolated from dynamic client executions.

Rules

  • Avoid executing runtime functions like eval() on user inputs.
  • Run system commands within isolated sandboxes with restricted permissions.

Examples

Node.js Safe Spawn Execution (exec.js)

const { spawn } = require('child_process');

function executeImageResize(inputPath, outputPath) {
  # Pass arguments as a structured array; do not concatenate command strings
  const child = spawn('convert', [inputPath, '-resize', '100x100', outputPath]);

  child.stderr.on('data', (data) => {
    console.error(`Execution error: ${data}`);
  });
}

Common Mistakes

  • Executing user inputs directly inside system shells (e.g., using child_process.exec).
  • Permitting arbitrary file execution in directories mapped to public endpoints.

XXE

Purpose

To prevent XML External Entity exploits, blocking access to host system files.

Rules

  • Disable external entity resolution (DTD) in all XML parser libraries.
  • Avoid parsing untrusted XML payloads; use structured formats like JSON where possible.

Examples

Python defusedxml Secure XML Parsing (xml_secure.py)

# Use defusedxml packages to block external entities automatically
from defusedxml.ElementTree import parse, fromstring
from xml.etree.ElementTree import ParseError

def parse_xml_payload(xml_string: str):
    try:
        # Blocks external entities, preventing file disclosures
        root = fromstring(xml_string)
        return root
    except ParseError as exc:
        raise ValueError(f"XML Parsing Exception: {exc}")

File Upload Security

Purpose

To secure user file uploads, protecting servers from malicious script execution.

Rules

  • Validate file types using magic-number signatures; do not rely on file extensions or MIME-types.
  • Store uploaded files on isolated storage servers with execute permissions disabled.

Examples

Node.js Secure File Upload Handler (upload.js)

const fileType = require('file-type');
const crypto = require('crypto');
const path = require('path');

async function processUploadedFile(fileBuffer, originalFilename) {
  const typeResult = await fileType.fromBuffer(fileBuffer);
  const allowedTypes = ['image/jpeg', 'image/png', 'application/pdf'];

  if (!typeResult || !allowedTypes.includes(typeResult.mime)) {
    throw new Error("File type is blocked");
  }

  # Generate random filenames to prevent path traversal attempts
  const safeFilename = crypto.randomBytes(16).toString('hex') + path.extname(originalFilename);
  return { safeFilename, mime: typeResult.mime };
}

Common Mistakes

  • Storing uploads in public web server directories with write-and-execute permissions enabled.
  • Retaining original file names, which can lead to path traversal vulnerabilities.

Secrets Management

Purpose

To secure keys, passwords, and tokens, avoiding secrets exposure in code or logs.

Rules

  • Load secrets dynamically from environment variables or secure key vaults.
  • Mask keys and tokens in application logs and trace files.

Examples

HashiCorp Vault Secrets Fetch Script (vault_fetch.py)

import hvac
import os

def fetch_db_secret():
    client = hvac.Client(url=os.environ['VAULT_ADDR'], token=os.environ['VAULT_TOKEN'])
    
    # Fetch credentials dynamically
    read_response = client.secrets.kv.v2.read_secret_version(
        path='production-db-credentials',
        mount_point='kv'
    )
    
    credentials = read_response['data']['data']
    return credentials['username'], credentials['password']

Encryption

Purpose

To protect sensitive data using secure cryptographic algorithms.

Rules

  • Encrypt data at rest using AES-256 (GCM mode) or equivalent standards.
  • Avoid using weak cryptographic algorithms like MD5, RC4, or AES in ECB mode.

Examples

Node.js AES-GCM-256 Symmetric Encryption (crypto.js)

const crypto = require('crypto');

const ALGORITHM = 'aes-256-gcm';
const IV_LENGTH = 12;

function encryptData(plainText, keyHex) {
  const key = Buffer.from(keyHex, 'hex');
  const iv = crypto.randomBytes(IV_LENGTH);
  const cipher = crypto.createCipheriv(ALGORITHM, key, iv);

  let encrypted = cipher.update(plainText, 'utf8', 'hex');
  encrypted += cipher.final('hex');
  
  const authTag = cipher.getAuthTag().toString('hex');
  return {
    iv: iv.toString('hex'),
    authTag,
    encryptedData: encrypted
  };
}

TLS

Purpose

To encrypt network communication, protecting data in transit from inspection.

Rules

  • Enforce TLS version 1.3 or TLS version 1.2 with secure cipher configurations.
  • Require HTTPS connections and disable outdated SSL protocols.

Examples

Nginx Secure SSL/TLS Server Setup (nginx-tls.conf)

server {
    listen 443 ssl http2;
    server_name api.example.com;

    ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';

    # Enable HTTP Strict Transport Security
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
}

Certificate Management

Purpose

To provision and renew TLS certificates dynamically, preventing outages.

Rules

  • Automate renewal operations for Let's Encrypt certificates before they expire.
  • Monitor certificates continuously to flag expiration risks early.

Workflow

  1. Cert-manager routes HTTP-01 or DNS-01 challenges.
  2. The ACME authority validates ownership.
  3. Cert-manager stores the TLS certificate in a secure namespace.
  4. Auto-renewal checks run 30 days before expiration.

Dependency Security

Purpose

To identify, track, and remediate vulnerabilities in third-party libraries.

Rules

  • Enforce automated dependency scanning on every pipeline run.
  • Pin library versions to specific targets instead of using floating ranges.

Workflow

flowchart TD
    A["Trigger CI Pipeline Code Change"] --> B["Run npm audit / pip-audit checks"]
    B --> C["Verify dependencies against Snyk database"]
    C --> D{Vulnerabilities Found?}
    D -- Yes --> E{"Critical/High severity?"}
    E -- Yes --> F["Fail Build stage & notify team"]
    E -- No --> G["Flag warning alerts and complete pipeline"]
    D -- No --> H["Complete pipeline successfully"]

Software Supply Chain Security

Purpose

To protect and verify software dependencies and build steps.

Rules

  • Verify third-party library integrity hashes during install phases.
  • Require cryptographic signatures on all container images.

Examples

Dependency Hash Pin Check (requirements.txt)

pyjwt[crypto]==2.8.0 --hash=sha256:568853b0e4544d6db3857502c77d9c6c2e3532c525f05352c803ff255b0b14c3

SBOM

Purpose

To maintain an inventory of software dependencies to trace vulnerability exposure.

Rules

  • Generate Software Bill of Materials (SBOM) manifests automatically on production releases.
  • Audit SBOM files against vulnerability feeds to locate risks.

Examples

GitHub Actions Syft SBOM Export Workflow (sbom.yml)

name: Generate SBOM
on:
  release:
    types: [published]
jobs:
  sbom:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
      - name: Build SBOM using Syft
        uses: anchore/sbom-action@v0
        with:
          image: "ghcr.io/org/app:${{ github.sha }}"
          format: "spdx-json"
          output-file: "sbom.spdx.json"

SAST

Purpose

To scan codebases for security vulnerabilities during development.

Rules

  • Enforce Static Application Security Testing (SAST) checks on pull requests.
  • Block merging if new code contains high-severity vulnerabilities.

Examples

Semgrep SAST Scanning Stage Configuration (semgrep.yml)

name: Semgrep SAST Scan
on: [pull_request]
jobs:
  semgrep:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
      - name: Run Semgrep scan
        run: |
          docker run --rm -v "${{ github.workspace }}:/src" returntocorp/semgrep \
            semgrep ci --config=p/security-audit --config=p/owasp-top-10

DAST

Purpose

To identify application vulnerabilities dynamically by scanning running services.

Rules

  • Run Dynamic Application Security Testing (DAST) scans in staging environments.
  • Protect staging databases from destructive scan payloads.

Workflow

  1. Deploy the application to the staging cluster.
  2. Trigger the DAST crawler (e.g., OWASP ZAP) against staging endpoints.
  3. Send security payloads to test input parameters and error configurations.
  4. Record target responses and identify vulnerabilities.
  5. Tear down target container resources.

Container Security

Purpose

To isolate application workloads, minimizing host system exposure.

Rules

  • Run containers using non-root user profiles.
  • Configure filesystems as read-only; use temporary volumes for writable paths.

Examples

Secure Dockerfile Base Directives (Dockerfile)

FROM alpine:3.19.1

# Configure non-root system group and user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup

WORKDIR /home/appuser/app

COPY --chown=appuser:appgroup index.js ./

USER appuser

EXPOSE 8080

ENTRYPOINT ["node", "index.js"]

Kubernetes Security

Purpose

To secure cluster components, network traffic, and access credentials.

Rules

  • Restrict pod capabilities using strict Pod Security Standard configurations.
  • Enforce namespace network isolation using NetworkPolicies.

Examples

Kubernetes Pod Security Context Options (security-context.yaml)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: secured-api
spec:
  template:
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 10001
        runAsGroup: 10001
        fsGroup: 10001
      containers:
      - name: application
        image: app:v1.0
        securityContext:
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: true
          capabilities:
            drop:
              - ALL

Cloud Security

Purpose

To secure cloud resource access and configurations.

Rules

  • Enable detailed cloud trail audit logging across all systems.
  • Restrict resources using resource-based and identity access policies.

Workflow

flowchart TD
    A["Ingest API request at WAF Gateway"] --> B["Validate IAM User Identity and Signature"]
    B --> C["Verify IP matches VPC Network access boundaries"]
    C --> D["Enforce KMS Encrypted Data access rules"]

IAM

Purpose

To manage cloud credentials, ensuring users have only necessary permissions.

Rules

  • Enforce the Principle of Least Privilege on all access policies.
  • Do not use administrative access keys for regular application operations.

Examples

AWS IAM Policy: Read-Only S3 Access (iam-s3.json)

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadOnlyAppAssets",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject"
      ],
      "Resource": "arn:aws:s3:::app-public-assets/*"
    }
  ]
}

Network Security

Purpose

To restrict network traffic flows to minimum necessary pathways.

Rules

  • Keep databases and cache servers isolated inside private, non-routable subnets.
  • Restrict administrative ingress ports using private subnets or VPN gateways.

Examples

AWS Security Group Configuration (security-groups.tf)

resource "aws_security_group" "db_access" {
  name        = "db-access-control"
  description = "Restrict access to database nodes"
  vpc_id      = var.vpc_id

  ingress {
    description     = "Allow database queries from application tasks only"
    from_port       = 5432
    to_port         = 5432
    protocol        = "tcp"
    security_groups = [var.app_security_group_id]
  }

  egress {
    from_port        = 0
    to_port          = 0
    protocol         = "-1"
    cidr_blocks      = ["0.0.0.0/0"]
  }
}

WAF

Purpose

To protect public endpoints by filtering malicious application traffic.

Rules

  • Enforce standard WAF rule groups (e.g., OWASP core rule sets) on all public-facing routes.
  • Block requests with suspicious headers or payload anomalies automatically.

Examples

AWS WAF IP Rate-Limiting Policy (waf.tf)

resource "aws_wafv2_web_acl" "waf_limits" {
  name        = "waf-limits-policy"
  scope       = "REGIONAL"
  description = "Blocks high frequency request IPs"

  default_action {
    allow {}
  }

  rule {
    name     = "IPRateLimit"
    priority = 1
    action {
      block {}
    }
    statement {
      rate_based_statement {
        limit              = 1000
        aggregate_key_type = "IP"
      }
    }
    visibility_config {
      cloudwatch_metrics_enabled = true
      metric_name                = "IPRateLimitMetric"
      sampled_requests_enabled   = true
    }
  }

  visibility_config {
    cloudwatch_metrics_enabled = true
    metric_name                = "GlobalWAFACL"
    sampled_requests_enabled   = true
  }
}

Rate Limiting

Purpose

To protect APIs from abuse and denial-of-service attempts.

Rules

  • Configure rate-limiting parameters on all public API endpoints.
  • Return HTTP 429 Too Many Requests status codes to blocked clients.

Examples

Express.js Rate Limiter Implementation (rate-limit.js)

const rateLimit = require('express-rate-limit');

const apiRateLimiter = rateLimit({
  windowMs: 15 * 60 * 1000, # 15 Minutes
  max: 100,                  # Limit each IP to 100 requests per window
  standardHeaders: true,     # Return rate limit info in headers
  legacyHeaders: false,
  message: {
    error: "Too many requests from this IP. Please try again later."
  }
});

module.exports = apiRateLimiter;

DDoS Protection

Purpose

To keep applications online during high-volume traffic surges.

Rules

  • Route traffic through CDN networks with integrated DDoS protection (e.g., Cloudflare, AWS Shield).
  • Enable auto-scaling policies to handle traffic spikes.

Workflow

  1. Direct public DNS queries to the DDoS protection provider.
  2. The provider filters traffic to drop malicious network packets.
  3. The provider forwards clean request streams to application load balancers.
  4. Scale backend instances automatically to handle legitimate traffic surges.

Logging

Purpose

To capture security events, auth failures, and access anomalies for audits.

Rules

  • Do not write sensitive data (passwords, tokens, credentials) to logs.
  • Write security log entries in structured JSON formats.

Examples

Node.js Security Event Logger (security-logger.js)

const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  defaultMeta: { service: 'auth-service' },
  transports: [
    new winston.transports.Console()
  ]
});

function logSecurityEvent(eventType, userId, clientIp, status) {
  logger.info({
    timestamp: new Date().toISOString(),
    event: eventType,
    userId,
    ip: clientIp,
    status
  });
}

module.exports = { logSecurityEvent };

Security Monitoring

Purpose

To analyze event logs in real-time, identifying indicators of compromise.

Rules

  • Consolidate log files into centralized SIEM platforms.
  • Monitor auth systems for brute-force patterns.

Workflow

  1. Export structured JSON logs to central search indexes (e.g., Loki).
  2. Query logs for security event triggers.
  3. Alert security teams if indicators of compromise are identified.
  4. Escalate warnings if anomaly patterns continue.

Incident Response

Purpose

To contain, investigate, and remediate security incidents.

Rules

  • Revoke compromised access tokens and secrets immediately.
  • Document incident timelines and actions taken for post-incident audits.

Workflow

flowchart TD
    A["Alert Triggers: Compromise Located"] --> B["Contain: Revoke tokens & isolate systems"]
    B --> C["Eradicate: Fix vulnerability / remove threat"]
    C --> D["Recover: Restore systems and verify metrics"]
    D --> E["Post-Incident: Review and update security controls"]

Examples

SEV-1 Incident Remediation Actions Checklist (incident-actions.md)

# SEV-1 Incident Remediation checklist

- [ ] Identify source and blast radius of compromise.
- [ ] Revoke compromised credentials and rotate keys.
- [ ] Apply network blocks to offending IP addresses.
- [ ] Restore affected systems from verified backups.
- [ ] Conduct post-mortem review and update security controls.

Vulnerability Management

Purpose

To track, evaluate, and resolve system vulnerabilities systematically.

Rules

  • Retain detailed lists of all identified vulnerabilities.
  • Set remediation deadlines based on CVSS severity scores.

Workflow

  1. Identify vulnerabilities using automated scans (SAST, DAST).
  2. Classify risks based on CVSS scores.
  3. Assign remediation tasks to development teams.
  4. Validate fixes using security regression tests.
  5. Update vulnerability inventory files.

Security Reviews

Purpose

To identify code design flaws before releasing changes.

Rules

  • Conduct threat modeling reviews for all major architecture changes.
  • Review configuration updates and changes to dependencies.

Best Practices

  • Use checklists (e.g., OWASP Top 10) to guide code reviews.
  • Focus code audits on trust boundaries and input handling.

AI Security

Purpose

To secure Large Language Model (LLM) interfaces, RAG architectures, and autonomous AI agents.

Rules

  • Validate and sanitize all inputs before routing them to LLM endpoints.
  • Enforce strict permission bounds on autonomous AI agents.

Workflow

flowchart TD
    A["Raw User Input Ingested"] --> B["Scan Input for Prompt Injections"]
    B --> C{Safe Input?}
    C -- No --> D["Reject Input / Return Error"]
    C -- Yes --> E["Query Vector Store (RAG) with User Context"]
    E --> F["Enforce User ACL Boundaries"]
    F --> G["Execute LLM Action in Sandboxed Environment"]

Prompt Injection

Purpose

To identify and block inputs designed to manipulate LLM instructions.

Rules

  • Treat LLM outputs as untrusted; validate and escape outputs before displaying them to users.
  • Use guardrail layers to validate prompt boundaries.

Examples

Python Guardrail Validation Script (guardrail.py)

import re

BLOCKED_PATTERNS = [
    r"(?i)ignore\s+(?:previous|all)?\s+instructions",
    r"(?i)system\s+prompt\s+disclosure",
    r"(?i)you\s+are\s+now\s+an\s+admin"
]

def check_input_for_injection(user_input: str) -> bool:
    for pattern in BLOCKED_PATTERNS:
        if re.search(pattern, user_input):
            return False
    return True

def process_prompt(user_input: str):
    if not check_input_for_injection(user_input):
        raise ValueError("Security violation: Prompt injection attempt detected")
    return user_input

RAG Security

Purpose

To protect retrieved context, preventing data leaks across tenants in RAG workflows.

Rules

  • Restrict vector database queries to match user access permission levels.
  • Do not store sensitive, unencrypted personal data in vector indexes.

Examples

Node.js RAG Query Access Check (rag-check.js)

const { Pinecone } = require('@pinecone-database/pinecone');
const pc = new Pinecone();

async function queryTenantEmbeddings(vector, userContext) {
  const index = pc.Index('documents');
  
  # Filter queries by tenant ID to prevent cross-tenant data leaks
  const queryResponse = await index.query({
    vector: vector,
    topK: 5,
    filter: {
      tenantId: { "$eq": userContext.tenantId }
    },
    includeMetadata: true
  });
  
  return queryResponse.matches;
}

Agent Security

Purpose

To run autonomous AI agents securely, limiting host and system exposure.

Rules

  • Restrict agent processes to isolated sandbox environments with limited system calls.
  • Enforce manual approval steps for destructive actions (e.g., payments, database deletes).

Examples

Secure Agent Code Execution Sandbox (agent_sandbox.py)

import docker

client = docker.from_env()

def execute_agent_code(generated_code: str):
    # Execute untrusted agent code in a sandboxed container with restricted resources
    container = client.containers.run(
        image="python:3.11-slim",
        command=f"python -c '{generated_code}'",
        network_disabled=True,
        mem_limit="128m",
        nano_cpus=500000000, # 0.5 CPU
        read_only=True,
        user="1000:1000",
        detach=True
    )
    
    try:
        result = container.wait(timeout=10) # 10s Execution limit
        output = container.logs()
        return output.decode('utf-8')
    finally:
        container.remove(force=True)

Common Mistakes

Purpose

To document common security engineering mistakes, helping teams avoid configuration issues.

Rules

  • Check configurations for insecure defaults before release.
  • Enforce strict parameter checking on all inputs.

Common Mistakes & Remediation

  • Mistake: Committing secrets to code repositories.
    • Remediation: Remove keys and load them using secure key vaults.
  • Mistake: Running containers as root.
    • Remediation: Enforce non-root user execution in Dockerfiles.
  • Mistake: Trusting user context flags from client-side cookies.
    • Remediation: Validate authorization tokens on server nodes for every request.

Anti Patterns

Purpose

To identify and remediate design patterns that degrade application and host security.

Rules

  • Avoid sharing administrative keys across multiple application domains.
  • Do not bypass security checks in development or testing pipelines.

Workflow

flowchart TD
    A["Identify Anti-Patterns"] --> B["Locate shared administrative keys"]
    B --> C["Isolate credentials by application domain"]
    C --> D["Locate hardcoded passwords in templates"]
    D --> E["Configure dynamic injection from key vaults"]

Engineering Checklist

Purpose

To provide a final validation checklist, verifying security controls are complete before release.

Checklist

  • Threat Modeling: STRIDE threat models exist for all major feature changes.
  • Input Validation: Input parameters are validated against strict type and length schemas.
  • Output Encoding: Variable values are sanitized and encoded based on display contexts.
  • Secrets Security: Credentials are stored in secure key vaults; no secrets exist in git.
  • Auth Security: Multi-factor authentication is active; session cookies configure Secure attributes.
  • Database Access: Database interactions use parameterized queries; access is restricted.
  • Dependency Safety: Automatic scans verify libraries are updated and pass vulnerability checks.
  • Container Context: Containers run as non-root users with read-only root filesystems.
  • Network Controls: Outbound requests are validated; network policies isolate databases.
  • Observability: Structured JSON logs are active; access anomalies trigger alerts.

Self Review Engine

Purpose

To define a self-criticism engine that audits security configurations before returning code.

Rules

  • Analyze all generated templates and code snippets against the review workflow prior to delivery.
  • Resolve any security vulnerabilities identified during review.

Workflow

flowchart TD
    Start["Draft Code/Config Completed"] --> Q1{"Is raw user input SQL concatenated?"}
    Q1 -- Yes --> R1["Refactor using parameterized variables / ORMs"] --> Q2
    Q1 -- No --> Q2{"Are container permissions elevated (root)?"}
    Q2 -- Yes --> R2["Inject USER directives and securityContexts"] --> Q3
    Q2 -- No --> Q3{"Are plaintext credentials included?"}
    Q3 -- Yes --> R3["Configure dynamic fetch from vault variables"] --> Q4
    Q3 -- No --> Q4{"Is input validation missing?"}
    Q4 -- Yes --> R4["Add validation schema check layers"] --> Q5
    Q4 -- No --> Q5{"Is output encoding missing?"}
    Q5 -- Yes --> R5["Inject context-specific encoding helper checks"] --> End
    Q5 -- No --> End["Deliver Secure Production-Grade Code"]

References

Purpose

To list core specifications, standards, and guidelines governing cybersecurity.

Recommended References

  • OWASP Application Security Verification Standard (ASVS): Structural framework to audit applications.
  • NIST Special Publication 800-53: Detailed list of security and privacy controls.
  • OWASP Top 10 Web Application Security Risks: Essential security guidelines for developers.
  • OWASP API Security Top 10: Security guidelines for REST and GraphQL APIs.
  • OWASP LLM Security Top 10: Critical security vulnerabilities targeting AI systems.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.