Skip to content
StackPractices

Tag: security

Browse 106 practical software engineering resources tagged with "security". Discover code recipes, design patterns, documentation templates, and in-depth guides to help you build, deploy, and maintain production-ready solutions involving security.

API Rate Limiting

Protect APIs from abuse and ensure fair resource usage with token bucket, sliding window, and leaky bucket rate limiting.

WebSocket Authentication and Security Patterns

How to authenticate WebSocket connections, implement token validation, and handle authorization for real-time messaging in production

Secure API Key Authentication for Services and Clients

How to generate, distribute, validate, and rotate API keys for machine-to-machine authentication using HMAC signatures, scopes, and rate-limited key policies.

Hash Passwords with Argon2

How to hash and verify passwords securely with Argon2id, the winner of the Password Hashing Competition, with correct parameter tuning and migration strategies from bcrypt.

Implement ABAC

How to implement attribute-based access control with policy engines, live context evaluation, and fine-grained authorization decisions across Python, Node.js, and Java.

Implement RBAC

How to implement role-based access control with hierarchical roles, permission grants, and middleware enforcement across Python, Node.js, and Java.

Implement SSO with SAML

How to implement SAML 2.0 single sign-on as a Service Provider with XML signature verification, IdP metadata handling, and secure session management in Python, Node.js, and Java.

JWT Authentication

How to generate, validate, and refresh JSON Web Tokens for stateless API authentication.

Implement Passwordless Login with Magic Links

How to build secure passwordless authentication using time-limited magic links sent via email, with token generation, validation, and replay attack prevention.

Node.js JWT Authentication: Verify and Refresh Tokens

Implement JWT authentication in Node.js with access and refresh tokens

Node.js OAuth2 GitHub Login with Express

Implement GitHub OAuth2 login flow in Node.js with Express and Passport

OAuth 2.0 Login

How to implement OAuth 2.0 authentication with Google, GitHub, and other providers.

Password Hashing

How to securely hash and verify passwords using modern algorithms across Python, JavaScript, and Java.

Implement Secure Session Management

How to create, validate, and expire user sessions securely across web applications using cookies, tokens, and server-side storage.

Two-Factor Authentication (2FA / TOTP)

How to implement time-based one-time password (TOTP) two-factor authentication for secure user login.

Rate Limiting with Redis Token Bucket Algorithm

Implement a distributed token bucket rate limiter using Redis atomic operations for API throttling across multiple server instances

Execute Raw SQL

How to execute raw SQL queries safely with parameterized statements.

Container Image Security Scanning with Trivy

Scan Docker images for vulnerabilities, misconfigurations, and secrets using Trivy, integrate scanning into CI/CD pipelines, and enforce image policies before deployment to production

Scan Docker Images for CVEs with Trivy and Grype

Scan Docker images for vulnerabilities before deployment using Trivy and Grype. Covers CI integration, severity filtering, SBOM, and remediation.

Slim Production Images with Multi-Stage Docker Builds

How to build minimal production Docker images using multi-stage builds with distroless base images, covering Go, Node.js, Python, and Java examples with image size reduction.

Docker Network Isolation and Inter-Container Security

Secure inter-container communication with custom Docker networks, network segmentation, and access control policies.

Docker Secrets Management Without Hardcoding Credentials

Inject secrets into containers using Docker secrets, env files, and external secret managers without hardcoding them in images.

Mount Configs and Secrets into Kubernetes Pods

How to mount ConfigMaps and Secrets into Kubernetes pods using env vars, volumes, projected volumes, and secret management with external secrets.

Setup SSL Certificates with Let's Encrypt

How to obtain, install, and auto-renew SSL certificates using Certbot with Nginx, Apache, and standalone modes for HTTPS-enabled deployments.

Configure Firewall Rules with iptables

Set up basic firewall rules using iptables in Bash to filter traffic, block ports, and protect Linux servers.

SSH Key Management

Generate, rotate, and distribute SSH keys securely with Bash scripts for team and server access.

Node.js File Upload Validation: Type, Size, and Content

Validate file uploads in Node.js with multer for type, size, and content

Safely Extract Zip Files with Python

How to extract and validate zip archives securely using Python zipfile and shutil.

Field-Level Auth with Custom GraphQL Schema Directives

Implement field-level authorization in GraphQL using custom schema directives that check user roles and permissions per field

Validate and Sanitize GraphQL Input Types Server-Side

Implement centralized input validation in GraphQL using custom validation functions, Zod schemas, and input type transforms

Secure APIs with HTTP Security Headers

How to configure essential security headers like HSTS, CSP, and X-Frame-Options to protect APIs and web applications from common attacks.

Configure iptables Firewall Rules with Bash

Set up basic firewall rules with iptables and bash scripts

SSH Key Management in Bash

Generate, rotate, and distribute SSH keys with bash scripts

Container Security Scanning

Scan container images for vulnerabilities, misconfigurations, and secrets with Trivy, Clair, and Snyk before deploying to production.

Protect Web Forms Against CSRF Attacks

How to prevent Cross-Site Request Forgery attacks using synchronizer tokens, SameSite cookies, and double-submit cookie patterns.

Data Privacy and GDPR Compliance

Implement data privacy controls, consent management, data anonymization, and GDPR-compliant data handling in web applications.

Schema-Based Data Validation with Zod in TypeScript

Validate and sanitize incoming data using Zod schemas with TypeScript inference, custom refinements, and error formatting for reliable API and form validation

Implement Encryption at Rest for Databases and File Storage

How to encrypt sensitive data before storing it in databases, object storage, and backups using AES-256-GCM, envelope encryption, and key management services.

Escape HTML Entities

How to escape HTML entities to prevent XSS attacks in Python, Java, and JavaScript.

HMAC Request Signing

Secure API requests with HMAC-SHA256 signatures to ensure integrity and authenticity.

Detect Bugs in Java with SpotBugs Static Analysis

How to configure SpotBugs for Maven and Gradle, interpret bug patterns, suppress false positives, and integrate with CI/CD pipelines.

Enforce Security Rules in Node.js with

How to configure eslint-plugin-security to detect insecure patterns in Node.js code, handle false positives, and integrate with CI/CD pipelines.

Implement OAuth 2.0 PKCE for Single-Page Applications

How to implement the OAuth 2.0 PKCE flow in single-page applications to securely authenticate users without exposing client secrets

Password Hashing in Production

Securely hash and verify passwords using bcrypt, scrypt, and Argon2 with what works.

Find Security Issues in Python Code with Bandit

How to use Bandit to scan Python code for common security vulnerabilities, configure ignore lists, integrate with CI/CD, and interpret results.

Encrypt and Decrypt Data with AES-GCM in Python

Encrypt sensitive data using AES-GCM with the cryptography library. Covers key derivation, nonce generation, authenticated encryption, and file encryption.

Secure JWT Refresh Token Rotation with Python

Implement secure JWT access and refresh token rotation in Python with blacklist, reuse detection, and automatic access token renewal for stateless auth

Strict Type Checking in Python with mypy

How to configure mypy strict mode for Python projects, handle common type errors, use Protocol and TypeGuard, and integrate with CI/CD.

Scan Python Packages for Known CVEs with pip-audit

How to use pip-audit to scan Python dependencies for known vulnerabilities, configure ignore lists, integrate with CI/CD, and remediate findings.

Manage Application Secrets with HashiCorp Vault and Python

Store, retrieve, and rotate application secrets securely using HashiCorp Vault with Python hvac client, dynamic secrets, and automatic lease renewal

Prevent SQL Injection with SQLAlchemy Parameterized Queries

Protect Python applications from SQL injection using SQLAlchemy parameterized queries, ORM models, input validation, and query inspection to ensure safe database access

Implement Rate Limiting for APIs and Web Applications

How to protect APIs and web endpoints from abuse using token bucket, sliding window, and fixed window rate limiting strategies with Redis and in-memory implementations.

Implement Request Signing with HMAC

Secure API requests with HMAC signatures and AWS Signature v4 authentication for tamper-proof message integrity.

Sanitize User Input

How to sanitize and validate user input in Python, Java, and JavaScript to prevent injection attacks.

Security Headers

Harden web applications with HTTP security headers: CSP, HSTS, X-Frame-Options, and a thorough security header checklist.

Prevent SQL Injection Attacks

How to write parameterized queries and use ORMs to eliminate SQL injection vulnerabilities across Python, JavaScript, and Java.

Strict TypeScript ESLint Configuration for Production

How to configure typescript-eslint with strict rules for production TypeScript projects, handle type-aware linting, and integrate with CI/CD.

Live Database Credentials with HashiCorp Vault

How to use HashiCorp Vault to generate short-lived database credentials, eliminating hardcoded passwords and reducing secret sprawl

Prevent Cross-Site Scripting (XSS)

How to sanitize user input, escape output, and use Content Security Policy to prevent XSS attacks in web applications.

Voucher Pattern

Validate claims and delegate access using signed vouchers without exposing sensitive data. A security pattern for token-based authorization between services.

Gatekeeper Pattern

Place a validation and security boundary at the edge of a system to inspect, sanitize, and authenticate all incoming requests before they reach internal services.

Data Governance Policy Template

A template for data classification, retention, access control, privacy, and compliance policies covering GDPR, CCPA, and SOC 2 requirements.

Patch Management Template

A template for scheduling, testing, and deploying security patches across environments.

SSL Certificate Management Template

A template for tracking TLS/SSL certificate inventory, renewals, deployments, and expiration risks across domains and services.

SSL Certificate Renewal Template

A template for tracking SSL certificate expiration and renewal workflows.

Third-Party Vendor Assessment Template

A structured template for evaluating the security, compliance, and operational posture of third-party vendors before onboarding or renewal.

GraphQL Schema Review Checklist

Checklist for reviewing GraphQL schemas: naming conventions, type design, pagination, error handling, security, performance, deprecation, and federation readiness with code examples and validation rules.

Access Control Policy Template

A template for defining authentication, authorization, RBAC, ABAC, MFA, password policies, session management, and access review procedures.

API Security Review Template

A checklist template for reviewing API authentication, rate limiting, and OWASP compliance.

Data Classification Template

A template for classifying data as public, internal, confidential, or restricted with handling rules.

Encryption Key Rotation Runbook

A runbook for encryption key rotation covering key types, rotation schedules, zero-downtime procedures, dual-key migration, verification, and rollback.

Incident Response Plan Template

A template for incident response covering severity classification, roles, detection, containment, eradication, recovery, and post-incident review procedures.

Incident Response Playbook Template

A step-by-step playbook template for handling security incidents.

OWASP Top 10 Remediation Checklist

Checklist for tracking OWASP Top 10 vulnerability remediation per application: risk assessment, fix priority, code-level remediation steps, verification testing, and compliance reporting with examples for each OWASP category.

Penetration Test Remediation Template

A template for tracking security findings, assigning remediation owners, and validating fixes after penetration tests.

Penetration Test Report Template

A template for penetration test reports covering scope, methodology, findings, severity ratings, evidence, and remediation recommendations.

Secrets Rotation Runbook

Runbook for rotating secrets without downtime: secret inventory, rotation schedule, zero-downtime rotation strategies, dual-key periods, automated rotation with AWS Secrets Manager and HashiCorp Vault, and emergency rotation procedures.

Secrets Rotation Template

A template for scheduling and tracking the rotation of API keys, tokens, and certificates.

Security Audit Checklist

A checklist for security audits covering network security, application security, data protection, access control, monitoring, incident response, and compliance.

Security Audit Checklist

A thorough checklist for conducting security audits of applications and infrastructure.

Security Incident Response Template

A template for security incident response covering detection, classification, containment, eradication, recovery, communication, and post-incident review.

Security Review Checklist for PRs

Checklist for security checks during pull request review: input validation, authentication, authorization, secrets, dependencies, injection, XSS, CSRF, logging, and automated tooling integration with code examples for secure patterns.

Vendor Risk Assessment Template

A template for evaluating third-party vendor security and operational risks.

Vulnerability Management Process Template

A template for vulnerability management covering discovery, triage, prioritization, remediation SLAs, verification, and reporting procedures.

Vulnerability Management Template

A repeatable template for tracking vulnerabilities, assigning remediation owners, defining patching timelines, and reporting security risks to stakeholders.

Serverless Security Checklist

Security hardening checklist for serverless functions: IAM least privilege, secret management, input validation, dependency scanning, network isolation, logging, and compliance with code examples for AWS Lambda, Azure, and GCP.

Third-Party Dependency Audit Template

A template for auditing third-party dependencies: license compliance, security vulnerabilities, maintenance health, and supply chain risk.

Penetration Test Report Template

A penetration test report template for documenting findings, risk ratings, reproduction steps, and remediation guidance for security assessments.

Complete Guide to GraphQL Security

Secure GraphQL APIs against introspection leaks, query depth attacks, cost-based DoS, batching abuse, and injection. Covers auth patterns, rate limiting, and production hardening.

API Gateway Design: Resilience, Routing, and Security

A practical guide to designing API gateways: routing patterns, rate limiting, authentication, circuit breakers, and observability for resilient APIs.

CI/CD Security: Harden Your Pipelines and Prevent Supply

A practical guide to securing CI/CD pipelines: secrets management, least-privilege runners, artifact signing, dependency scanning, and defending against supply chain attacks.

API Security Checklist — Authentication to Encryption

A thorough security checklist for APIs: authentication, authorization, input validation, rate limiting, encryption, logging, and deployment hardening.

Complete Guide to API Security

Secure your APIs end-to-end. Covers rate limiting, authentication, input validation, CORS, SQL injection prevention, API gateway patterns, request size limits, pagination security, mass assignment, versioning, audit logging, and API security testing with practical code examples.

Complete Guide to Authentication Patterns

Implement authentication in production. Covers JWT, OAuth2, session-based auth, passkeys, MFA, refresh tokens, token rotation, RBAC, ABAC, SSO with SAML and OpenID Connect, and secure logout patterns with practical code examples.

Content Security Policy: CSP Headers, Nonces, Hashes

Master Content Security Policy: CSP directives, nonces, hashes, reporting, strict-dynamic, nonce-based CSP, hash-based CSP, and production deployment patterns for web security.

CORS Security: Origins, Headers, Preflight, Credentials

Master CORS security: same-origin policy, CORS headers, preflight requests, credential handling, common misconfigurations, and production security patterns for web APIs.

Encryption at Rest: AES-256, KMS, Envelope Encryption

Master encryption at rest: AES-256-GCM, key management services, envelope encryption, key rotation, database encryption, field-level encryption, and production security patterns.

OAuth2 and OIDC: Authorization Code, PKCE, Token Validation

Master OAuth2 and OpenID Connect for production: authorization code flow with PKCE, token validation, refresh tokens, scopes, JWT verification, and security best practices.

Complete Guide to OWASP Top 10 2025

Mitigate each OWASP Top 10 2025 risk with practical code examples. Covers broken access control, cryptographic failures, injection, insecure design, security misconfiguration, vulnerable components, auth failures, software integrity, logging failures, and SSRF.

Complete Guide to Secrets Management

Manage application secrets securely in production. Covers HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, GCP Secret Manager, Doppler, secret rotation, environment variables, zero-downtime rotation, and secrets in CI/CD pipelines with practical code examples.

Complete Guide to Supply Chain Security

Secure your software supply chain end-to-end. Covers SBOM generation, dependency scanning, Sigstore, SLSA framework, provenance attestation, package registries, typosquatting, dependency confusion, and CI/CD pipeline hardening with practical code examples.

Complete Guide to Web Security Headers

Implement CSP, HSTS, X-Frame-Options, and secure headers. Covers content security policy, CORS, referrer policy, permissions policy, and testing with security scanners.

Security Best Practices Guide

A thorough guide to application security: authentication, authorization, input validation, secrets management, and common vulnerability prevention.

Web Application Security (OWASP Top 10)

A developer-focused guide to the OWASP Top 10: injection, broken access control, XSS, insecure design, and how to prevent each vulnerability with code examples.

Webhook Security — Delivery, Verification, and Protection

A practical guide to securing webhooks: signature verification, replay attack prevention, payload encryption, and endpoint hardening for reliable delivery.

Complete Guide to AWS Lambda in Production

Run AWS Lambda in production with confidence. Covers cold start optimization, layers, deployment patterns, observability with X-Ray, security hardening, connection pooling, and cost tuning for production workloads.