Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Redact newsletter verification_token from webhook deliveries (F4, F7)

Damian Legawiec15ef9eb012c0
diff --git a/spree/core/app/models/concerns/spree/webhook_payload_redaction.rb b/spree/core/app/models/concerns/spree/webhook_payload_redaction.rb
index 1b2456ac2d..83d5b2d8a3 100644
--- a/spree/core/app/models/concerns/spree/webhook_payload_redaction.rb
+++ b/spree/core/app/models/concerns/spree/webhook_payload_redaction.rb
@@ -17,7 +17,7 @@ module Spree
extend ActiveSupport::Concern
# Payload keys under `data` whose values are live credentials.
- SENSITIVE_PAYLOAD_KEYS = %w[reset_token unsubscribe_token].freeze
+ SENSITIVE_PAYLOAD_KEYS = %w[reset_token unsubscribe_token verification_token].freeze
REDACTION_PLACEHOLDER = '[REDACTED]'
diff --git a/spree/core/spec/models/concerns/spree/webhook_payload_redaction_spec.rb b/spree/core/spec/models/concerns/spree/webhook_payload_redaction_spec.rb
index 55f5626d80..359266694c 100644
--- a/spree/core/spec/models/concerns/spree/webhook_payload_redaction_spec.rb
+++ b/spree/core/spec/models/concerns/spree/webhook_payload_redaction_spec.rb
@@ -26,6 +26,22 @@ describe Spree::WebhookPayloadRedaction do
expect(described_class.merge(payload, secrets)).to eq(original)
end
+ # The newsletter double opt-in event carries a live has_secure_token that
+ # must never land in the persisted delivery log.
+ it 'redacts the newsletter verification_token and re-attaches it at send time' do
+ original = {
+ 'name' => 'newsletter_subscriber.subscription_requested',
+ 'data' => { 'email' => '[email protected]', 'verification_token' => 'live-token' }
+ }
+
+ payload, secrets = described_class.split(original)
+
+ expect(payload['data']['verification_token']).to eq(placeholder)
+ expect(payload['data']['email']).to eq('[email protected]')
+ expect(secrets).to eq('verification_token' => 'live-token')
+ expect(described_class.merge(payload, secrets)).to eq(original)
+ end
+
it 'returns the payload untouched when nothing is sensitive' do
original = { 'data' => { 'number' => 'R123' } }