src/orchestrator/skills/security-hardening/SKILL.md
Security architecture including authentication, authorization, RLS policies, CSP, input validation, and API security. Use when implementing auth flows, writing RLS policies, configuring CSP/headers, validating inputs, or auditing security. Trigger terms: RLS, CSP, Server Actions, Zod, auth flow
npx skillsauth add etylsarin/opencastle security-hardeningInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| Layer | Tool | Protection |
|-------|------|------------|
| Edge | WAF / CDN | DDoS, bot detection |
| Headers | Framework config | HSTS, CSP, X-Frame-Options |
| Middleware | Proxy layer | Session refresh, protected routes |
| Server Actions | Auth provider | Authentication, CSRF |
| Database | RLS Policies | Row-level authorization |
| API Routes | CRON_SECRET | Cron job authorization |
| Input | Zod | Schema validation |
| Rate Limiting | Proxy layer | IP-based throttling |
Auth provider with Server Actions pattern. Resolve library via database capability slot in skill matrix.
| Concern | Approach |
|---------|----------|
| Sign in/up/out | Server Actions (POST-only → automatic CSRF protection) |
| Session refresh | Middleware updateSession(), HTTP-only cookies |
| Protected routes | Middleware check |
| OAuth | Configured in auth provider dashboard |
| User roles | profiles.roles TEXT[] |
| Cron auth | CRON_SECRET env var, Bearer token in authorization header |
Principle of least privilege. External domains are project-specific (see deployment customization).
default-src 'self' — deny by defaultobject-src 'none' — block pluginsframe-ancestors 'self' — prevent clickjackingupgrade-insecure-requests — enforce HTTPSNote: 'unsafe-inline'/'unsafe-eval' may be required in dev mode — use nonces/hashes in production.
Examples — Next.js next.config.js headers and middleware pattern:
// next.config.js
module.exports = {
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
// minimal example; restrict further per app needs
value: "default-src 'self'; script-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self' https://api.example.com;",
},
],
},
];
},
};
// middleware.js (Next.js Edge middleware example)
import { NextResponse } from 'next/server';
export function middleware(request) {
const res = NextResponse.next();
res.headers.set('Content-Security-Policy', "default-src 'self'; img-src 'self' data:;");
return res;
}
SQL examples and role system: See the database skill (authoritative source for RLS).
ALTER TABLE x ENABLE ROW LEVEL SECURITY; on all tablesauth.uid() for auth checks; EXISTS subqueries for role checksRLS verification & test pattern
-- run in psql
SELECT relname, relrowsecurity
FROM pg_class
WHERE relname = 'your_table_name';
relrowsecurity = true indicates RLS enabled.
-- As owner (create test row)
INSERT INTO your_table_name (id, owner_id, data) VALUES (1, 'owner-uid', 'secret');
-- As another_role (should return zero rows if RLS correct)
SET ROLE other_role;
SELECT * FROM your_table_name WHERE id = 1;
-- expected: 0 rows
Automate this check in CI: run the enabling query and a simple positive/negative test as part of the security gate.
'use server';
import { z } from 'zod';
import { revalidatePath } from 'next/cache';
const schema = z.object({ name: z.string().min(1), price: z.number().positive() });
export async function createItem(formData: FormData) {
const parsed = schema.safeParse(Object.fromEntries(formData.entries()));
if (!parsed.success) return { error: 'Validation failed', details: parsed.error.format() };
// insert into DB ...
revalidatePath('/items');
return { success: true };
}
// Cron authorization pattern
const authHeader = request.headers.get('authorization');
if (!authHeader || authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
Generate secret: openssl rand -hex 32. Rotate quarterly.
Input: Zod schemas in all Server Actions and route handlers; React Hook Form client-side.
SELECT relrowsecurity FROM pg_class WHERE relname = 'your_table')./api/me).next.config.js or middleware; validate headers with curl -I against a preview URL.Cross-reference: see api-patterns/SKILL.md for Server Action patterns and session-checkpoints/SKILL.md for checkpointing security-sensitive work.
development
Defines 10 sequential validation gates: secret scanning, lint/test/build checks, blast radius analysis, dependency auditing, browser testing, cache management, regression checks, and smoke tests. Use when running pre-deploy validation or CI checks, CI/CD pipelines, deployment pipeline validation, pre-merge checks, continuous integration, or pull request validation.
development
Generates test plans, writes unit/integration/E2E test files, identifies coverage gaps, and flags common testing anti-patterns. Use when writing tests, creating test suites, planning test strategies, mocking dependencies, measuring code coverage, or test planning.
development
Provides model routing rules, validates delegation prerequisites, supplies cost tracking templates, and defines dead-letter queue formats for Team Lead orchestration. Load when assigning tasks to agents, choosing model tiers, starting a delegation session, running a multi-agent workflow, delegating work, choosing which model to use, or assigning tasks.
testing
Saves and restores session state including task progress, file changes, and delegation history. Use when saving progress, resuming interrupted work, picking up where you left off, or checkpointing current work.