security-best-practices

Implement HTTPS, input validation, CSRF protection, and JWT authentication for web applications.

2|Updated Mar 7, 2025
One-click install
npx skills add https://github.com/AbdelrhmanUZaki/KnowledgeNuggets --skill security-best-practices-abdelrhmanuzaki
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: security-best-practices
Source: https://github.com/AbdelrhmanUZaki/KnowledgeNuggets/tree/main/2-setup/shared/gemini/config/skills/security-best-practices
Command: npx skills add https://github.com/AbdelrhmanUZaki/KnowledgeNuggets --skill security-best-practices-abdelrhmanuzaki

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Web applications face constant threats from common vulnerabilities like SQL Injection, XSS, CSRF, and DDoS attacks. This Skill provides concrete, code-level guidance to harden Express.js APIs and infrastructure against the OWASP Top 10 without requiring deep security expertise. ## Core Features & Use Cases - Security Headers & HTTPS Enforcement: Configure Helmet middleware, Content Security Policy, HSTS, and HTTPS redirects for production environments. - Vulnerability Prevention: Apply Joi input validation, parameterized queries, DOMPurify output encoding, CSRF tokens, and rate limiting to block injection and abuse. - Secrets & Authentication Management: Manage environment variables and Kubernetes Secrets, plus implement JWT access tokens with refresh token rotation. - Use Case: When launching a public API, use this Skill to audit your Express.js app against the OWASP Top 10 checklist and add rate limiting, CSRF protection, and secure authentication before going live. ## Quick Start Ask the AI to review your Express.js API for security vulnerabilities and add Helmet headers, rate limiting, and input validation following security best practices.

Frequently Asked Questions about security-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent SQL Injection in Node.js applications?▼

Prevent SQL Injection by using parameterized queries instead of string concatenation, such as db.query('SELECT * FROM users WHERE email = ?', [email]). Combine this with Joi input validation to reject malformed input before it reaches the database.

How to add rate limiting to an Express.js API?▼

Use the express-rate-limit middleware to cap requests per IP, for example 100 requests per 15 minutes on API routes. Apply stricter limits like 5 attempts per 15 minutes on authentication endpoints, with skipSuccessfulRequests enabled for login routes.

What security headers does Helmet set for Express apps?▼

Helmet sets HTTP security headers including Content Security Policy, HSTS with preload, and frame protections. You can customize CSP directives for scripts, styles, images, and connections to allow only trusted sources.

Does this approach work with frameworks other than Express.js?▼

The code examples target Express.js with middleware like helmet, csurf, and express-rate-limit. The underlying principles such as parameterized queries, output encoding, and token rotation apply to any web framework, but implementation details differ.

Why should refresh tokens be rotated on each use?▼

Refresh token rotation invalidates the old token every time a new access token is issued, limiting the damage if a token is stolen. Storing refresh tokens in the database allows server-side revocation and detection of token reuse.

How do I manage API keys and secrets securely?▼

Store secrets in environment variables loaded from .env files that are never committed to version control, or use Kubernetes Secrets for deployed workloads. Always validate that required variables like DATABASE_URL exist at startup and fail fast if missing.