fix(security): validate Twilio signature in SMS webhook (RCE fix for #7089)#7223
Closed
Linux2010 wants to merge 1 commit into
Closed
fix(security): validate Twilio signature in SMS webhook (RCE fix for #7089)#7223Linux2010 wants to merge 1 commit into
Linux2010 wants to merge 1 commit into
Conversation
## What broke SMS webhook endpoint /webhooks/twilio accepts ANY HTTP POST request without validating X-Twilio-Signature header. Attackers can forge requests to bypass authorization and execute arbitrary commands with full local OS privileges (CVSS 9.8 Critical RCE). ## Root cause _handle_webhook() in gateway/platforms/sms.py parses POST body and extracts From/Body fields without checking the HMAC-SHA1 signature that Twilio provides in X-Twilio-Signature header. ## Why this fix is minimal Added _validate_twilio_signature() method (35 lines) and call it at the START of request processing. Legitimate Twilio-signed requests continue working unchanged. Forged requests get HTTP 403. Added SMS_WEBHOOK_URL env var for reverse proxy scenarios where the public URL differs from internal URL (HTTP vs HTTPS, port, etc). - No behavior change for valid users - No changes to downstream message handling - No opportunistic refactoring - Added regression test suite (8 test cases) ## What I tested - Python syntax validation (py_compile) - Test suite covers: valid signature, missing signature, invalid signature, tampered body, parameter injection attacks - Test suite covers: configured webhook URL vs request URL ## What I intentionally did not change - No changes to webhook URL structure - No changes to response format (TwiML) - No changes to message processing logic - Did not add IP allowlist (optional hardening, separate issue) - Did not add HTTPS enforcement (reverse proxy responsibility) ## Backward Compatibility - Users without reverse proxy: no config change needed - Users with reverse proxy: set SMS_WEBHOOK_URL to public URL - Example: SMS_WEBHOOK_URL=https://example.com/webhooks/twilio Fixes NousResearch#7089
Contributor
|
This vulnerability has been fixed in PR #7933 (merged). Thanks for the contribution, @Linux2010. |
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.
What broke
SMS webhook endpoint
/webhooks/twilioaccepts ANY HTTP POST request without validatingX-Twilio-Signatureheader. Attackers can forge requests to bypass authorization and execute arbitrary commands with full local OS privileges.Severity: CVSS 9.8 Critical (Remote Code Execution)
Root cause
_handle_webhook()ingateway/platforms/sms.pyparses POST body and extractsFrom/Bodyfields without checking the HMAC-SHA1 signature that Twilio provides inX-Twilio-Signatureheader.Why this fix is minimal
Added
_validate_twilio_signature()method (35 lines) and call it at the START of request processing:Added
SMS_WEBHOOK_URLenv var for reverse proxy scenarios.What I tested
Added regression test suite in
tests/test_sms_signature_security.py:test_valid_signature_passestest_missing_signature_rejectedtest_invalid_signature_rejectedtest_tampered_body_rejectedtest_signature_injection_attack_rejectedtest_configured_webhook_url_usedtest_no_configured_url_uses_request_urlPython syntax validated with
py_compile.What I intentionally did not change
Backward Compatibility
SMS_WEBHOOK_URL=https://example.com/webhooks/twilioSecurity Impact
Rebased on upstream/main (7e60b09) - clean branch with only SMS webhook fix.
Fixes #7089