/spree-commerce:spree-securityfrom spree-commerce
Audits and hardens Spree e-commerce deployments: Rails credentials, Devise auth, CanCanCan permissions, Doorkeeper OAuth2 scopes, API key tiers, webhook HMAC, OWASP Top 10 for Rails, PCI scope, and multi-store isolation.
Ships in spree-commerce. 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.
None: SKILL.md is the whole skill.
Fetch live docs:
Spree::Ability (CanCanCan) in the live source for current default permissions.config/initializers/devise.rb.config/initializers/doorkeeper.rb.| Layer | Tool |
|---|---|
| Customer authentication | Devise (v5 ships in-core; spree_auth_devise is archived) |
| Admin authentication | Same Devise system; differentiation via Spree::Role |
| Authorization | CanCanCan via Spree::Ability |
| API auth (v3 Store) | Publishable key + per-user JWT |
| API auth (v3 Admin) | Per-user API key + OAuth2 (Doorkeeper) |
| API auth (v2 legacy) | OAuth2 (Doorkeeper) password + client_credentials grants |
| OAuth2 server | Doorkeeper |
| CSRF | Rails default — required for HTML, exempted for API |
spree_auth_devise Is DeprecatedThe standalone spree_auth_devise gem is archived as of Feb 2026. Spree v5+ ships Devise auth in the core gem. Do NOT install the old gem on new projects — it conflicts and creates a maintenance burden.
# app/models/spree/ability.rb
class Spree::Ability
include CanCan::Ability
def initialize(user)
user ||= Spree.user_class.new
if user.has_spree_role?(:admin)
can :manage, :all
elsif user.has_spree_role?(:order_manager)
can :manage, Spree::Order
else
can :read, [Spree::Product, Spree::Taxon]
end
end
end
Extend via decorator — don't replace.
| Token type | Scope | Where stored |
|---|---|---|
Publishable key (pk_…) | Read-only public catalog + cart endpoints | Browser env (NEXT_PUBLIC_*) — safe |
| User JWT | Customer's account, their orders | httpOnly cookie server-side |
Cart token (order_token) | Anonymous cart only | httpOnly cookie server-side |
| Admin API key | Per-user admin scope | Server env vars or vault — never to browser |
| OAuth2 access token (admin scope) | App integration | Server-to-server only |
Webhooks 2.0 signs with HMAC-SHA256 over the raw body using a per-endpoint shared secret. Always verify:
def verify(body, header, secret)
expected = OpenSSL::HMAC.hexdigest('SHA256', secret, body)
ActiveSupport::SecurityUtils.secure_compare(expected, header.sub(/^sha256=/, ''))
end
Use secure_compare — never == (timing attack).
| Risk | Spree-specific mitigation |
|---|---|
| A01 Broken access control | CanCanCan Spree::Ability — never skip authorize!. Multi-store scoping. |
| A02 Cryptographic failures | Rails credentials. TLS everywhere. No secrets in YAML. |
| A03 Injection | ActiveRecord parameterization. Ransack: lock ransackable_attributes. |
| A04 Insecure design | Don't accept user-supplied IDs without ownership check. Use prefixed IDs. |
| A05 Misconfiguration | config.force_ssl = true. config.action_controller.default_url_options = { protocol: 'https' }. |
| A06 Vulnerable deps | bundler-audit, brakeman in CI. |
| A07 ID&A failures | Devise default rate-limits. Add 2FA via devise-two-factor. |
| A08 Software integrity | Pin gem versions. Verify gem signatures where supported. |
| A09 Logging | Filter params: Rails.application.config.filter_parameters += [:password, :credit_card]. |
| A10 SSRF | Never Net::HTTP.get(params[:url]). |
API v2 filters use Ransack (filter[status_eq]=complete). By default, all columns and associations are filterable. Lock down per-model:
# app/models/spree/order_decorator.rb
module SecureOrderRansack
def self.prepended(base)
base.class_eval do
def self.ransackable_attributes(_auth = nil)
%w[number state payment_state shipment_state created_at]
end
def self.ransackable_associations(_auth = nil)
%w[user line_items]
end
end
end
end
Spree::Order.prepend(SecureOrderRansack)
Without this, attackers can filter by sensitive columns (passwords, tokens).
API v3's prefixed IDs (prod_…, ord_…) are opaque strings — they don't expose row counts (sequential integers do). But always pair with ownership checks:
order = current_store.orders.find(params[:id]) # scoped lookup
Not:
order = Spree::Order.find(params[:id]) # IDOR risk
Spree's never touches raw card numbers when configured correctly:
tok_…, pm_…, etc.)Don't build a custom card form that sends params[:card_number] to Rails. That escalates PCI scope dramatically.
As covered in spree-multi-store, always scope queries by current_store. A single missed scope can leak another tenant's orders.
Configure in config/initializers/devise.rb:
config.password_length = 12..128
config.maximum_attempts = 5
config.unlock_in = 30.minutes
config.timeout_in = 30.minutes
Add zxcvbn-style strength via devise_zxcvbn if needed.
Spree doesn't ship 2FA, but Devise extensions add it:
gem 'devise-two-factor'
Or use WebAuthn (webauthn-ruby) for hardware-key auth on admin accounts.
RAILS_MASTER_KEY unlocks config/credentials.yml.encconfig/master.key — gitignore itclass Spree::Api::V3::BaseController < ActionController::API
# ActionController::API doesn't include CSRF protection — correct for APIs
end
But never disable CSRF on HTML controllers (admin UI). Default Rails CSRF tokens protect admin from cross-origin attacks.
Spree's per-endpoint API rate limiting is built in (v5+). For brute-force protection on admin login, layer rack-attack:
# config/initializers/rack_attack.rb
Rack::Attack.throttle('admin_login', limit: 5, period: 15.minutes) do |req|
req.ip if req.path == '/admin/login' && req.post?
end
config.force_ssl = true + HSTS headersRAILS_MASTER_KEY in vault (not in code)can :manage, :all outside admin roleransackable_attributes locked per exposed modelbundler-audit and brakeman clean in CIconfig.filter_parameters includes password, token, secret, credit_cardContent-Security-Policy)- run: bundle exec brakeman -q --no-pager --exit-on-warn
Treat new findings as build failures.
bundle exec bundler-audit check --update
Run on every CI build and weekly via scheduled job.
# Wrong — secret in code
ApiClient.new('sk_live_…')
# Right
ApiClient.new(Rails.application.credentials.dig(:my_service, :api_key))
# Also right
ApiClient.new(ENV.fetch('MY_SERVICE_API_KEY'))
spree_auth_devise to a v5 project — archived gem; conflicts.current_store.orders scoping — leaks across stores.localStorage — XSS-exfiltratable.skip_before_action :authenticate_user! — accidental backdoor.Always cross-reference the Spree security advisories page and rubysec.com for the gems your Spree version depends on.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
spree, ecommerce-security, rails-security, owasp-top-10, pci-compliance
npx claudepluginhub orcaqubits/agentic-commerce-skills-plugins --plugin spree-commerce22 skills in this plugin
/spree-admin-customizationCustomize the Spree v5 Admin Dashboard — Tailwind 4 + Hotwire/Turbo/Stimulus stack, the `Spree.admin.navigation` declarative API (v5.2+) for menu items, partial injection slots (`store_nav_partials`, `store_products_nav_partials`, `store_orders_nav_partials`, `settings_nav_partials`), the Admin SDK components + form builder, custom dashboard reports, the Page Builder for storefront editing, and theme management. Use when adding admin pages, injecting UI into existing screens, or building admin extensions./spree-api-v3Build with Spree's v3 APIs (v5.4+) — Store API at `/api/v3/store/*` (publishable key + per-user JWT, customer-facing) and Admin API at `/api/v3/admin/*` (per-user API keys + OAuth2 Doorkeeper, admin/operations). Covers the flat-JSON Stripe-like envelope, `?expand=` / `?include=` parameters, prefixed IDs (`prod_…`, `ord_…`), OpenAPI 3.0 spec, rate limiting, idempotency, and migration from v2 JSON:API. Use when building API clients, SDKs, or extending API endpoints in a Spree v5.4+ deployment./spree-catalogBuild and customize Spree's catalog — Products with Variants and OptionTypes/OptionValues, Taxonomies and Taxons (nested set), Properties, Images via ActiveStorage, multi-currency Prices, the v5.3+ PriceList feature for customer/segment overrides, MeiliSearch faceted search (v5.4+), product archiving/activation, CSV import/export, and SEO. Use when modeling products, customizing the catalog UI, indexing search, or importing inventory.Other plugins' skills for the same job