Allow operator-trusted internal hosts for webhook endpoints (SSRF guard has no opt-in)
Is your feature request related to a problem? Please describe.
Spree blocks webhook URLs that resolve to private addresses in two places:
Spree::WebhookEndpoint#url_must_not_resolve_to_private_iprefuses to save them: "Url must not point to an internal or private network address".Spree::Webhooks::DeliverWebhook#make_requestsends every non-development delivery throughSsrfFilter.post, which fails withHostname '10.43.0.15' has no public ip addresses.
That's the right default for URLs entered in the admin. But there's no way to opt a destination you run yourself back in. A common setup: Spree and the storefront (e.g. the Next.js storefront, which consumes order webhooks for transactional email) run in the same Kubernetes cluster, and the webhook targets the storefront's internal Service (http://storefront.<ns>.svc.cluster.local/api/webhooks/spree, a 10.x ClusterIP). Today the only way to make that work is to override the private make_request method and skip validation on save. That override breaks whenever make_request changes. On main it already would, since the signed body is now payload_json / deliverable_payload and header_decorators were added.
It also fails silently. An endpoint saved with validate: false shows as active with the right subscriptions, and Sidekiq logs the job as done. Only Spree::WebhookDelivery#success == false shows that nothing arrived. So an endpoint that transactional email depends on (order confirmations, password resets) can stay broken unnoticed until someone inspects the delivery records.
Reproduced on main (53d9925):
url = 'http://10.43.0.15/api/webhooks/spree'
endpoint = build(:webhook_endpoint, store: store, url: url)
endpoint.valid? # => false, "Url must not point to an internal or private network address"
endpoint.save!(validate: false)
delivery = create(:webhook_delivery, :pending, webhook_endpoint: endpoint)
Spree::Webhooks::DeliverWebhook.call(delivery: delivery, secret_key: endpoint.secret_key)
delivery.reload
# success=false error_type="connection_error"
# request_errors="Hostname '10.43.0.15' has no public ip addresses"Spree::Api::Configuration has only webhooks_enabled and webhooks_verify_ssl. There's nothing to allow a trusted internal host.
Describe the solution you'd like
An operator-level allowlist, e.g.
preference :webhooks_allowed_internal_hosts, :array, default: [], env: 'SPREE_WEBHOOKS_ALLOWED_INTERNAL_HOSTS'matched on host (exact match, or a suffix like .svc.cluster.local). It would be honoured in both places:
- the endpoint validation skips the private-IP check for an allowed host;
DeliverWebhook#make_requestuses the existing plainNet::HTTPbranch (the one already used in development) for an allowed host, andSsrfFilterfor everything else.
Because it's set in config or an ENV var, not in the admin, a store admin still can't point a webhook at an internal address. The SSRF protection stays in place for every destination the operator hasn't listed.
Describe alternatives you've considered
- Prepending a decorator over
make_request. It's fragile across releases, as above. - Sending through a public ingress. That leaves the cluster and comes back just to get past the check, and exposes the webhook receiver publicly.
Rails.env.development?. Not an option in production.
Additional context
Present in 5.6.1; the behaviour is unchanged on main (6.0.0.beta4). Happy to open a PR if the approach sounds right.
Source: spree/spree