Skip to content

Commit 5c37183

Browse files
committed
fix(voice-call): pin Twilio webhook verification to the configured public path
buildTwilioVerificationUrl overwrote the configured publicUrl path with the incoming request path, so behind a path-rewriting reverse proxy the reconstructed verification URL no longer matched the URL Twilio signed and valid webhooks were rejected. Use the configured public path (keep the request query), mirroring the Plivo sibling fixed in #112559. Restores callback-path binding and adds proxy-prefix accept + local-path reject regression tests.
1 parent e085b37 commit 5c37183

3 files changed

Lines changed: 65 additions & 4 deletions

File tree

‎docs/plugins/voice-call.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ openclaw logs --follow
905905

906906
Common causes:
907907

908-
- `publicUrl` points at a different path than `serve.path`.
908+
- `publicUrl` does not match the webhook URL configured in the provider console (scheme, host, or path). A public path that differs from `serve.path` is fine when a proxy maps the public path to `serve.path` — set `publicUrl` to the public one.
909909
- The tunnel URL changed after the Gateway started.
910910
- A proxy forwards the request but strips or rewrites host/proto headers.
911911
- Firewall or DNS routes the public hostname somewhere other than the Gateway.
@@ -919,8 +919,10 @@ under your control.
919919

920920
### Signature verification fails
921921

922-
Provider signatures are checked against the public URL OpenClaw reconstructs
923-
from the incoming request. If signatures fail:
922+
Provider signatures are checked against `publicUrl` when it is configured
923+
(scheme, host, and path come from `publicUrl`; only the query is taken from
924+
the incoming request), falling back to a URL reconstructed entirely from the
925+
request otherwise. If signatures fail:
924926

925927
- Confirm the provider webhook URL exactly matches `publicUrl`, including scheme, host, and path.
926928
- For ngrok free-tier URLs, update `publicUrl` when the tunnel hostname changes.

‎extensions/voice-call/src/webhook-security.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,66 @@ describe("verifyTwilioWebhook", () => {
648648
expect(result.verificationUrl).toBe(urlWithQuery);
649649
});
650650

651+
it("pins Twilio publicUrl verification to the configured path behind a path-rewriting proxy", () => {
652+
const authToken = "test-auth-token";
653+
// Twilio signs the public URL it was configured to call, including the proxy prefix.
654+
const publicUrl = "https://voice.openclaw.ai/proxy/voice/webhook";
655+
const signedUrl = `${publicUrl}?callId=abc`;
656+
const postBody = "CallSid=CS123&CallStatus=completed&From=%2B15550000000";
657+
658+
const signature = twilioSignature({ authToken, url: signedUrl, postBody });
659+
660+
const result = verifyTwilioWebhook(
661+
{
662+
headers: {
663+
host: "voice.openclaw.ai",
664+
"x-forwarded-proto": "https",
665+
"x-twilio-signature": signature,
666+
},
667+
// Reverse proxy rewrote the public /proxy/voice/webhook path to the local path.
668+
rawBody: postBody,
669+
url: "http://local/voice/webhook?callId=abc",
670+
method: "POST",
671+
query: { callId: "abc" },
672+
},
673+
authToken,
674+
{ publicUrl },
675+
);
676+
677+
expect(result.ok).toBe(true);
678+
expect(result.verificationUrl).toBe(signedUrl);
679+
});
680+
681+
it("rejects a Twilio signature for the local path when publicUrl configures a different path", () => {
682+
const authToken = "test-auth-token";
683+
const publicUrl = "https://voice.openclaw.ai/proxy/voice/webhook";
684+
// Signature computed over the local (proxy-rewritten) path, not the configured public path.
685+
const localSignedUrl = "https://voice.openclaw.ai/voice/webhook?callId=abc";
686+
const postBody = "CallSid=CS123&CallStatus=completed&From=%2B15550000000";
687+
688+
const signature = twilioSignature({ authToken, url: localSignedUrl, postBody });
689+
690+
const result = verifyTwilioWebhook(
691+
{
692+
headers: {
693+
host: "voice.openclaw.ai",
694+
"x-forwarded-proto": "https",
695+
"x-twilio-signature": signature,
696+
},
697+
rawBody: postBody,
698+
url: "http://local/voice/webhook?callId=abc",
699+
method: "POST",
700+
query: { callId: "abc" },
701+
},
702+
authToken,
703+
{ publicUrl },
704+
);
705+
706+
// Before the fix the request path was used, so this local-path signature validated;
707+
// now verification is bound to the configured public path and rejects it.
708+
expect(result.ok).toBe(false);
709+
});
710+
651711
it("redacts query params from invalid Twilio signature diagnostics", () => {
652712
const result = verifyTwilioWebhook(
653713
{

‎extensions/voice-call/src/webhook-security.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ function buildTwilioVerificationUrl(
300300
try {
301301
const base = new URL(publicUrl);
302302
const requestUrl = new URL(ctx.url);
303-
base.pathname = requestUrl.pathname;
304303
base.search = requestUrl.search;
305304
return base.toString();
306305
} catch {

0 commit comments

Comments
 (0)