Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Drop Spree::PermittedAttributes, add a model-level extension hook
Status: Implemented
Target: Spree 6.0
Depends on: 6.0-admin-api.md (v3 flat-params conventions), 6.0-store-scoped-custom-field-definitions.md
Author: Damian
Last updated: 2026-08-20
Summary
Spree::PermittedAttributes is a global mutable allowlist of 66 attribute lists, created so host apps and extensions could add writable attributes from an initializer instead of decorating controllers. It was built for the Rails admin and storefront, both of which are gone. API v3 permits attributes inline in controllers, and merchant-added data is now served by Custom Fields, which are sortable and filterable. The registry is close to dead already: only five of its 66 keys are read by name anywhere in the codebase, and the composed ControllerHelpers::StrongParameters helpers built on top of it are called from nowhere at all.
We delete the registry and the helper module, and replace the one capability they still uniquely provided — declaring an extra writable attribute on a plain core resource — with an additional_permitted_attributes class_attribute on Spree::Base that v3 controllers append to their inline allowlist. Extensions still declare from an initializer — the ergonomics that made the registry popular — but against the model rather than a global hash, so the list is scoped, discoverable, and cannot be reached by code that has no business touching another resource. It also generalizes a convention already copy-pasted into four rule base classes.
Key Decisions (do not deviate without discussion)
Spree::PermittedAttributesis deleted outright at 6.0, with no deprecation bridge. This is a recorded exception to the deprecation-bridges convention. The constant is not being renamed — it is being removed along with the mechanism that consumed it, so there is nothing to warn-and-delegate to. Handled as a documented clean break in the upgrade guide, like the CSVshipping_categoryremoval in6.0-fulfillment-and-delivery.md.Spree::Core::ControllerHelpers::StrongParametersis deleted and itsincluderemoved fromSpree::BaseControllerandApi::V3::BaseController. Nothing in the codebase calls any of its methods.additional_permitted_attributesis aclass_attributeonSpree::Base, defaulting to[]. Extensions append from an initializer —Spree::Product.additional_permitted_attributes += [:brand_id]— which keeps the ergonomics of the registry it replaces (one line, no decorator) while scoping the list to one model instead of a global hash. Always+=, never=: assigning replaces what another extension added.- The union happens in
ResourceController#permitted_attributes, which appendsmodel_additional_permitted_attributesto the subclass'sresource_permitted_attributes. Subclasses overrideresource_permitted_attributes(the plain list); overridingpermitted_attributesbypasses the union and is wrong. normalize_paramsis NOT the union point, and normalization is not universal. An early cut applied the union insidenormalize_paramson the theory that every write funnels through it. It does not: 63 write controllers deliberately never normalize. Worse, normalization is not a neutral pass —resolve_prefixed_idsrecurses into nested hashes decoding anything matching/\A[a-z]+_[a-zA-Z0-9]+\z/under a*_idkey, so enrolling a controller into it corrupts opaque provider values. A Stripewebhook_endpoint_idofwe_1MqJ8bLkdIwHu7ixIhqHQfbodecodes to2345514981514645561106. Controllers carrying gatewaypreferencesor merchantmetadatamust never normalize.- Controllers that override
permitted_paramssplatmodel_additional_permitted_attributesinto their ownparams.permit. This preserves each controller's existing normalization behavior — a one-line addition, not a restructuring. Two credential endpoints (api_keys,invitations) are deliberately excluded: their parameters are the authorization surface, not extensible resource data. - The registry's name-inference fallback is removed.
resource_permitted_attributesraisesNotImplementedErrorwhen undeclared, matchingmodel_classandserializer_class. Silent inference from a model name is what let attribute lists drift out of sight. - Core STI subclasses assign in the class body (
self.additional_permitted_attributes = [product_ids: []]), whichclass_attributescopes to that subclass while leaving the parent's value alone. The eight existing method-style overrides were converted to assignments so one mechanism covers both core declarations and extension appends. - The hook is for extension-added columns only. Core attributes stay in the controller's inline
params.permit. A core model must never declare its own base attributes through this hook — that would recreate the registry one class at a time. - Custom Fields remain the recommended path for merchant-added data. The hook is documented as the fallback for extensions that add real database columns, not as the default extension story.
Design Details
Current state
The registry has three consumer paths, all of which are being removed:
- Five explicit Store API reads —
wishlists,wishlist_items,carts/payment_sessions,carts/items,customer/payment_setup_sessions. Plus one inSpree::Carts::AddItem, which flattensline_item_attributesto filter incoming options. - The inference fallback in
ResourceController#permitted_attributes, which derives a key from the model name viapublic_send. Nearly every admin controller that reaches it is read-only; the four with real write actions (customers/addresses,orders,admin_users,stock_transfers) all define their own inline permits and never touch it. ControllerHelpers::StrongParameters, which delegates all 66 keys and defines six composed helpers (permitted_checkout_attributes,permitted_product_attributes, …). Zero callers. Its composed helpers describe nested-attributes payload shapes (bill_address_attributes,payments_attributes) that v3 explicitly rejected with its flat-params rule.
The registry also has a demonstrated failure mode: because the same attribute must be listed in several disconnected places, a variant attribute had to be permitted in three of them or one write path silently discarded it — see 6.0-duties-and-custom-fees.md. A single global list that is not actually the single source of truth is worse than no list.
The hook
On Spree::Base:
# Extra writable attributes contributed by extensions, appended to the v3
# controller allowlist for this resource.
#
# Spree::Product.additional_permitted_attributes += [:brand_id]
#
# Entries are `params.permit` fragments: bare symbols, or hashes for
# collections and nested structures (`{ region_ids: [] }`).
class_attribute :additional_permitted_attributes, instance_writer: false, default: [].freeze
Extensions declare from an initializer, the same place the old registry was fed:
# config/initializers/spree.rb
Spree::Product.additional_permitted_attributes += [:brand_id]
No decorator, no registration step. class_attribute gives per-class storage
with inheritance, so appending to Spree::Product leaves Spree::Variant and
Spree::Base untouched, and a core STI subclass can assign its own value
(self.additional_permitted_attributes = [product_ids: []]) without disturbing
its parent.
Controller wiring
ResourceController gains a two-level split: the subclass declares its own list,
the base appends what extensions contributed.
def permitted_params
normalize_params(params.permit(*permitted_attributes))
end
# Resource list + extension contributions. Subclasses override
# `resource_permitted_attributes`, never this.
def permitted_attributes
resource_permitted_attributes + model_additional_permitted_attributes
end
def resource_permitted_attributes
raise NotImplementedError, 'Subclass must implement resource_permitted_attributes or permitted_params'
end
def model_additional_permitted_attributes
return [] unless respond_to?(:model_class, true)
model = model_class
return [] unless model.respond_to?(:additional_permitted_attributes)
Array(model.additional_permitted_attributes)
rescue NotImplementedError
[]
end
A controller that overrides permitted_params outright bypasses that path, so it
splats the extras into its own call:
def permitted_params
params.permit(*model_additional_permitted_attributes, :name, :active)
end
Three consequences to handle deliberately:
- Overriding
permitted_attributessilently drops extension attributes. That method is the union;resource_permitted_attributesis the override point. Nothing enforces this, which is why it is called out in CLAUDE.md. - Do not enroll a controller into
normalize_paramsto get the union. The splat gets the same result without changing parameter semantics. Normalization decodes prefixed IDs recursively through nested hashes, which corrupts gatewaypreferencesand merchantmetadata(see Key Decisions), and hands the action already-decoded primary keys — so afind_by_prefix_id!in that action must read rawparamsor become a plainfind. - Both guards in
model_additional_permitted_attributesare load-bearing: a controller need not definemodel_class(therespond_to?check plus theNotImplementedErrorrescue), andSpree.base_classis host-overridable, so the hook is not guaranteed to be inherited fromSpree::Base.
The four existing rule classes
Spree::PromotionRule, Spree::PromotionAction, Spree::DeliveryMethodRule and Spree::CommissionRule each define their own identical additional_permitted_attributes default. Once Spree::Base carries it, those four definitions are redundant and get deleted; the inherited default takes over. Their STI subclasses keep their overrides untouched.
Their consuming controllers are a different mechanism and stay as they are: PromotionsController#subclassed_collection_attributes and the delivery-method-rules equivalent walk a subclass registry and union across every registered type, because the controller writes an STI base and cannot know which subclass a request targets. The new ResourceController union asks a single model_class. Both can coexist — the registry walk is for polymorphic writes, the model hook is for the concrete resource. The three respond_to? guards in those controllers become redundant and can be dropped in the same pass.
What replaces each old use
| Old use | Replacement |
|---|---|
| Merchant adds a data field | Custom Fields (sortable/filterable since 5.6) |
| Extension adds a column to a core model | additional_permitted_attributes on the model |
| Extension adds an STI rule/action type | additional_permitted_attributes + registry registration (unchanged) |
| Core attribute lists | Inline params.permit in the controller (unchanged) |
Migration Path
- Add the hook. Define
additional_permitted_attributesonSpree::Base. Delete the four redundant copies on the rule base classes. - Wire the union into
ParamsNormalizer#normalize_params, and replace the inference fallback inResourceController#permitted_attributeswithNotImplementedError. Run the API suite: any write controller that was silently relying on inference now fails loudly, which is the point. One did —admin/tax_categories_controllerhad full CRUD and no allowlist of its own; it now declares[:name, :tax_code, :description, :is_default]. - Inline the five Store API reads.
wishlists,wishlist_items,carts/payment_sessions,carts/items,customer/payment_setup_sessions. Each list is short and moves verbatim into the controller. - Handle
Carts::AddItem. It readsline_item_attributesto filter incoming option keys, so it needs a home for that list that is not a controller. Put it onSpree::LineItemas a constant and have both the workflow andcarts/items_controllerread it. - Convert
params.permitcall sites that skipnormalize_paramsso the union reaches them — these opt out otherwise. Controllers that already normalize need no change regardless of how they build their list. - Delete
ControllerHelpers::StrongParameters, itsincludein both base controllers, itsrequire_dependency, andspree/core/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb. - Delete
spree/core/lib/spree/permitted_attributes.rband anyrequireof it. - Docs. Rewrite the
Permitted Attributessection ofdocs/developer/customization/api.mdx; update thebrand_idexamples indocs/developer/tutorial/extending-models.mdx(two places) anddocs/developer/tutorial/api.mdx. - Upgrade guide. Add a breaking-change entry to
docs/developer/upgrades/5.6-to-6.0.mdxcovering the constant removal, the helper-module removal, and theadditional_permitted_attributesreplacement with a before/after example. - Specs. Cover the union in
ResourceController(an extension-declared attribute is writable; an undeclared one is dropped), and confirmNotImplementedErrorwhen neitherpermitted_attributesnorpermitted_paramsis defined.
Constraints on Current Work
- Do not add new keys to
Spree::PermittedAttributes, and do not read it in new code. - New v3 controllers declare
permitted_attributes(a plain list) rather than overridingpermitted_params, unless the controller genuinely needs a bespoke builder. Overridingpermitted_paramsopts out of the extension union. - Do not rely on the model-name inference fallback — it is being removed. Every write controller states its own list.
- A core model must not declare its own base attributes via
additional_permitted_attributes. That hook is for extensions. - Extensions being written now against
PermittedAttributesshould be pointed atadditional_permitted_attributesinstead.
Open Questions
- Whether the two
admin/products_controllerinlinevariants: [...]lists and the nestedAdmin::Products::VariantsControllerlist should be consolidated as part of this work. The three-places problem from6.0-duties-and-custom-fees.mdis adjacent but not caused by the registry, and fixing it here would widen the change. Leaning toward a separate follow-up. - Whether the remaining
params.permitcall sites that bypassnormalize_paramsshould be converted in bulk. They opt out of the extension union, but converting them is unrelated churn; the position taken here is to convert them as they are touched.
Resolved during implementation: the option-key list Carts::AddItem needs now lives on Spree::LineItem::WRITABLE_ATTRIBUTES, read by both the workflow and the Store API items controller. Note that the old code did line_item_attributes.flatten, which left the literal { metadata: {} } hash as an options key — meaningless, and surviving only because a later delete_if dropped nils. The constant holds the three scalar keys that were actually doing work.
References
docs/plans/6.0-admin-api.md— v3 flat-params conventionsdocs/plans/6.0-duties-and-custom-fees.md— the three-places failure that motivated distrusting the global listdocs/plans/6.0-delivery-method-rules.md,docs/plans/6.0-extendable-validations.md— theadditional_permitted_attributesprecedent and the decorators-stay-the-additive-path positionspree/core/lib/spree/permitted_attributes.rb,spree/core/lib/spree/core/controller_helpers/strong_parameters.rb— the code being removed