1---
2name: cybersecurity-2
3description: Security rules, architecture decisions, and hardening guidelines for building secure systems. Use this skill whenever designing or reviewing a Next.js frontend, FastAPI backend, authentication flow, Docker environment, AI agent, RAG pipeline, admin tool, or any feature that handles user input, secrets, file uploads, external integrations, or sensitive business data. Also use when reviewing pull requests for security, preparing production deployments, or building any system that processes untrusted content. Covers OWASP top 10, container hardening, prompt injection defense, and supply-chain security.
4metadata:
5 source: https://skillmd.com/skills/aibot88/cybersecurity-2
6---
7
8## 10 Core Principles
9
101. Validate everything.
112. Authorize everything.
123. Trust nothing from the client.
134. Trust nothing from the model.
145. Minimize privileges everywhere.
156. Keep secrets out of code and logs.
167. Harden containers and networks by default.
178. Restrict tools, files, and outbound access.
189. Log security-relevant actions.
1910. Design so compromise has limited blast radius.
20
21## When to Use
22
23- Designing or reviewing a Next.js frontend or FastAPI backend
24- Creating authentication or authorization flows
25- Building Dockerfiles or Docker Compose environments
26- Adding file upload, search, scraping, or external integrations
27- Creating admin dashboards or internal tools
28- Building AI chat, agent, RAG, tool-calling, or automation systems
29- Handling user-generated content or third-party content
30- Preparing production deployments
31- Reviewing pull requests for security-sensitive changes
32- Implementing APIs that expose sensitive business data
33
34## Core Security Philosophy
35
36- Security must be designed into the architecture, not added as a final step
37- Every external input is untrusted until validated
38- Every internal component may eventually be compromised — design accordingly
39- Prefer secure defaults, least privilege, narrow permissions, and explicit allowlists
40- Prevention matters, but limiting blast radius after compromise matters equally
41- Simplicity is a security feature — avoid unnecessary complexity and hidden magic
42- Never trust the frontend for security decisions
43- Never trust LLM output as safe, correct, or authorized
44- If a feature is security-sensitive and unclear, choose the more restrictive behavior
45
46## Golden Rules
47
481. **Validate all inputs** at every boundary
492. **Escape or sanitize all outputs** based on rendering context
503. **Authenticate every sensitive action**
514. **Authorize every resource access** — authentication ≠ authorization
525. **Never expose secrets** in code, logs, images, or client bundles
536. **Never execute user-controlled input** in shells, SQL, templates, or interpreters
547. **Never assume internal traffic is trustworthy**
558. **Never mount dangerous host resources** into containers
569. **Never let AI outputs directly perform privileged actions** without validation and authorization
5710. **Every sensitive action must be observable**, auditable, and attributable
58
59## Secure Architecture Rules
60
61- Separate domain logic, application logic, infrastructure, and API layers — sensitive logic must not be scattered across routers or middleware
62- Enforce authentication and authorization separately — being authenticated does not imply permission
63- Perform object-level authorization on every resource access (IDOR prevention)
64- Centralize auth rules — inconsistent enforcement across routes causes privilege escalation
65- Apply least privilege by default to users, service accounts, tools, and background jobs
66- Treat background jobs, workers, cron tasks, and internal endpoints as production attack surfaces
67- Use allowlists instead of blocklists for input validation
68- Validate at the boundary, then work with trusted internal types
69
70## AI & Agent Security Rules
71
72These rules are critical when building any AI-powered feature:
73
74- **Treat all model inputs as untrusted** — user instructions, retrieved documents, web content, OCR, tool outputs can all contain prompt injection
75- **Never let the model decide authorization** — LLMs are not security boundaries and can be manipulated
76- **Separate trust layers explicitly** — system instructions, developer rules, user input, retrieved content, and tool results are NOT equally authoritative
77- **Tell the model that retrieved content is data, not instructions** — hostile text can imitate system guidance
78- **Use strict tool allowlists** — every available tool is part of the attack surface
79- **Validate all tool arguments server-side** before execution — even aligned models can generate dangerous parameters
80- **Require authorization checks outside the model** for sensitive tool calls (file access, email, payments, shell, data export, admin)
81- **Treat model-generated code, SQL, shell commands, URLs as untrusted** — prompt injection and hallucinations produce harmful actions
82- **Sandbox tool execution** with timeouts, memory limits, network restrictions, filesystem isolation
83- **Prevent unrestricted browsing/retrieval** from feeding the model with high-trust privileges — malicious websites contain hidden prompt injection
84- **Never give the model raw secrets or broad credentials** — assume they may appear in logs, outputs, or downstream prompts
85- **Protect memory/context stores** from untrusted writes — persistent prompt injection survives across sessions
86- **Require human approval for high-risk actions** — sending messages, writing files, purchases, production changes
87- **Log every tool call** — validated arguments, acting identity, policy decision, execution result
88- **Use typed output schemas** for planning and tool execution — structure reduces attack opportunities
89- **Model proposes, policy layer decides** — separate reasoning from enforcement
90- **Never let the model self-modify its security rules or tool permissions**
91- **Test for prompt injection explicitly** — "ignore previous instructions," hidden HTML, fake tool responses, poisoned PDFs
92
93## Quick Security Checklist
94
95Before shipping any feature, verify:
96
97- [ ] All external inputs validated with schemas (Pydantic/Zod)
98- [ ] Authentication required for sensitive endpoints
99- [ ] Authorization checked per resource (not just per route)
100- [ ] No secrets in code, config, logs, or Docker images
101- [ ] SQL uses parameterized queries (no string concatenation)
102- [ ] No unsafe shell execution with user input
103- [ ] Error responses do not leak internals
104- [ ] Rate limits and request size limits applied
105- [ ] Containers run as non-root with minimal capabilities
106- [ ] AI tool calls validated and authorized outside the model
107- [ ] Security-relevant events logged with request IDs
108- [ ] Dependencies scanned for known vulnerabilities
109
110## Security Review Decision Tree
111
112```
113Does the feature handle...
114|
115+-- Auth, secrets, uploads, external URLs, HTML rendering, admin actions, AI tool execution
116| --> Requires explicit security review
117|
118+-- New dependency, third-party API, browser script, Docker image, background worker
119| --> Requires supply-chain and privilege review
120|
121+-- User files, prompts, markdown, URLs, or documents that influence model behavior
122| --> Requires prompt injection and content safety review
123|
124+-- Payments, account data, exports, or internal tooling
125| --> Requires authorization and auditability review
126|
127+-- Shell execution, filesystem access, or code execution
128 --> Must be sandboxed and reviewed as high risk
129```
130
131## Deep Dives
132
133| File | Content |
134|------|---------|
135| `references/web-security.md` | Frontend (Next.js) + Backend (FastAPI) security rules, auth, secrets, input validation, API design |
136| `references/docker-security.md` | Container hardening, infrastructure, network isolation, supply chain |
137| `references/ai-agent-security.md` | AI/agent security, RAG, prompt injection, tool safety, admin tools |
138
139## Practical Examples
140
141| File | Content |
142|------|---------|
143| `examples/secure-fastapi-endpoint.py` | FastAPI endpoint with validation, auth, authorization, error handling |
144| `examples/secure-nextjs-auth-flow.md` | Next.js auth with CSP, cookies, CSRF, redirect validation |
145| `examples/secure-docker-compose.yml` | Hardened docker-compose with all security measures |
146
147## Checklists
148
149| File | Content |
150|------|---------|
151| `checklists/pull-request-security-checklist.md` | Security review checklist for PRs |
152| `checklists/production-security-checklist.md` | Pre-deploy production readiness checklist |