dist/codex/salesforce-commerce/skills/sf-security/SKILL.md
Implement Salesforce Commerce security — SLAS OAuth 2.1, session management, CSRF tokens, XSS prevention (isprint encoding in ISML), PCI compliance, RBAC in Business Manager, OWASP Top 10 protections, and Salesforce Shield for B2B. Use when implementing authentication or security controls.
npx skillsauth add orcaqubits/agentic-commerce-claude-plugins sf-securityInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Implement Salesforce Commerce security across B2C and B2B platforms.
Always fetch the latest official documentation BEFORE implementing security controls:
Why: OAuth flows, CSRF protection patterns, encoding modes, and PCI requirements evolve. Live docs ensure correct implementation of current security standards.
SLAS (B2C Commerce) -- OAuth 2.1 with PKCE:
| Client Type | Flow | Use Case |
|-------------|------|----------|
| Public (browser/PWA Kit) | authorization_code_pkce | Guest and registered users |
| Private (server-side) | client_credentials | Guest sessions |
| Private (server-side) | authorization_code | Registered users |
| Any | Refresh token | Session extension |
PKCE (Proof Key for Code Exchange) is required for all public client flows. Guest tokens enable anonymous shopping before login.
Salesforce OAuth (B2B Commerce):
| Flow | Use Case | |------|----------| | Connected Apps | OAuth application registration | | JWT Bearer | Server-to-server authentication | | Web Server Flow | User authorization with redirect |
Session Management:
Token Lifecycle:
| Token | Typical TTL | Storage | |-------|-------------|---------| | Access Token | 30 minutes | Memory or httpOnly cookie | | Refresh Token | 30 days | httpOnly cookie (never localStorage) | | CSRF Token | Per request | Hidden form field or custom header |
B2C Commerce (ISML):
| Encoding Mode | Context |
|---------------|---------|
| htmlcontent | HTML body text |
| htmlsinglequote / htmldoublequote | HTML attributes |
| jshtml | JavaScript strings in HTML |
| jsonvalue | JSON data |
| uricomponent | URL parameters |
Always use <isprint> with explicit encoding. Never use raw ${variable} for user-controlled data. Set Content Security Policy headers to restrict script sources.
B2B Commerce (LWC):
textContent instead of innerHTML in JavaScriptlightning-formatted-* components for safe rendering| Directive | Purpose |
|-----------|---------|
| default-src | Fallback for all resource types |
| script-src | Allowed script sources (restrict to self and trusted CDNs) |
| style-src | Allowed stylesheet sources |
| img-src | Allowed image sources |
| connect-src | Allowed API/fetch targets |
| frame-ancestors | Clickjacking protection |
Configure CSP headers in Business Manager or via server configuration. Use nonce or hash for inline scripts rather than unsafe-inline.
B2C Commerce: Validate tokens with CSRFProtection.validateRequest() in controllers. Generate tokens with CSRFProtection.generateToken(). Include hidden token fields in all state-changing forms. Use double-submit cookie pattern for AJAX.
B2B Commerce: Built-in Salesforce CSRF protection. <lightning-input> includes tokens automatically. @AuraEnabled Apex methods have CSRF protection.
| Layer | Technique | |-------|-----------| | Client-side | HTML5 validation, JavaScript checks (UX only, not security) | | Server-side | Whitelist validation, type checking, length limits | | Form definitions | SFCC XML form definitions with validation rules | | Query API | Parameterized queries -- never string concatenation |
Always validate on the server. Client-side validation is a convenience, not a security measure.
| Requirement | Implementation | |-------------|---------------| | Tokenization | Never store raw card numbers; use tokenized payment methods | | SAQ-A Scope | Use hosted payment fields to minimize PCI scope | | TLS 1.2+ | Enforce for all API communication and payment processing | | Log Masking | No card data in application logs | | Gateway | Use Salesforce Commerce Payments or validated third-party processors |
B2C Commerce: Business Manager roles (Admin, Merchant, Content) with granular, site-specific permissions. Custom roles for organization-specific needs.
B2B Commerce: Salesforce profiles and permission sets. Buyer permissions control ordering (browse, cart, checkout, approve). Account hierarchy restricts visibility based on relationships.
B2B Sharing Rules:
| Threat | Mitigation | |--------|------------| | Injection | Parameterized queries via Query API; input whitelisting | | Broken Auth | SLAS/OAuth best practices; MFA where available; strong password policies | | Sensitive Data Exposure | Salesforce Shield encryption at rest (B2B); TLS in transit; log masking | | Security Misconfiguration | Disable dev features in production; change default credentials; suppress stack traces | | Access Control | Authorization checks on every request; least privilege principle | | Monitoring | Log authentication events, failed logins, suspicious activity |
Fetch the SLAS OAuth 2.1 guide, B2C Commerce security reference, and Salesforce OWASP documentation for exact token flows, encoding specifications, and compliance requirements before implementing.
development
Build with Spree's headless Next.js storefront — the official `spree/storefront` repo (Next.js 16 App Router with Server Actions and Turbopack, React 19 Server Components, Tailwind CSS 4, TypeScript 5, `@spree/sdk`, Sentry), server-only auth (httpOnly JWT cookies + publishable key), MeiliSearch faceted catalog, one-page checkout with Apple/Google Pay/Klarna/Affirm/SEPA, multi-region market routing, GA4 + JSON-LD SEO, and Vercel/Docker deployment. Use when forking or customizing the storefront, or evaluating headless adoption.
tools
Build Spree extensions as Rails engines — gem scaffolding, `bin/rails g spree:extension`, mounting routes/migrations/assets, the modern `prepend` decorator pattern (`*_decorator.rb` with `self.prepended(base)`), generators (`spree:model_decorator`, `spree:controller_decorator`), the four customization surfaces in preference order (Events > Webhooks > Dependencies > Decorators), Spree::Dependencies for swapping service objects, gem release/versioning, and the deprecated Deface engine. Use when building a reusable Spree extension or adding non-trivial customization to an app.
development
Build with Spree's event bus and Webhooks 2.0 — `Spree::Events` publication, `Spree::Subscriber` DSL with `subscribes_to` and `on`, wildcard matching, lifecycle events (`{model}.created/.updated/.deleted` via `publishes_lifecycle_events`), the canonical event catalog (order.*, payment.*, shipment.*, product.*), Webhooks 2.0 endpoints, HMAC-SHA256 signing (`X-Spree-Webhook-Signature`), exponential-backoff retries, and Sidekiq job orchestration. Use when wiring event-driven business logic, building webhook consumers, or replacing ActiveSupport callback chains.
tools
Cross-cutting Spree development patterns — the customization preference hierarchy (Events > Webhooks > Dependencies > Decorators), `Spree::Dependencies` service-object swapping, the `_decorator.rb` + `prepend` + `self.prepended` idiom, idempotent subscribers and webhook receivers, multi-store scoping discipline, prefixed IDs, calculator polymorphism (shipping/promotion/tax share the base), service-object composition with `dry-monads` or simple results, why to avoid `class_eval` reopening and Deface, and Spree-on-Rails idioms (Hotwire/Turbo Stimulus, ActiveStorage, Action Cable, Sidekiq). Use when designing the architecture of a Spree extension or solving cross-cutting concerns.