You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Debugging a little it appears as if the gem encodes the ' as %27 via URI, whereas the signature generated by Twilio did not encode the ' as %27. Because if I do the calculation to generate the signature keeping the ' as ', I get the signatures to match.
Twilio support gave me the workaround of making the Webhook a POST instead of a GET. My code is now as follows:
# Need this because env['rack.url_scheme'] is only for the last leg of the journey,
# Rack::Request#scheme gets us the scheme of the real request
rack_request = Rack::Request.new(env)
validator = Twilio::Security::RequestValidator.new(ENV["MEMBERS_TWILIO_SECRET"])
twilio_signature = env["HTTP_X_TWILIO_SIGNATURE"]
url = "#{rack_request.scheme}://" + env["HTTP_HOST"] + env["REQUEST_URI"]
# params arg: Use rack_request.params for POST request. Use {} for GET request
unless validator.validate(url, rack_request.params, twilio_signature)
raise "Twilio request validation failed."
end
Same issue described above was happening to me. It was happening because the url contained a query parameter that had an apostraphe in the value
e.g. the url had an apostraphe that was encoded with %27 https://www.example.com?name=O%27Malley
The fix for me was to double encode the query parameters before sending the request to twilio.
e.g. https://www.example.com?name=O%2527Malley
And then make sure to do an extra decoding on the callback query params on my backend
Issue Summary
An apostrophe in the body of a text message causes validation of Twilio webhook to fail
Steps to Reproduce
Code Snippet
Technical details:
The text was updated successfully, but these errors were encountered: