Skip to content

fix(relay-kit): restrict URL signing to authorized MoonPay hosts in sign-url endpoint - #1116

Merged
pedromcunha merged 1 commit into
relayprotocol:mainfrom
magqqgq:magqqgq-patch-1
Aug 31, 2026
Merged

fix(relay-kit): restrict URL signing to authorized MoonPay hosts in sign-url endpoint#1116
pedromcunha merged 1 commit into
relayprotocol:mainfrom
magqqgq:magqqgq-patch-1

Conversation

@magqqgq

@magqqgq magqqgq commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

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

  • Format your code according to the Contributor Guide.
  • Add unit tests as outlined in the Contributor Guide.
  • Update documentation as needed, including docstrings or example tutorials.

…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.
@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

@magqqgq is attempting to deploy a commit to the Uneven Labs Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown

Greptile Summary

This change restricts the demo signing endpoint to HTTPS production and sandbox MoonPay hosts, rejects malformed URL input, ignores non-string supplemental query values, and returns an error when its signing secret is unavailable.

One request to an allowed production MoonPay URL completed successfully and returned a signature. No actionable defect is reported.

T-Rex validation blocked

The full request matrix could not complete because the local Next.js demo service did not finish first-time route compilation within the available command lifecycle. The incomplete checks covered hostname-confusion URLs, malformed and repeated URL values, supplemental duplicate parameters, sandbox URLs, and the missing-secret response.

Confidence Score: 5/5

The targeted implementation adds exact hostname and HTTPS validation before the signing operation, and no author-actionable issue was identified.

No final findings were identified. An allowed MoonPay request returned a signature; the remaining local request matrix was incomplete because of demo service startup timing.

Files Needing Attention: No files require author action.

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex attempted to run the complete local /api/sign-url request matrix, but validation was blocked because the Next.js demo service did not finish initial route compilation before the command lifecycle ended.
  • A route-level harness script sign-url-route-harness.sh was prepared to start the demo and issue every requested attack, malformed input, secret, supplemental query, sandbox, and HMAC-verification request.
  • Observed harness output in sign-url-02-after.log captured only the harness header before the command runner terminated, and the prior sign-url-01-before.log capture existed but also did not finish due to the same harness lifecycle issue.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "fix(relay-kit): restrict URL signing to ..." | Re-trigger Greptile

@pedromcunha
pedromcunha self-requested a review August 31, 2026 16:30
@pedromcunha
pedromcunha merged commit fadb834 into relayprotocol:main Aug 31, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants