sfnext-security
БесплатноБез исполняемых скриптовНе проверенConfigure Storefront Next security response headers, Content Security Policy (CSP), CSP contributors, Cloudflare Turnstile bot protection, and the shared…
от SalesforceCommerceCloud★ 58 звёзд на GitHubОб этом скилле
Storefront Next Security
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.
Default headers
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).
Allow a new third-party origin
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
Roll out or relax safely
- Migrating or adding many origins: set
csp: { reportOnly: true }, watch DevTools violations, extend the directives, then removereportOnly. A startup warning is logged while it is on. - Disable one header with
hsts: falseorpermissionsPolicy: false.headers: { enabled: false }disables everything; use it for debugging only. A startup warning is logged whenever any header is disabled.
CSP contributors
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:
- Derive origins from config you already have;
toCspOriginreturnsnullfor unsafe values. - The runtime validates contributors at boot: https only, no wildcards, no credentials, no whitespace.
- Contribute only while the feature is active, so disabled features never widen the policy.
- Add a colocated
*.test.tslike the shipped ones.
Use a contributor for a feature toggled by config; use the defaultCspDirectives spread for one-off origins.
Turnstile bot protection
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, `disable
Установить sfnext-security в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл sfnext-security?
Configure Storefront Next security response headers, Content Security Policy (CSP), CSP contributors, Cloudflare Turnstile bot protection, and the shared cookie domain. Use for "Refused to load the script/connect/image" CSP violations, adding a third-party origin, app.security.headers, defaultCspDirectives, csp reportOnly rollout, writing a CSP contributor under src/middlewares/csp-contributors, HSTS or Permissions-Policy, Turnstile widget or enforceTurnstile, TURNSTILE_SECRET_KEYS, log-only rollout, or app.cookies.domain across subdomains. Do not use for auth tokens, cookie names or login flows (use `storefront-next:sfnext-authentication`), SFRA proxy routing (use `storefront-next:sfnext-hybrid-storefronts`), or consent banners and tracking (use `storefront-next:sfnext-analytics-consent`).
Как установить скилл sfnext-security?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл sfnext-security запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic