#security
28 snippets tagged with #security
In-Memory Rate Limiter for Express
Token bucket rate limiter middleware for Express with configurable window and max requests per IP.
Best for: API abuse prevention
JWT Refresh Token Rotation
Implement secure token rotation with short-lived access tokens and one-time-use refresh tokens.
Best for: Secure API authentication
Bcrypt Password Hash & Verify
Hash and verify passwords with bcrypt using configurable salt rounds and timing-safe comparison.
Best for: User registration
Node.js Crypto Utility Functions
Common cryptographic operations: hashing, HMAC, encryption, random tokens, and password hashing.
Best for: Secure password storage and verification
Node.js Token Bucket Rate Limiter
Implement an in-memory token bucket rate limiter for controlling API request throughput.
Best for: Protecting APIs from abuse and DDoS
CORS Configuration Middleware
Configure Cross-Origin Resource Sharing with origin allowlists, credentials, and preflight handling.
Best for: API CORS configuration
Secure Cookie and Session Management
Handle HTTP cookies with signing, encryption, and session management using secure defaults.
Best for: Authentication session handling
Webhook Handler with Signature Verification
Process incoming webhooks with HMAC signature verification, replay protection, and idempotency.
Best for: GitHub/Stripe webhook processing
API Key Authentication Middleware
Simple API key validation middleware that checks the X-API-Key header against a set of valid keys.
Best for: Public API authentication
Webhook Signature Verification
Verifies HMAC-SHA256 webhook signatures to ensure payloads are from trusted sources.
Best for: GitHub webhook handlers
Sliding Window Rate Limiter
Implements sliding window rate limiting that distributes limits more evenly than fixed windows.
Best for: API rate limiting
Edge Middleware Rate Limiter
Rate limit API requests at the edge using a sliding window counter with configurable thresholds.
Best for: API abuse prevention
Next.js Middleware for Authentication
Protect routes with Next.js middleware using token verification and role-based redirects.
Best for: Protecting authenticated routes at the edge
API Route Rate Limiting
Add rate limiting to Next.js API routes with sliding window, IP-based limits, and custom responses.
Best for: API abuse prevention
Server-Only Utility Functions
Ensure utility functions only run on the server using the server-only package to prevent client leakage.
Best for: protecting secrets
Rate Limiter for Edge Functions
Implement sliding window rate limiting in Next.js middleware using in-memory or KV store.
Best for: API protection
Content Security Policy Headers
Configure strict CSP and security headers in Next.js for production-grade security.
Best for: production security
Webhook Handler with Signature Verification
Handle incoming webhooks with signature verification and idempotent processing.
Best for: payment webhooks
Row-Level Security Policies
Enforce data access rules at the database level with PostgreSQL Row-Level Security policies.
Best for: Multi-tenant databases
GRANT and REVOKE Permission Management
Manage database permissions with GRANT and REVOKE for roles, schemas, and tables.
Best for: database security
Nginx SSL Setup with Certbot
Bash script to install and configure SSL certificates with Certbot for Nginx with auto-renewal.
Best for: Setting up HTTPS for production websites
Nginx Rate Limiting Configuration
Nginx rate limiting with multiple zones for API and login routes, burst handling, and custom error pages.
Best for: Protecting APIs from abuse and DDoS
Fail2ban Security Configuration
Configure Fail2ban to protect SSH and Nginx from brute force attacks with custom jail rules.
Best for: Protecting SSH from brute force attacks
Spring Security — JWT Authentication
Implement JWT authentication with Spring Security: token generation, validation, and filter chain.
Best for: Securing REST APIs with JWT tokens
AES Encryption and Decryption
Encrypt and decrypt data with AES-GCM in Java: key generation, secure random IV, and Base64 encoding.
Best for: Encrypting sensitive data at rest
Secure Password Hashing
Hash passwords securely with PBKDF2 and verify them — no external libraries required.
Best for: User registration password storage
Spring Security — Role-Based Access Control
Configure RBAC with Spring Security: roles, method security, endpoint permissions, and custom filters.
Best for: Fine-grained API endpoint authorization
Spring Security with JWT Authentication
Configure Spring Security in Kotlin: JWT token generation, validation, role-based access, and security filters.
Best for: JWT-based stateless authentication