Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

sfnext-security

БесплатноБез исполняемых скриптовНе проверен

Configure Storefront Next security response headers, Content Security Policy (CSP), CSP contributors, Cloudflare Turnstile bot protection, and the shared…

SalesforceCommerceCloudот 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 remove reportOnly. A startup warning is logged while it is on.
  • Disable one header with 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.

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; toCspOrigin returns null for 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.ts like 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

Полный SKILL.md на GitHub

Установить sfnext-security в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

evals/trigger-evals.jsonreferences/COOKIE-DOMAIN.mdreferences/TURNSTILE.md

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), без исполняемых скриптов.

Похожие скиллы

Сравнить sfnext-security с