crombieman/undercurrent-cortex/security-posture

Claude Code and agent skill by crombieman/undercurrent-cortex

Trust tier 3
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Source check pending

Checking that the SKILL.md file is still in the repository.

This skill should be used when the user asks to "add an API route", "handle user input", "write a webhook", "add authentication", "security review", "security audit", "is this secure", "validate input", "add rate limiting", "add CSRF", "RLS", "env vars", "email template", "stripe integration", "payment flow", "send email", or before any code that touches auth, user data, API boundaries, or external inputs . The unified security contract.

Install

npx vskill@latest install crombieman/undercurrent-cortex/security-posture

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

The same SKILL.md was published earlier as crombieman/undercurrent-cortex/security-posture.

Security Posture

TL;DR: 16 security invariants. Every API route, user input handler, and data boundary must satisfy these.

The 16 Invariants

Server-Side Isolation
  1. `server-only` imports — All sensitive modules (DB clients, API keys, scoring, pipeline) use import "server-only". Client components never import server modules.
  2. Env validation — All process.env access routed through getServerEnv() / getPublicEnv() from src/lib/env.ts. No direct process.env usage anywhere.
  3. Column-level RLS — Row Level Security enabled on all tables. Policies grant minimum necessary access. Admin client (createAdminClient()) used for writes; cookie client for reads.
Authentication & Authorization
  1. `verifyCronSecret()` — Pipeline and cron routes verify CRON_SECRET header. Returns JSON error if missing/invalid.
  2. Middleware matcher — Every route under (dashboard)/ has a corresponding entry in middleware.ts config.matcher. Missing routes = silent auth bypass (sessions not refreshed → RLS sees anon role).
  3. Stripe webhook verification — constructEventWithSecret() verifies signature + checks replay window. Webhook secret in STRIPE_WEBHOOK_SECRET env var.
Input Validation
  1. Zod validation — All user input validated with Zod schemas before processing. Trust nothing from the client.
  2. CSRF tokens — State-changing POST routes verify CSRF token. Prevents cross-site request forgery.
  3. Rate limiting — Public endpoints use rate limiter. Note: in-memory limiter resets on cold starts (see references/known-limitations.md).
Output Safety
  1. `escapeHtml()` — All user-provided strings in email templates escaped via shared escapeHtml() from src/lib/email.ts. Prevents XSS in weekly digest, alert emails, welcome emails.
  2. JSON error responses — API routes wrap all throwable code in try/catch returning JSON. Unhandled throws produce HTML 500 → client res.json() fails. Every route has a single outer try/catch.
  3. No secret logging — Never log API keys, tokens, user emails, Stripe customer IDs, or webhook payloads. Use structured logger with sanitized context.
Data Safety
  1. No SQL injection — Parameterized queries only via Supabase client. Never construct raw SQL strings from user input.
  2. Env three-way sync — New env vars must be added to: src/lib/env.ts (validation) + Vercel dashboard + GitHub Secrets (for Actions). All three must stay in sync.
  3. Optional env documentation — Env vars that are optional (e.g., feature-flagged sources) documented with @optional comments in env.ts.
Supply Chain
  1. Dependency auditing — npm audit --audit-level=high runs in CI and Husky pre-commit hook. Block on high/critical vulnerabilities. Stripe API version pinned. npm overrides for unpatched transitive CVEs.

When Adding an API Route

Verify all of:

  • Route is in try/catch returning JSON errors
  • Auth check (getUser or verifyCronSecret)
  • Input validated with Zod
  • CSRF token on POST routes
  • Rate limiting on public endpoints
  • If under (dashboard)/, middleware matcher updated
  • No secrets logged
  • Env vars in env.ts + Vercel + GitHub Secrets

When Handling User Input

Verify all of:

  • Zod schema validates shape and bounds
  • String inputs escaped before email/HTML rendering
  • No raw user strings in SQL or PostgREST filters
  • Error messages don't leak internal state

When Writing a Webhook Endpoint

Verify all of:

  • Signature verified via constructEventWithSecret() — never trust unverified payloads
  • Replay window checked (webhook_events table stores event IDs, reject duplicates)
  • Idempotency key on any state-changing operations triggered by the webhook
  • Event type handled with switch/case, not open-ended if/else
  • Log event type + event ID only — never log the full payload (contains PII and payment details)
  • Return 200 quickly — offload long processing to avoid webhook timeout retries
  • Rate limiting on webhook endpoint — prevent abuse from spoofed requests
  • Webhook secret stored in env var, validated via getServerEnv()

When Sending Email

Verify all of:

  • All user-provided strings passed through escapeHtml() from src/lib/email.ts
  • Template variables (name, ticker, summary) are ALL escaped before interpolation
  • Digest body items are intentional HTML from callers — these are NOT escaped in the template
  • Test with XSS payloads in user-controlled fields: <script>alert(1)</script> in name, ticker
  • Rate limit email sends — no duplicate alerts within cooldown period
  • No double-escaping (escape once at template boundary, not at both caller and template)
  • Subject line length capped and sanitized — no user-controlled strings in subject without escaping and truncation

Implementation File Quick Reference

FileGuardsCheck When
src/lib/env.tsEnv var validation (getServerEnv/getPublicEnv)Adding env vars
src/middleware.tsSession refresh, route matchingAdding dashboard routes
src/lib/verify-cron.tsCRON_SECRET header checkAdding cron/pipeline routes
src/lib/stripe/server.tsStripe client, apiVersion pinStripe integration changes
src/lib/email.tsescapeHtml, email templatesEmail template changes

See references/security-audit-history.md for the security audit history template. See references/known-limitations.md for the known limitations template.


See Also

  • database-query-safety — RLS policies and query patterns overlap: both enforce data access boundaries [related]
  • deploy-readiness — Security invariants must be verified before production deploy [enforcement]

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Extension points

  • hookPre/post lifecycle hooks

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/crombieman/undercurrent-cortex/security-posture/badge)](https://verified-skill.com/skills/crombieman/undercurrent-cortex/security-posture)

Something wrong with this skill or its page? Tell us.