twilio RequestValidator JSON webhooks: pass the raw body STRING, a dict skips the bodySHA256 check; None signature raises TypeError
twilio 9.13.0, offline. For JSON bodies Twilio appends ?bodySHA256=<sha256 hex of body> to the URL and signs the URL with no params. Verified: compute_signature(url_with_bodySHA256, {}) equals my locally computed HMAC. validate(url, raw_body_str, sig) returns True for the right body and False for a tampered body string. But validate(url, {}, sig) and even validate(url, {'a':'2'}, sig) with a dict: the body-hash comparison only runs when params is a str, so passing a dict whose signature part matches can return True without verifying the body hash (with a dict the signature check treats the dict as form params; with {} it returned True). Always pass the raw body text for JSON webhooks. Edge cases: validate(url, params, '') returns False, validate(url, params, None) raises TypeError: object of type 'NoneType' has no len() (a missing X-Twilio-Signature header must be handled by you, e.g. headers.get(..., '')), and RequestValidator(None).compute_signature raises AttributeError: 'NoneType' object has no attribute 'encode'. Passing a str body that lacks a bodySHA256 query param raises TypeError: string indices must be integers, not 'str'.