Skip to content
Back to skills

Frontend Security

ASecurity

Frontend security rules to apply while writing code — XSS prevention, token handling, browser storage, secrets, CORS, API error handling, content security, and dependencies. Apply whenever writing or editing frontend .ts/.tsx code.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 11, 2026
developmentgoreactapifrontendsecuritydocumentation

Works with

  • cli
  • api

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add makigjuro/cloud-app-blueprint --skill frontend-security --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Frontend Security?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Frontend Security
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/makigjuro-frontend-security/badge)](https://www.skillsdirectory.com/skills/makigjuro-frontend-security)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: frontend-security
description: Frontend security rules to apply while writing code — XSS prevention, token handling, browser storage, secrets, CORS, API error handling, content security, and dependencies. Apply whenever writing or editing frontend .ts/.tsx code.
user-invocable: false
paths:
  - "src/**/*.ts"
  - "src/**/*.tsx"
  - "web/src/**/*.ts"
  - "web/src/**/*.tsx"
---

# Frontend Security Rules

Apply these rules while writing frontend code, not just during review.

## XSS Prevention

- Never use `dangerouslySetInnerHTML` without DOMPurify sanitization
- Sanitize any user-generated content before rendering: `DOMPurify.sanitize(userContent)`
- Avoid injecting raw HTML from API responses — parse and render structured data instead
- When rendering markdown, use a library that sanitizes by default (e.g., `react-markdown` with `rehype-sanitize`)

## Authentication & Token Handling

- Never hardcode API keys, tokens, secrets, or credentials in frontend source code
- Auth tokens should be managed by the auth library (OIDC client, MSAL, etc.) with automatic silent renewal
- API key mode is acceptable for local development only — production must use a proper auth flow (OIDC, OAuth2)
- On 401 response from the API: clear auth state and redirect to `/login?redirect={currentPath}`
- On 403 response: show an access denied message, do not retry or redirect to login

## localStorage / sessionStorage

- Keep access tokens in memory (e.g. a non-persisted Zustand store fed by the auth library) — never write them to localStorage/sessionStorage yourself; let the auth library own any token storage
- Only store non-sensitive user preferences in localStorage — never store tokens, sensitive PII, full user profiles, or secrets
- Use `sessionStorage` for data that should not persist across tabs (if applicable)
- When using Zustand `persist` middleware (or similar), use `partialize` to explicitly select which fields are stored
- Clear auth state on logout and on 401 (in-memory token plus anything the auth library persisted)

## No Hardcoded Secrets

- Never commit `.env` files with real API keys or secrets
- Use `.env.example` with placeholder values for documentation
- Environment variables exposed to the frontend (e.g., `VITE_API_URL`) must never contain secrets — they are visible in the browser bundle
- Validate: no string literals matching patterns like `sk_`, `pk_`, `api_key_`, `bearer`, `password=` in committed code

## CORS Configuration

- Only allow specific origins in production CORS configuration, never `Access-Control-Allow-Origin: *`
- CORS is a server-side concern, but frontend developers should be aware of it when configuring API clients
- If hitting CORS errors locally, fix the server CORS config rather than using a proxy that masks the issue in dev

## API Error Handling

- Never display raw API error messages or stack traces to users
- Map error codes to user-friendly messages
- Log detailed error information to the browser console (development) or error tracking service (production)
- Never include request headers (especially auth headers) in error logs or error boundaries

## Content Security

- Avoid `eval()`, `new Function()`, and other dynamic code execution
- When using iframes, apply `sandbox` attribute with minimal permissions
- Use `rel="noopener noreferrer"` on external links with `target="_blank"`

## Dependencies

- Review new frontend dependencies before adding — check for known vulnerabilities
- Keep `package-lock.json` (or equivalent) committed for reproducible builds
- Run `npm audit` periodically and address critical/high vulnerabilities
- Prefer well-maintained packages with active security response

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.