Fix Twilio signature validation behind reverse proxy#5541
Merged
Conversation
Use BASE_API_URL to reconstruct the canonical public URL for signature validation instead of request.url, which reflects the internal proxy URL. Twilio signs requests using the TwiML App's configured URL (e.g. https://api.omi.me/v1/phone/twiml), but request.url returns the pod's internal address, causing every webhook to fail with 403. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Greptile SummaryThis PR fixes a Key changes:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as Twilio Client SDK
participant Twilio as Twilio Cloud
participant Proxy as Reverse Proxy
participant App as FastAPI App (pod)
Client->>Twilio: Initiate call
Twilio->>Proxy: POST /v1/phone/twiml\n(signed with public URL https://api.omi.me/v1/phone/twiml)
Proxy->>App: Forward POST\n(request.url = http://pod-ip:8080/v1/phone/twiml)
Note over App: Before fix: url = str(request.url)\n→ http://pod-ip:8080/v1/phone/twiml\n→ signature mismatch → 403
Note over App: After fix: url = BASE_API_URL + /v1/phone/twiml\n→ https://api.omi.me/v1/phone/twiml\n→ matches Twilio-signed URL → 200
App->>App: validate_twilio_signature(url, params, signature)
App->>Twilio: TwiML response (VoiceResponse)
Twilio->>Client: Call connected
Last reviewed commit: 6ab40b4 |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/v1/phone/twimlwas returning 403 "Invalid Twilio signature" on every callrequest.urlreturns the internal pod/proxy URL (e.g.http://pod-ip:8080/...), but Twilio signs requests using the public URL configured in the TwiML App (https://api.omi.me/v1/phone/twiml)BASE_API_URLenv var (already available) so the signature matchesTest plan
🤖 Generated with Claude Code