Secure-by-Default
Use this skill to review and harden a React Native + Next.js codebase with practical, high-signal checks.
Principles:
- Prefer “deny by default” at trust boundaries (server APIs, server actions, deep links).
- Every finding must include (1) evidence and (2) a concrete remediation.
- Don’t demand tooling the repo doesn’t use; but do call out missing guardrails.
Workflow
- Identify entry points and trust boundaries.
- Next.js: API routes, server actions, middleware, auth flows, data fetching.
- React Native: network calls, deep links, local storage, push notification handlers.
- Check common risk areas (prioritize likely, exploitable issues).
- Auth:
- session handling, token storage, cookie flags, logout/invalidation
- authorization checks at every server boundary (not just UI gating)
- CSRF posture for cookie-based auth (Next.js forms/actions/APIs)
- Input validation:
- server-side validation for API routes/server actions
- schema validation for externally supplied data
- strict allowlists for enums and identifiers
- Data exposure:
- logging PII/tokens, leaking stack traces, returning overbroad objects
- client-side secrets (API keys, service credentials) accidentally bundled
- Injection:
- SQL/NoSQL injection, unsafe query building
- SSRF (fetching user-controlled URLs on the server)
- command execution, unsafe
eval/Function/dynamic imports
- Transport:
- HTTPS-only assumptions, insecure redirects, mixed content
- certificate pinning only if the repo already uses it (mobile)
- Abuse resistance:
- missing rate limiting on public endpoints
- missing request size limits/timeouts for expensive operations
- Dependency and configuration review (if tooling exists).
- Look for existing
audit or security scan scripts.
- Report outdated or vulnerable dependencies only if scan data exists.
- Prefer
pnpm audit / npm audit / yarn npm audit only when already used by the repo.
- React Native specific checks.
- Avoid storing tokens in
AsyncStorage; prefer secure storage libraries.
- Ensure deep links are validated and routed safely (no arbitrary URL execution).
- Confirm sensitive screens prevent screenshots/screen recording if required by policy.
- Confirm TLS is used for all network calls; avoid custom trust managers unless required and audited.
- Next.js specific checks.
- Verify security headers (CSP, HSTS, frame protection, content-type sniffing) if configured.
- Ensure server actions/API routes validate input and enforce auth.
- Ensure server-only code is not imported into client bundles (secrets, admin SDKs).
- Ensure environment variables follow Next.js conventions (
NEXT_PUBLIC_ only for non-secrets).
Fast Static “Red Flag” Greps (No New Tools)
Use simple search to spot high-risk patterns quickly (then confirm with code reading):
- Secrets:
NEXT_PUBLIC_ used for sensitive values
- obvious key patterns (
sk_, AIza, -----BEGIN, ghp_, xoxb-)
- Dangerous APIs:
eval(, new Function(, child_process, exec(, spawn(
- Open redirects:
redirect( where destination comes from query params without an allowlist
- SSRF:
- server-side
fetch(urlFromUser) without allowlist/URL parsing
- RN:
WebView with javaScriptEnabled and untrusted content without navigation restrictions
When reporting, include the exact file/line region and how to exploit (high-level, not step-by-step).
Resources
- Secret and red-flag scan script:
scripts/scan_redflags.sh
- Next.js and React Native checklists:
references/nextjs-security.md, references/react-native-security.md
Output Format
Provide:
- Findings (severity: High/Medium/Low)
- Evidence (file references)
- Recommended Fixes (minimal, aligned to repo patterns)
- Follow-up Checks (if tooling or docs are missing)
- “Verification” (how to confirm the fix worked, using existing scripts or minimal repro steps)
Notes
- Do not introduce new dependencies unless asked.
- If a security policy exists in the repo, follow it.
1---2name: secure-by-default3description: Check for common vulnerabilities and enforce safe patterns in React Native and Next.js apps. Use for auth, input validation, secrets handling, and dependency scanning workflows.4---56# Secure-by-Default78Use this skill to review and harden a React Native + Next.js codebase with practical, high-signal checks.910Principles:11- Prefer “deny by default” at trust boundaries (server APIs, server actions, deep links).12- Every finding must include (1) evidence and (2) a concrete remediation.13- Don’t demand tooling the repo doesn’t use; but do call out missing guardrails.1415## Workflow16171. Identify entry points and trust boundaries.18- Next.js: API routes, server actions, middleware, auth flows, data fetching.19- React Native: network calls, deep links, local storage, push notification handlers.20212. Check common risk areas (prioritize likely, exploitable issues).22- Auth:23 - session handling, token storage, cookie flags, logout/invalidation24 - authorization checks at every server boundary (not just UI gating)25 - CSRF posture for cookie-based auth (Next.js forms/actions/APIs)26- Input validation:27 - server-side validation for API routes/server actions28 - schema validation for externally supplied data29 - strict allowlists for enums and identifiers30- Data exposure:31 - logging PII/tokens, leaking stack traces, returning overbroad objects32 - client-side secrets (API keys, service credentials) accidentally bundled33- Injection:34 - SQL/NoSQL injection, unsafe query building35 - SSRF (fetching user-controlled URLs on the server)36 - command execution, unsafe `eval`/`Function`/dynamic imports37- Transport:38 - HTTPS-only assumptions, insecure redirects, mixed content39 - certificate pinning only if the repo already uses it (mobile)40- Abuse resistance:41 - missing rate limiting on public endpoints42 - missing request size limits/timeouts for expensive operations43443. Dependency and configuration review (if tooling exists).45- Look for existing `audit` or security scan scripts.46- Report outdated or vulnerable dependencies only if scan data exists.47- Prefer `pnpm audit` / `npm audit` / `yarn npm audit` only when already used by the repo.48494. React Native specific checks.50- Avoid storing tokens in `AsyncStorage`; prefer secure storage libraries.51- Ensure deep links are validated and routed safely (no arbitrary URL execution).52- Confirm sensitive screens prevent screenshots/screen recording if required by policy.53- Confirm TLS is used for all network calls; avoid custom trust managers unless required and audited.54555. Next.js specific checks.56- Verify security headers (CSP, HSTS, frame protection, content-type sniffing) if configured.57- Ensure server actions/API routes validate input and enforce auth.58- Ensure server-only code is not imported into client bundles (secrets, admin SDKs).59- Ensure environment variables follow Next.js conventions (`NEXT_PUBLIC_` only for non-secrets).6061## Fast Static “Red Flag” Greps (No New Tools)6263Use simple search to spot high-risk patterns quickly (then confirm with code reading):64- Secrets:65 - `NEXT_PUBLIC_` used for sensitive values66 - obvious key patterns (`sk_`, `AIza`, `-----BEGIN`, `ghp_`, `xoxb-`)67- Dangerous APIs:68 - `eval(`, `new Function(`, `child_process`, `exec(`, `spawn(`69- Open redirects:70 - `redirect(` where destination comes from query params without an allowlist71- SSRF:72 - server-side `fetch(urlFromUser)` without allowlist/URL parsing73- RN:74 - `WebView` with `javaScriptEnabled` and untrusted content without navigation restrictions7576When reporting, include the exact file/line region and how to exploit (high-level, not step-by-step).7778## Resources7980- Secret and red-flag scan script: `scripts/scan_redflags.sh`81- Next.js and React Native checklists: `references/nextjs-security.md`, `references/react-native-security.md`8283## Output Format8485Provide:86- Findings (severity: High/Medium/Low)87- Evidence (file references)88- Recommended Fixes (minimal, aligned to repo patterns)89- Follow-up Checks (if tooling or docs are missing)90 - “Verification” (how to confirm the fix worked, using existing scripts or minimal repro steps)9192## Notes9394- Do not introduce new dependencies unless asked.95- If a security policy exists in the repo, follow it.