From af2c830f7036c7fdc7b9d8c1827d65216f08b63e Mon Sep 17 00:00:00 2001 From: 0xallam Date: Tue, 20 Jan 2026 12:38:04 -0800 Subject: [PATCH] refactor: standardize vulnerability skills format --- strix/agents/StrixAgent/system_prompt.jinja | 5 +- strix/skills/__init__.py | 7 +- strix/skills/coordination/root_agent.md | 111 +++-- strix/skills/frameworks/fastapi.md | 279 +++++++------ strix/skills/frameworks/nextjs.md | 294 +++++++++----- strix/skills/protocols/graphql.md | 355 +++++++++------- strix/skills/scan_modes/deep.md | 214 +++++----- strix/skills/scan_modes/quick.md | 95 ++--- strix/skills/scan_modes/standard.md | 149 +++---- .../skills/technologies/firebase_firestore.md | 312 +++++++------- strix/skills/technologies/supabase.md | 379 +++++++++++------- .../vulnerabilities/authentication_jwt.md | 110 ++--- .../broken_function_level_authorization.md | 104 ++--- .../skills/vulnerabilities/business_logic.md | 119 +++--- strix/skills/vulnerabilities/csrf.md | 220 +++++----- strix/skills/vulnerabilities/idor.md | 224 ++++++----- .../vulnerabilities/information_disclosure.md | 227 +++++------ .../vulnerabilities/insecure_file_uploads.md | 114 +++--- .../skills/vulnerabilities/mass_assignment.md | 154 +++---- strix/skills/vulnerabilities/open_redirect.md | 205 +++++----- .../vulnerabilities/path_traversal_lfi_rfi.md | 182 +++++---- .../skills/vulnerabilities/race_conditions.md | 129 +++--- strix/skills/vulnerabilities/rce.md | 250 ++++++++---- strix/skills/vulnerabilities/sql_injection.md | 217 +++++----- strix/skills/vulnerabilities/ssrf.md | 178 ++++---- .../vulnerabilities/subdomain_takeover.md | 175 ++++---- strix/skills/vulnerabilities/xss.md | 234 ++++++----- strix/skills/vulnerabilities/xxe.md | 137 ++++--- 28 files changed, 2904 insertions(+), 2275 deletions(-) diff --git a/strix/agents/StrixAgent/system_prompt.jinja b/strix/agents/StrixAgent/system_prompt.jinja index e8f0b2a..bde3157 100644 --- a/strix/agents/StrixAgent/system_prompt.jinja +++ b/strix/agents/StrixAgent/system_prompt.jinja @@ -398,11 +398,10 @@ Default user: pentester (sudo available) {% if loaded_skill_names %} -{# Dynamic skills loaded based on agent specialization #} - {% for skill_name in loaded_skill_names %} +<{{ skill_name }}> {{ get_skill(skill_name) }} - + {% endfor %} {% endif %} diff --git a/strix/skills/__init__.py b/strix/skills/__init__.py index 1a91543..c3ac391 100644 --- a/strix/skills/__init__.py +++ b/strix/skills/__init__.py @@ -1,7 +1,10 @@ +import re + from strix.utils.resource_paths import get_strix_resource_path _EXCLUDED_CATEGORIES = {"scan_modes", "coordination"} +_FRONTMATTER_PATTERN = re.compile(r"^---\s*\n.*?\n---\s*\n", re.DOTALL) def get_available_skills() -> dict[str, list[str]]: @@ -127,7 +130,9 @@ def load_skills(skill_names: list[str]) -> dict[str, str]: if skill_path and (skills_dir / skill_path).exists(): full_path = skills_dir / skill_path var_name = skill_name.split("/")[-1] - skill_content[var_name] = full_path.read_text() + content = full_path.read_text() + content = _FRONTMATTER_PATTERN.sub("", content).lstrip() + skill_content[var_name] = content logger.info(f"Loaded skill: {skill_name} -> {var_name}") else: logger.warning(f"Skill not found: {skill_name}") diff --git a/strix/skills/coordination/root_agent.md b/strix/skills/coordination/root_agent.md index 4c4f163..981c3b9 100644 --- a/strix/skills/coordination/root_agent.md +++ b/strix/skills/coordination/root_agent.md @@ -1,41 +1,92 @@ -# ROOT COORDINATION AGENT +--- +name: root-agent +description: Orchestration layer that coordinates specialized subagents for security assessments +--- -You are a COORDINATION AGENT ONLY. You do NOT perform any security testing, vulnerability assessment, or technical work yourself. +# Root Agent -Your ONLY responsibilities: -1. Create specialized agents for specific security tasks -2. Monitor agent progress and coordinate between them -3. Compile final scan reports from agent findings -4. Manage agent communication and dependencies +Orchestration layer for security assessments. This agent coordinates specialized subagents but does not perform testing directly. -CRITICAL RESTRICTIONS: -- NEVER perform vulnerability testing or security assessments -- NEVER write detailed vulnerability reports (only compile final summaries) -- ONLY use agent_graph and finish tools for coordination -- You can create agents throughout the scan process, depending on the task and findings, not just at the beginning! +You can create agents throughout the testing process—not just at the beginning. Spawn agents dynamically based on findings and evolving scope. -## Agent Management +## Role -BEFORE CREATING AGENTS: +- Decompose targets into discrete, parallelizable tasks +- Spawn and monitor specialized subagents +- Aggregate findings into a cohesive final report +- Manage dependencies and handoffs between agents + +## Scope Decomposition + +Before spawning agents, analyze the target: + +1. **Identify attack surfaces** - web apps, APIs, infrastructure, etc. +2. **Define boundaries** - in-scope domains, IP ranges, excluded assets +3. **Determine approach** - blackbox, greybox, or whitebox assessment +4. **Prioritize by risk** - critical assets and high-value targets first + +## Agent Architecture + +Structure agents by function: + +**Reconnaissance** +- Asset discovery and enumeration +- Technology fingerprinting +- Attack surface mapping + +**Vulnerability Assessment** +- Injection testing (SQLi, XSS, command injection) +- Authentication and session analysis +- Access control testing (IDOR, privilege escalation) +- Business logic flaws +- Infrastructure vulnerabilities + +**Exploitation and Validation** +- Proof-of-concept development +- Impact demonstration +- Vulnerability chaining + +**Reporting** +- Finding documentation +- Remediation recommendations + +## Coordination Principles + +**Task Independence** + +Create agents with minimal dependencies. Parallel execution is faster than sequential. + +**Clear Objectives** + +Each agent should have a specific, measurable goal. Vague objectives lead to scope creep and redundant work. + +**Avoid Duplication** + +Before creating agents: 1. Analyze the target scope and break into independent tasks -2. Check existing agents to avoid duplication -3. Create agents with clear, specific objectives to avoid duplication +2. Check existing agents to avoid overlap +3. Create agents with clear, specific objectives -AGENT TYPES YOU CAN CREATE: -- Reconnaissance: subdomain enum, port scanning, tech identification, etc. -- Vulnerability Testing: SQL injection, XSS, auth bypass, IDOR, RCE, SSRF, etc. Can be black-box or white-box. - - Direct vulnerability testing agents to implement hierarchical workflow (per finding: discover, verify, report, fix): each one should create validation agents for findings verification, which spawn reporting agents for documentation, which create fix agents for remediation +**Hierarchical Delegation** -COORDINATION GUIDELINES: -- Ensure clear task boundaries and success criteria -- Terminate redundant agents when objectives overlap -- Use message passing only when essential (requests/answers or critical handoffs); avoid routine status messages and prefer batched updates +Complex findings warrant specialized subagents: +- Discovery agent finds potential vulnerability +- Validation agent confirms exploitability +- Reporting agent documents with reproduction steps +- Fix agent provides remediation (if needed) -## Final Responsibilities +**Resource Efficiency** -When all agents complete: -1. Collect findings from all agents -2. Compile a final scan summary report -3. Use finish tool to complete the assessment +- Avoid duplicate coverage across agents +- Terminate agents when objectives are met or no longer relevant +- Use message passing only when essential (requests/answers, critical handoffs) +- Prefer batched updates over routine status messages -Your value is in orchestration, not execution. +## Completion + +When all agents report completion: + +1. Collect and deduplicate findings across agents +2. Assess overall security posture +3. Compile executive summary with prioritized recommendations +4. Invoke finish tool with final report diff --git a/strix/skills/frameworks/fastapi.md b/strix/skills/frameworks/fastapi.md index 47904db..81163bf 100644 --- a/strix/skills/frameworks/fastapi.md +++ b/strix/skills/frameworks/fastapi.md @@ -1,146 +1,191 @@ -# FASTAPI — ADVERSARIAL TESTING PLAYBOOK +--- +name: fastapi +description: Security testing playbook for FastAPI applications covering ASGI, dependency injection, and API vulnerabilities +--- -## Critical +# FastAPI -FastAPI (on Starlette) spans HTTP, WebSocket, and background tasks with powerful dependency injection and automatic OpenAPI. Security breaks where identity, authorization, and validation drift across routers, middlewares, proxies, and channels. Treat every dependency, header, and object reference as untrusted until bound to the caller and tenant. +Security testing for FastAPI/Starlette applications. Focus on dependency injection flaws, middleware gaps, and authorization drift across routers and channels. -## Surface Map +## Attack Surface -- ASGI stack: Starlette middlewares (CORS, TrustedHost, ProxyHeaders, Session), exception handlers, lifespan events -- Routers/sub-apps: APIRouter with prefixes/tags, mounted apps (StaticFiles, admin subapps), `include_router`, versioned paths -- Security and DI: `Depends`, `Security`, `OAuth2PasswordBearer`, `HTTPBearer`, scopes, per-router vs per-route dependencies -- Models and validation: Pydantic v1/v2 models, unions/Annotated, custom validators, extra fields policy, coercion -- Docs and schema: `/openapi.json`, `/docs`, `/redoc`, alternative docs_url/redoc_url, schema extensions -- Files and static: `UploadFile`, `File`, `FileResponse`, `StaticFiles` mounts, template engines (`Jinja2Templates`) -- Channels: HTTP (sync/async), WebSocket, StreamingResponse/SSE, BackgroundTasks/Task queues -- Deployment: Uvicorn/Gunicorn, reverse proxies/CDN, TLS termination, header trust +**Core Components** +- ASGI middlewares: CORS, TrustedHost, ProxyHeaders, Session, exception handlers, lifespan events +- Routers and sub-apps: APIRouter prefixes/tags, mounted apps (StaticFiles, admin), `include_router`, versioned paths +- Dependency injection: `Depends`, `Security`, `OAuth2PasswordBearer`, `HTTPBearer`, scopes -## Methodology +**Data Handling** +- Pydantic models: v1/v2, unions/Annotated, custom validators, extra fields policy, coercion +- File operations: UploadFile, File, FileResponse, StaticFiles mounts +- Templates: Jinja2Templates rendering -1. Enumerate routes from OpenAPI and via crawling; diff with 404-fuzzing for hidden endpoints (`include_in_schema=False`). -2. Build a Principal × Channel × Content-Type matrix (unauth, user, staff/admin; HTTP vs WebSocket; JSON/form/multipart) and capture baselines. -3. For each route, identify dependencies (router-level and route-level). Attempt to satisfy security dependencies minimally, then mutate context (tokens, scopes, tenant headers) and object IDs. -4. Compare behavior across deployments: dev/stage/prod often differ in middlewares (CORS, TrustedHost, ProxyHeaders) and docs exposure. +**Channels** +- HTTP (sync/async), WebSocket, SSE/StreamingResponse +- BackgroundTasks and task queues -## High Value Targets +**Deployment** +- Uvicorn/Gunicorn, reverse proxies/CDN, TLS termination, header trust -- `/openapi.json`, `/docs`, `/redoc` in production (full attack surface map; securitySchemes and server URLs) -- Auth flows: token endpoints, session/cookie bridges, OAuth device/PKCE, scope checks +## High-Value Targets + +- `/openapi.json`, `/docs`, `/redoc` in production (full attack surface map, securitySchemes, server URLs) +- Auth flows: token endpoints, session/cookie bridges, OAuth device/PKCE - Admin/staff routers, feature-flagged routes, `include_in_schema=False` endpoints - File upload/download, import/export/report endpoints, signed URL generators -- WebSocket endpoints carrying notifications, admin channels, or commands -- Background job creation/fetch (`/jobs/{id}`, `/tasks/{id}/result`) -- Mounted subapps (admin UI, storage browsers, metrics/health endpoints) +- WebSocket endpoints (notifications, admin channels, commands) +- Background job endpoints (`/jobs/{id}`, `/tasks/{id}/result`) +- Mounted subapps (admin UI, storage browsers, metrics/health) -## Advanced Techniques +## Reconnaissance -### Openapi And Docs - -- Try default and alternate locations: `/openapi.json`, `/docs`, `/redoc`, `/api/openapi.json`, `/internal/openapi.json`. -- If OpenAPI is exposed, mine: paths, parameter names, securitySchemes, scopes, servers; find endpoints hidden in UI but present in schema. -- Schema drift: endpoints with `include_in_schema=False` won’t appear—use wordlists based on tags/prefixes and common admin/debug names. - -### Dependency Injection And Security - -- Router vs route dependencies: routes may miss security dependencies present elsewhere; check for unprotected variants of protected actions. -- Minimal satisfaction: `OAuth2PasswordBearer` only yields a token string—verify if any route treats token presence as auth without verification. -- Scope checks: ensure scopes are enforced by the dependency (e.g., `Security(...)`); routes using `Depends` instead may ignore requested scopes. -- Header/param aliasing: DI sources headers/cookies/query by name; try case variations and duplicates to influence which value binds. - -### Auth And Jwt - -- Token misuse: developers may decode JWTs without verifying signature/issuer/audience; attempt unsigned/attacker-signed tokens and cross-service audiences. -- Algorithm/key confusion: try HS/RS cross-use if verification is not pinned; inject `kid` header targeting local files/paths where custom key lookup exists. -- Session bridges: check cookies set via SessionMiddleware or custom cookies. Attempt session fixation and forging if weak `secret_key` or predictable signing is used. -- Device/PKCE flows: verify strict PKCE S256 and state/nonce enforcement if OAuth/OIDC is integrated. - -### Cors And Csrf - -- CORS reflection: broad `allow_origin_regex` or mis-specified origins can permit cross-site reads; test arbitrary Origins and credentialed requests. -- CSRF: FastAPI/Starlette lack built-in CSRF. If cookies carry auth, attempt state-changing requests via cross-site forms/XHR; validate origin header checks and same-site settings. - -### Proxy And Host Trust - -- ProxyHeadersMiddleware: if enabled without network boundary, spoof `X-Forwarded-For/Proto` to influence auth/IP gating and secure redirects. -- TrustedHostMiddleware absent or lax: perform Host header poisoning; attempt password reset links / absolute URL generation under attacker host. -- Upstream/CDN cache keys: ensure Vary on Authorization/Cookie/Tenant; try cache key confusion to leak personalized responses. - -### Static And Uploads - -- UploadFile.filename: attempt path traversal and control characters; verify server joins/sanitizes and enforces storage roots. -- FileResponse/StaticFiles: confirm directory boundaries and index/auto-listing; probe symlinks and case/encoding variants. -- Parser differentials: send JSON vs multipart for the same route to hit divergent code paths/validators. - -### Template Injection - -- Jinja2 templates via `TemplateResponse`: search for unescaped injection in variables and filters. Probe with minimal expressions: +**OpenAPI Mining** ``` -- `{{7*7}}` → arithmetic confirmation -- `{{cycler.__init__.__globals__['os'].popen('id').read()}}` for RCE in unsafe contexts +GET /openapi.json +GET /docs +GET /redoc +GET /api/openapi.json +GET /internal/openapi.json ``` -- Confirm autoescape and strict sandboxing; inspect custom filters/globals. -### Ssrf And Outbound +Extract: paths, parameters, securitySchemes, scopes, servers. Endpoints with `include_in_schema=False` won't appear—fuzz based on discovered prefixes and common admin/debug names. -- Endpoints fetching user-supplied URLs (imports, previews, webhooks validation): test loopback/RFC1918/IPv6, redirects, DNS rebinding, and header control. -- Library behavior (httpx/requests): examine redirect policy, header forwarding, and protocol support; try `file://`, `ftp://`, or gopher-like shims if custom clients are used. +**Dependency Mapping** -### Websockets +For each route, identify: +- Router-level dependencies (applied to all routes) +- Route-level dependencies (per endpoint) +- Which dependencies enforce auth vs just parse input -- Authenticate each connection (query/header/cookie). Attempt cross-origin handshakes and cookie-bearing WS from untrusted origins. -- Topic naming and authorization: if using user/tenant IDs in channels, subscribe/publish to foreign IDs. -- Message-level checks: ensure per-message authorization, not only at handshake. +## Key Vulnerabilities -### Background Tasks And Jobs +### Authentication & Authorization -- BackgroundTasks that act on IDs must re-enforce ownership/tenant at execution time. Attempt to fetch/cancel others’ jobs by referencing their IDs. -- Export/import pipelines: test job/result endpoints for IDOR and cross-tenant leaks. +**Dependency Injection Gaps** +- Routes missing security dependencies present on other routes +- `Depends` used instead of `Security` (ignores scope enforcement) +- Token presence treated as authentication without signature verification +- `OAuth2PasswordBearer` only yields a token string—verify routes don't treat presence as auth -### Multi App Mounting +**JWT Misuse** +- Decode without verify: test unsigned tokens, attacker-signed tokens +- Algorithm confusion: HS256/RS256 cross-use if not pinned +- `kid` header injection for custom key lookup paths +- Missing issuer/audience validation, cross-service token reuse -- Mounted subapps (e.g., `/admin`, `/static`, `/metrics`) may bypass global middlewares. Confirm middleware parity and auth on mounts. +**Session Weaknesses** +- SessionMiddleware with weak `secret_key` +- Session fixation via predictable signing +- Cookie-based auth without CSRF protection + +**OAuth/OIDC** +- Device/PKCE flows: verify strict PKCE S256 and state/nonce enforcement + +### Access Control + +**IDOR via Dependencies** +- Object IDs in path/query not validated against caller +- Tenant headers trusted without binding to authenticated user +- BackgroundTasks acting on IDs without re-validating ownership at execution time +- Export/import pipelines with IDOR and cross-tenant leaks + +**Scope Bypass** +- Minimal scope satisfaction (any valid token accepted) +- Router vs route scope enforcement inconsistency + +### Input Handling + +**Pydantic Exploitation** +- Type coercion: strings to ints/bools, empty strings to None, truthiness edge cases +- Extra fields: `extra = "allow"` permits injecting control fields (role, ownerId, scope) +- Union types and `Annotated`: craft shapes hitting unintended validation branches + +**Content-Type Switching** +``` +application/json ↔ application/x-www-form-urlencoded ↔ multipart/form-data +``` +Different content types hit different validators or code paths (parser differentials). + +**Parameter Manipulation** +- Case variations in header/cookie names +- Duplicate parameters exploiting DI precedence +- Method override via `X-HTTP-Method-Override` (upstream respects, app doesn't) + +### CORS & CSRF + +**CORS Misconfiguration** +- Overly broad `allow_origin_regex` +- Origin reflection without validation +- Credentialed requests with permissive origins +- Verify preflight vs actual request deltas + +**CSRF Exposure** +- No built-in CSRF in FastAPI/Starlette +- Cookie-based auth without origin validation +- Missing SameSite attribute + +### Proxy & Host Trust + +**Header Spoofing** +- ProxyHeadersMiddleware without network boundary: spoof `X-Forwarded-For/Proto` to influence auth/IP gating +- Absent TrustedHostMiddleware: Host header poisoning in password reset links, absolute URL generation +- Cache key confusion: missing Vary on Authorization/Cookie/Tenant + +### Server-Side Vulnerabilities + +**Template Injection (Jinja2)** +```python +{{7*7}} # Arithmetic confirmation +{{cycler.__init__.__globals__['os'].popen('id').read()}} # RCE +``` +Check autoescape settings and custom filters/globals. + +**SSRF** +- User-supplied URLs in imports, previews, webhooks validation +- Test: loopback, RFC1918, IPv6, redirects, DNS rebinding, header control +- Library behavior (httpx/requests): redirect policy, header forwarding, protocol support +- Protocol smuggling: `file://`, `ftp://`, gopher-like shims if custom clients + +**File Upload** +- Path traversal in `UploadFile.filename` with control characters +- Missing storage root enforcement, symlink following +- Vary filename encodings, dot segments, NUL-like bytes +- Verify storage paths and served URLs + +### WebSocket Security + +- Missing per-connection authentication +- Cross-origin WebSocket without origin validation +- Topic/channel IDOR (subscribing to other users' channels) +- Authorization only at handshake, not per-message + +### Mounted Apps + +Sub-apps at `/admin`, `/static`, `/metrics` may bypass global middlewares. Verify auth enforcement parity across all mounts. + +### Alternative Stacks + +- If GraphQL (Strawberry/Graphene) is mounted: validate resolver-level authorization, IDOR on node/global IDs +- If SQLModel/SQLAlchemy present: probe for raw query usage and row-level authorization gaps ## Bypass Techniques -- Content-type switching: `application/json` ↔ `application/x-www-form-urlencoded` ↔ `multipart/form-data` to traverse alternate validators/handlers. -- Parameter duplication and case variants to exploit DI precedence. -- Method confusion via proxies (e.g., `X-HTTP-Method-Override`) if upstream respects it while app does not. -- Race windows around dependency-validated state transitions (issue token then mutate with parallel requests). +- Content-type switching to traverse alternate validators +- Parameter duplication and case variants exploiting DI precedence +- Method confusion via proxies (`X-HTTP-Method-Override`) +- Race windows around dependency-validated state transitions (issue token then mutate with parallel requests) -## Special Contexts +## Testing Methodology -### Pydantic Edges +1. **Enumerate** - Fetch OpenAPI, diff with 404-fuzzing for hidden endpoints +2. **Matrix testing** - Test each route across: unauth/user/admin × HTTP/WebSocket × JSON/form/multipart +3. **Dependency analysis** - Map which dependencies enforce auth vs parse input +4. **Cross-environment** - Compare dev/stage/prod for middleware and docs exposure differences +5. **Channel consistency** - Verify same authorization on HTTP and WebSocket for equivalent operations -- Coercion: strings to ints/bools, empty strings to None; exploit truthiness and boundary conditions. -- Extra fields: if models allow/ignore extras, sneak in control fields for downstream logic (scope/role/ownerId) that are later trusted. -- Unions and `Annotated`: craft shapes hitting unintended branches. +## Validation Requirements -### Graphql And Alt Stacks - -- If GraphQL (Strawberry/Graphene) is mounted, validate resolver-level authorization and IDOR on node/global IDs. -- If SQLModel/SQLAlchemy present, probe for raw query usage and row-level authorization gaps. - -## Validation - -1. Show unauthorized data access or action with side-by-side owner vs non-owner requests (or different tenants). -2. Demonstrate cross-channel consistency (HTTP and WebSocket) for the same rule. -3. Include proof where proxies/headers/caches alter outcomes (Host/XFF/CORS). -4. Provide minimal payloads confirming template/SSRF execution or token misuse, with safe or OAST-based oracles. -5. Document exact dependency paths (router-level, route-level) that missed enforcement. - -## Pro Tips - -1. Always fetch `/openapi.json` first; it’s the blueprint. If hidden, brute-force likely admin/report/export routes. -2. Trace dependencies per route; map which ones enforce auth/scopes vs merely parse input. -3. Treat tokens returned by `OAuth2PasswordBearer` as untrusted strings—verify actual signature and claims on the server. -4. Test CORS with arbitrary Origins and with credentials; verify preflight and actual request deltas. -5. Add Host and X-Forwarded-* fuzzing when behind proxies; watch for redirect/absolute URL differences. -6. For uploads, vary filename encodings, dot segments, and NUL-like bytes; verify storage paths and served URLs. -7. Use content-type toggling to hit alternate validators and code paths. -8. For WebSockets, test cookie-based auth, origin restrictions, and per-message authorization. -9. Mine client bundles/env for secret paths and preview/admin flags; many teams hide routes via UI only. -10. Keep PoCs minimal and durable (IDs, headers, small payloads) and prefer reproducible diffs over noisy payloads. - -## Remember - -Authorization and validation must be enforced in the dependency graph and at the resource boundary for every path and channel. If any route, middleware, or mount skips binding subject, action, and object/tenant, expect cross-user and cross-tenant breakage. +- Side-by-side requests showing unauthorized access (owner vs non-owner, cross-tenant) +- Cross-channel proof (HTTP and WebSocket for same rule) +- Header/proxy manipulation showing altered outcomes (Host/XFF/CORS) +- Minimal payloads for template injection, SSRF, token misuse with safe/OAST oracles +- Document exact dependency paths (router-level, route-level) that missed enforcement diff --git a/strix/skills/frameworks/nextjs.md b/strix/skills/frameworks/nextjs.md index ed9f11d..5ae8860 100644 --- a/strix/skills/frameworks/nextjs.md +++ b/strix/skills/frameworks/nextjs.md @@ -1,154 +1,228 @@ -# NEXT.JS — ADVERSARIAL TESTING PLAYBOOK +--- +name: nextjs +description: Security testing playbook for Next.js covering App Router, Server Actions, RSC, and Edge runtime vulnerabilities +--- -## Critical +# Next.js -Modern Next.js combines multiple execution contexts (Edge, Node, RSC, client) with smart caching (ISR/RSC fetch cache), middleware, and server actions. Authorization and cache boundaries must be enforced consistently across all paths or attackers will cross tenants, leak data, or invoke privileged actions. +Security testing for Next.js applications. Focus on authorization drift across runtimes (Edge/Node), caching boundaries, server actions, and middleware bypass. -## Surface Map +## Attack Surface -- Routers: App Router (`app/`) and Pages Router (`pages/`) coexist; test both -- Runtimes: Node.js vs Edge (V8 isolates with restricted APIs) -- Data paths: RSC (server components), Client components, Route Handlers (`app/api/**`), API routes (`pages/api/**`) -- Middleware: `middleware.ts`/`_middleware.ts` -- Rendering modes: SSR, SSG, ISR, on-demand revalidation, draft/preview mode -- Images: `next/image` optimization and remote loader -- Auth: NextAuth.js (callbacks, CSRF/state, callbackUrl), custom JWT/session bridges -- Server Actions: streamed POST with `Next-Action` header and action IDs +**Routers** +- App Router (`app/`) and Pages Router (`pages/`) often coexist +- Route Handlers (`app/api/**`) and API routes (`pages/api/**`) +- Middleware: `middleware.ts` at project root -## Methodology +**Runtimes** +- Node.js (full API access) +- Edge (V8 isolates, restricted APIs) -1. Inventory routes (pages + app), static vs dynamic segments, and params. Map middleware coverage and runtime per path. -2. Capture baseline for each role (unauth, user, admin) across SSR, API routes, Route Handlers, Server Actions, and streaming data. -3. Diff responses while toggling runtime (Edge/Node), content-type, fetch cache directives, and preview/draft mode. -4. Probe caching and revalidation boundaries (ISR, RSC fetch, CDN) for cross-user/tenant leaks. +**Rendering & Caching** +- SSR, SSG, ISR, on-demand revalidation +- RSC (React Server Components) with fetch cache +- Draft/preview mode -## High Value Targets +**Data Paths** +- Server Components, Client Components +- Server Actions (streamed POST with `Next-Action` header) +- `getServerSideProps`, `getStaticProps` + +**Integrations** +- NextAuth.js (callbacks, CSRF, callbackUrl) +- `next/image` optimization and remote loaders + +## High-Value Targets - Middleware-protected routes (auth, geo, A/B) - Admin/staff paths, draft/preview content, on-demand revalidate endpoints -- RSC payloads and flight data, streamed responses (server actions) +- RSC payloads and flight data, streamed responses - Image optimizer and custom loaders, remotePatterns/domains -- NextAuth callbacks (`/api/auth/callback/*`), sign-in providers, CSRF/state handling +- NextAuth callbacks (`/api/auth/callback/*`), sign-in providers - Edge-only features (bot protection, IP gates) and their Node equivalents -## Advanced Techniques +## Reconnaissance -### Route Enumeration +**Route Discovery** -- __BUILD_MANIFEST.sortedPages: Execute `console.log(__BUILD_MANIFEST.sortedPages.join('\n'))` in browser console to instantly reveal all registered routes (Pages Router and static App Router paths compiled at build time) -- __NEXT_DATA__: Inspect `