fix(relay-kit): restrict URL signing to authorized MoonPay hosts in sign-url endpoint - #1116
Conversation
…ign-url endpoint ## Motivation This PR hardens the `sign-url` API endpoint in the `relay-kit` demo to prevent arbitrary URL signing. Previously, the endpoint lacked strict domain validation before generating HMAC SHA-256 signatures using the server-side MoonPay secret. This allowed potential abuse where the backend could be tricked into signing unauthorized or malicious URLs. By introducing an explicit allowlist, we ensure the server only signs legitimate MoonPay production and sandbox endpoints. ## Modifications * **Domain Allowlist & Protocol Validation (`demo/pages/api/sign-url.ts`)**: * Introduced a strict `MOONPAY_HOSTS` Set containing `buy.moonpay.com` and `buy-sandbox.moonpay.com`. * Added the `isAllowedMoonPayUrl` helper to verify that incoming URLs strictly use the `https:` protocol and match the authorized hostnames. * **Enhanced Error Handling (`demo/pages/api/sign-url.ts`)**: * Added robust `try-catch` URL parsing and early-exit HTTP `400 Bad Request` responses for malformed, non-string, or unauthorized URLs before any cryptographic operations are performed. ## Checklist - [x] Format your code according to the Contributor Guide. - [ ] Add unit tests as outlined in the Contributor Guide. - [x] Update documentation as needed, including docstrings or example tutorials.
|
@magqqgq is attempting to deploy a commit to the Uneven Labs Team on Vercel. A member of the Team first needs to authorize it. |
|
Motivation
This PR hardens the
sign-urlAPI endpoint in therelay-kitdemo to prevent arbitrary URL signing. Previously, the endpoint lacked strict domain validation before generating HMAC SHA-256 signatures using the server-side MoonPay secret. This allowed potential abuse where the backend could be tricked into signing unauthorized or malicious URLs. By introducing an explicit allowlist, we ensure the server only signs legitimate MoonPay production and sandbox endpoints.Modifications
demo/pages/api/sign-url.ts):MOONPAY_HOSTSSet containingbuy.moonpay.comandbuy-sandbox.moonpay.com.isAllowedMoonPayUrlhelper to verify that incoming URLs strictly use thehttps:protocol and match the authorized hostnames.demo/pages/api/sign-url.ts):try-catchURL parsing and early-exit HTTP400 Bad Requestresponses for malformed, non-string, or unauthorized URLs before any cryptographic operations are performed.Checklist