Skip to content

Commit d49601b

Browse files
masatohoshinovincentkoc
authored andcommitted
fix(voice-call): pin Twilio verification to public URL path
1 parent 992d19a commit d49601b

3 files changed

Lines changed: 21 additions & 24 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 public webhook URL configured with the provider. A reverse proxy may map that public path to a different `serve.path`, but `publicUrl` must remain the provider-facing URL.
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+
Twilio and Plivo URL signatures use `publicUrl` when it is configured: its
923+
scheme, host, and path are preserved, while the request query is applied.
924+
Without `publicUrl`, OpenClaw reconstructs the URL from the request. Telnyx
925+
signatures do not include the request URL. 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: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -732,36 +732,30 @@ describe("verifyTwilioWebhook", () => {
732732
expect(result.verificationUrl).toBe(webhookUrl);
733733
});
734734

735-
it("uses request query when publicUrl omits it", () => {
735+
it("uses the configured public path with the request query", () => {
736736
const authToken = "test-auth-token";
737-
const publicUrl = "https://example.com/voice/webhook";
738-
const urlWithQuery = `${publicUrl}?callId=abc&turnToken=secret-turn-token`;
737+
const publicUrl = "https://example.com/proxy/voice/webhook";
738+
const urlWithQuery = `${publicUrl}?callId=abc`;
739739
const postBody = "CallSid=CS123&CallStatus=completed&From=%2B15550000000";
740-
741-
const signature = twilioSignature({
742-
authToken,
743-
url: urlWithQuery,
744-
postBody,
745-
});
746-
747-
const result = verifyTwilioWebhook(
748-
{
740+
const verifySignedUrl = (signedUrl: string) =>
741+
verifyTwilioSignedRequest({
749742
headers: {
750743
host: "example.com",
751744
"x-forwarded-proto": "https",
752-
"x-twilio-signature": signature,
745+
"x-twilio-signature": twilioSignature({ authToken, url: signedUrl, postBody }),
753746
},
754747
rawBody: postBody,
755-
url: "http://local/voice/webhook?callId=abc&turnToken=secret-turn-token",
756-
method: "POST",
757-
query: { callId: "abc", turnToken: "secret-turn-token" },
758-
},
759-
authToken,
760-
{ publicUrl },
761-
);
748+
authToken,
749+
publicUrl,
750+
});
762751

752+
const result = verifySignedUrl(urlWithQuery);
763753
expect(result.ok).toBe(true);
764754
expect(result.verificationUrl).toBe(urlWithQuery);
755+
756+
const localPathResult = verifySignedUrl("https://example.com/voice/webhook?callId=abc");
757+
expect(localPathResult.ok).toBe(false);
758+
expect(localPathResult.reason).toContain(`${publicUrl}?callId=***`);
765759
});
766760

767761
it("redacts query params from invalid Twilio signature diagnostics", () => {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ function buildTwilioVerificationUrl(
320320
try {
321321
const base = new URL(publicUrl);
322322
const requestUrl = new URL(ctx.url);
323-
base.pathname = requestUrl.pathname;
323+
// Proxies may rewrite the local request path. Preserve the provider-facing
324+
// publicUrl path and apply only per-request query parameters.
324325
base.search = requestUrl.search;
325326
return base.toString();
326327
} catch {

0 commit comments

Comments
 (0)