security-best-practices

Applies secure coding patterns for input validation, authentication, and web vulnerabilities in Python.

Updated Apr 15, 2026
One-click install
npx skills add https://github.com/shoshoavi/agentic_worflows --skill security-best-practices-shoshoavi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: security-best-practices
Source: https://github.com/shoshoavi/agentic_worflows/tree/main/cursor/skills/security-best-practices
Command: npx skills add https://github.com/shoshoavi/agentic_worflows --skill security-best-practices-shoshoavi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing secure code requires constant vigilance against common vulnerabilities like SQL injection, XSS, CSRF, and leaked secrets. This Skill provides a consolidated set of defensive coding patterns so you avoid shipping exploitable authentication, database, and API code. ## Core Features & Use Cases - Input Validation & Injection Prevention: Pydantic-based request validation, path traversal guards, and parameterized SQL queries with SQLAlchemy. - Authentication & Secrets Management: bcrypt password hashing, JWT token creation/verification, rate limiting, and environment-based secret handling with log filtering. - Web Security Hardening: XSS escaping with bleach sanitization, CSRF token verification, security headers middleware, HTTPS enforcement, and audit logging. - Use Case: When building a FastAPI endpoint that accepts user registration, apply the validation models, password hashing, rate limiting, and security headers patterns to ship a hardened endpoint. ## Quick Start Review my FastAPI user registration endpoint and apply the security best practices patterns to fix any vulnerabilities.

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 Python?▼

Prevent SQL injection by always using parameterized queries instead of string formatting with user input. Use placeholders like $1 with raw connections, or SQLAlchemy ORM filters and text() with bound parameters, which escape values automatically.

How to hash passwords securely in Python?▼

Hash passwords using passlib's CryptContext with the bcrypt scheme, never storing plaintext. Enforce a minimum length of 12 characters before hashing, and verify logins with the context's verify method against the stored hash.

How do I validate user input with Pydantic?▼

Validate user input by defining Pydantic models with Field constraints like min_length, max_length, pattern, and ge/le bounds. Add custom field_validator methods for business rules such as rejecting reserved usernames.

Does FastAPI support CSRF protection?▼

FastAPI supports CSRF protection through custom dependencies that compare a session-stored token against an X-CSRF-Token header on state-changing requests. Generate tokens with secrets.token_urlsafe and reject mismatches with a 403 error.

Why should secrets never be hardcoded in source code?▼

Hardcoded secrets leak through version control history, logs, and shared code, enabling credential theft. Load API keys and database URLs from environment variables or pydantic-settings with a .env file, and filter secret patterns from log output.

What security headers should a web API return?▼

A web API should return X-Frame-Options DENY, X-Content-Type-Options nosniff, Strict-Transport-Security with a long max-age, and a restrictive Content-Security-Policy. Implement these via middleware that sets headers on every response.