/storefront-next:sfnext-securityfrom storefront-next
Configures Storefront Next security headers, Content Security Policy (CSP), Cloudflare Turnstile bot protection, and shared cookie domains. Handles CSP violations, third-party origin additions, HSTS, Permissions-Policy, and Turnstile setup.
Ships in storefront-next. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Security is configured under app.security in config.server.ts: security.headers for response headers and CSP, security.turnstile for bot protection. Cookie sharing is app.cookies.domain. Your project ships deeper docs: docs/README-SECURITY-HEADERS.md, docs/README-TURNSTILE.md, docs/README-COOKIE-DOMAIN.md. Read them for details; this skill is the task guide.
Every storefront gets these with no opt-in, from @salesforce/storefront-next-runtime/security via the securityHeadersMiddleware in src/middlewares/security-headers.server.ts:
| Header | Default |
|---|---|
Content-Security-Policy | Strict, nonce-based (no 'unsafe-inline' scripts, no 'unsafe-eval') |
Strict-Transport-Security | Sent on Managed Runtime only, suppressed locally |
X-Frame-Options | SAMEORIGIN |
X-Content-Type-Options | nosniff |
Referrer-Policy | strict-origin-when-cross-origin |
Permissions-Policy | camera=(), microphone=(), geolocation=() |
The CSP directive table (which origins script-src, connect-src, img-src, and frame-src allow by default) is in docs/README-SECURITY-HEADERS.md. The per-request nonce is read in root.tsx and must be forwarded to any inline <script> you render (for example the JSON-LD component takes a nonce prop).
The violation message names the directive to extend ("Refused to connect to ..." means connect-src). Spread the defaults, because each directive you set fully replaces the default:
// config.server.ts
import { defaultCspDirectives } from '@salesforce/storefront-next-runtime/security';
security: {
headers: {
csp: {
directives: {
...defaultCspDirectives,
'script-src': [...defaultCspDirectives['script-src']!, 'https://cdn.example.com'],
'connect-src': [...defaultCspDirectives['connect-src']!, 'https://api.example.com'],
},
},
},
},
Use exact origins, not wildcards. Do not load third-party scripts synchronously in the document head; load them after interaction or idle (see storefront-next:sfnext-performance).
Env-var override is awkward for directives (names contain hyphens, and a JSON override replaces the whole map). Use config.server.ts for directives and env vars for toggles:
PUBLIC__app__security__headers__csp__reportOnly=true
PUBLIC__app__security__headers__hsts=false
csp: { reportOnly: true }, watch DevTools violations, extend the directives, then remove reportOnly. A startup warning is logged while it is on.hsts: false or permissionsPolicy: false. headers: { enabled: false } disables everything; use it for debugging only. A startup warning is logged whenever any header is disabled.A contributor lets a feature add its own exact origins to the CSP at boot instead of hand-editing directives. Shipped examples in src/middlewares/csp-contributors/: cimulate.ts (Shopper Agent widget, active when enabled in config), data360.ts (connect-src for the tenant ingestion host), and openstreetmap.ts (a deliberate no-op; replace it to permit map tiles).
Shape (see data360.ts for the smallest real one):
import type { CspContributor, CspContribution } from '@salesforce/storefront-next-runtime/security';
import { toCspOrigin } from './to-csp-origin.js';
export function createMyFeatureCspContributor(cfg: { enabled?: boolean; apiUrl?: string } | undefined): CspContributor {
const origin = cfg?.apiUrl ? toCspOrigin(cfg.apiUrl) : null;
return {
id: 'my-feature',
isActive: () => cfg?.enabled === true && origin !== null,
contribute: (): CspContribution => (origin ? { 'connect-src': [origin] } : {}),
};
}
Then add it to the contributors array in src/middlewares/security-headers.server.ts. Rules:
toCspOrigin returns null for unsafe values.*.test.ts like the shipped ones.Use a contributor for a feature toggled by config; use the defaultCspDirectives spread for one-off origins.
Cloudflare Turnstile guards passwordless email, checkout registration, and order lookup. It is fail-open on Cloudflare outages (so a Turnstile incident never blocks checkout) and fail-closed on real bot signals (forged, replayed, or missing tokens).
Config (config.server.ts, overridable with PUBLIC__ env vars): security.turnstile.enabled, mode (managed, non-interactive, invisible), sites (per-site site keys), and verification.mode (enforce, log-only, disabled).
| Variable | Purpose |
|---|---|
TURNSTILE_SECRET_KEYS | JSON map of site key to secret key. Server-only. Required for enforce and log-only |
PUBLIC__app__security__turnstile__enabled | Master switch; when false the widget never renders |
PUBLIC__app__security__turnstile__sites | JSON per-site keys |
PUBLIC__app__security__turnstile__verification__mode | enforce, log-only, disabled |
Rollout: deploy with verification.mode set to log-only, read the logs for would_block, then switch to enforce. Shoppers start without a cc-tv_<siteId> attestation cookie after the switch, which is expected.
Add protection to a new server action by rendering TurnstileWidget (src/components/security/turnstile-widget.tsx) in the form and calling enforceTurnstile (src/lib/turnstile/enforce.server.ts) in the action before doing work. Pass request, config, turnstileToken, logger, actionName, email, and turnstileCookieName; set the cc-tv cookie from the returned cookieValue when it is non-null. Copy an existing caller such as src/routes/action.authorize-passwordless-email.ts. Cloudflare test keys and a manual test matrix: references/TURNSTILE.md.
Cookies are host-only by default. To share them across subdomains or with SFRA, set app.cookies.domain (or commerce.sites[].cookies.domain per site; env PUBLIC__app__cookies__domain=.example.com) and match Business Manager: Site Preferences, Hybrid Auth Settings, cookie-domain level 0 for host-only, 2 for the first-level parent domain. Level 1 is rejected. A mismatch silently breaks sessions. Full checklist: references/COOKIE-DOMAIN.md.
| Symptom | Cause / fix |
|---|---|
Added origin to script-src and other scripts broke | You replaced the directive. Spread defaultCspDirectives['script-src'] first |
| Inline script blocked | Missing nonce. Read it from root loader data and pass it on |
CSS/JS fail on local Safari after enabling your own upgrade-insecure-requests | The default suppresses it locally for a reason; keep the default |
Login does not stick after setting cookies.domain | Domain is not a parent of the serving host, or Business Manager level mismatches |
| Turnstile widget never appears | Expected when Cloudflare says no challenge is needed (interaction-only); check network tab and cc-tv_<siteId> |
| Everything blocked in Turnstile tests | Secret keys missing in TURNSTILE_SECRET_KEYS for the configured site key |
storefront-next:sfnext-authentication - cookies, sessions, login flows that Turnstile protectsstorefront-next:sfnext-hybrid-storefronts - SFRA proxy and dwsid session bridgestorefront-next:sfnext-configuration - config.server.ts and PUBLIC__ overridesstorefront-next:sfnext-performance - loading third-party scripts safelystorefront-next:sfnext-analytics-consent - tracking consent and analytics adaptersstorefront-next:sfnext-deployment - Managed Runtime environment variablesWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub salesforcecommercecloud/b2c-developer-tooling --plugin storefront-next25 skills in this plugin
/sfnext-accessibilityBuild and fix accessible UI in a Storefront Next storefront (WCAG 2.1 AA): jsx-a11y lint findings, missing accessible names and labels, form error association, dialog focus management, aria-live status messages, keyboard behavior, color contrast, and verifying fixes with Storybook a11y/play() tests and the e2e axe scan with its baseline. Use for "accessibility", "a11y", "WCAG", "screen reader", "aria-label", "focus trap", "axe violation", pnpm lint:a11y, pnpm a11y, a11y-baseline.json, skip-a11y, STORYBOOK_A11Y_TEST_MODE, or an accessibility audit finding to fix. Do not use for general lint/typecheck gates (use `storefront-next:sfnext-quality-gates`), writing non-accessibility tests (use `storefront-next:sfnext-testing`), or color/token design (use `storefront-next:sfnext-theming`)./sfnext-analytics-consentStorefront Next analytics: engagement adapters (Einstein, Active Data, Data 360), adding a custom adapter, tracking consent gating, PageViewTracker, useAnalytics events, and first-touch attribution (dw_attribution). Use when configuring engagement.adapters in config.server.ts, writing an adapter with hasConsent, registering it in initializeEngagementAdapters, wiring the consent banner (trackingConsent, consentCategories, dw_dnt), firing trackViewProduct/trackCartItemAdd events, debugging why no analytics events are sent, or passing campaign attribution to orders. Do not use for general config loading or env vars (use `storefront-next:sfnext-configuration`), CSP/script allowlisting of third-party tags (use `storefront-next:sfnext-security`), or SEO meta/JSON-LD (use `storefront-next:sfnext-seo`)./sfnext-authenticationWork with Storefront Next's server-only authentication and session architecture (SLAS guest/registered tokens, httpOnly cookies, auth.server.ts middleware). Use for getAuth, useAuth, updateAuth, destroyAuth, protecting account routes, login/logout actions, guest-to-registered basket/wishlist merge, "session expired" redirects, 401 recovery loops, cc-at/cc-nx/usid/dwsid cookies, cookie names or expiry, passwordless login, social login, OTP email verification, passkeys, guest order lookup, or refresh-token lifetime settings. Do not use for Turnstile, CSP headers or cookie-domain config (use `storefront-next:sfnext-security`), calling SCAPI clients (use `storefront-next:sfnext-scapi`), or sharing sessions with SFRA (use `storefront-next:sfnext-hybrid-storefronts`)./sfnext-commerce-featuresCatalogue and router for optional Storefront Next commerce features: Shopper Context (qualifiers, source codes), Order Management returns/cancel/tracking (SOM/OMS), delivery estimates, feature stubs (@feature-stub), guest order lookup, the app_storefrontnext_base email cartridge, and the shipped extensions (bnpl, bopis, multiship, store-locator, ratings-reviews, customer-preferences, product-content, shipping-delivery, theme-switcher). For each: which flag, SLAS scope, Business Manager setting, cartridge, or extension registry entry it needs, and which in-project doc to read. Use when asked how to enable a feature, why a feature does not render, what prerequisites a feature has, or which stubs are mock data. Do not use for building a new extension (use `storefront-next:sfnext-extensions`), config loading (use `storefront-next:sfnext-configuration`), or SLAS login flows (use `storefront-next:sfnext-authentication`)./sfnext-componentsBuild and modify UI components in a Storefront Next storefront: page components with Suspense and use()/Await, createPage and withSuspense, Tailwind v4 token classes, shape tokens (rounded-ui, shadow-ui, border-ui), shadcn/ui primitives in src/components/ui (sync-shadcn), CVA variants, data-slot, DynamicImage, lazy-loaded overlays, and Storybook stories with snapshot tests. Use when creating or editing a component in src/components, adding a shadcn primitive, fixing styling that ignores the theme, writing a *.stories.tsx file, or running pnpm storybook:test. Do not use for re-branding colors, fonts, or logos (use `storefront-next:sfnext-theming`), route loaders (use `storefront-next:sfnext-data-fetching`), or Page Designer registration (use `storefront-next:sfnext-page-designer`)./sfnext-configurationConfigure a Storefront Next app: config.server.ts (defineConfig, metadata/runtime/app), AppConfig types in src/types/config.ts, PUBLIC__ environment variable overrides, getConfig(context) / useConfig(), extension config (app.extension, app.serverExtension), protected paths, server-only secrets, and multi-site settings (commerce.sites, url.prefix, seoRoutes, siteAliasMap, cookie domain). Use when editing config.server.ts, adding a config value, an env var is ignored or "not applied", `pnpm config:inspect` / `config:push-env`, "Ignoring environment variable" warnings, protected config path errors, setting up a second site or locale URLs, or going through the pre-launch config checklist. Do not use for creating a project or the npm script list (use `storefront-next:sfnext-project-setup`), pushing bundles or MRT env management (use `storefront-next:sfnext-deployment` / `b2c-cli:b2c-mrt`), or hybrid proxy and cookie-sharing with SFRA (use `storefront-next:sfnext-hybrid-storefronts`).Other plugins' skills for the same job