fix: validate webhook signatures on percent-encoded request paths - #809
Merged
Conversation
Rack::TwilioWebhookAuthentication decided whether to validate a request by matching the configured patterns against the raw PATH_INFO, which is still percent-encoded. The routers this middleware sits in front of (Rails, Sinatra) decode and normalize the path before matching their own routes, so the two disagreed about which path had been requested. On a disagreement the middleware failed open: a request to /%76oice did not match /\/voice/, so signature validation was skipped entirely and the request was passed through to an app that then routed it to the /voice action. Any endpoint protected only by this middleware would accept unsigned, forged webhooks, with no 403 and no log line to show for it. Match the configured patterns against each form the path can take by the time it reaches the router -- raw, percent-decoded, and with dot segments and repeated slashes collapsed -- and validate if any of them matches. Erring towards validating means this can only widen the set of checked requests, so an integration that works today cannot silently lose its protection. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
Author
sbansla
approved these changes
Sep 10, 2026
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.
Problem
Rack::TwilioWebhookAuthenticationdecided whether to validate a request by matching the configuredpatterns against the raw
PATH_INFO, which is still percent-encoded. The routers this middlewaresits in front of — Rails' Journey, Sinatra — decode and normalize the path before matching their own
routes, so the two disagreed about which path had been requested.
On a disagreement the middleware failed open: it passed the request to the app without validating
its signature, while the router still dispatched it to the guarded action.
Fix
Match the configured patterns against each form the path can take by the time it reaches the router
— raw, percent-decoded, and with dot segments and repeated slashes collapsed — and validate if any
of them matches.
Matching on any candidate is deliberate: it can only widen the set of validated requests, so an
integration that works today cannot silently lose its protection. The failure mode inverts from
"wave it through" to "check it".
Three details worth a reviewer's attention:
Rack::Utils.unescape_path, notunescape. The latter is form decoding and turns+into aspace; in a path a plus is a literal plus.
%FF%FEdecodes to bytes that makeString#matchraiseArgumentError, which would be an unhandled 500 on a hostile path.%256Fdecodes to aliteral
%6Fand routes to/%6Fice, not/voice— so decoding twice would over-match.original_url, used for the signature computation itself, is deliberately untouched. It has arelated encoding mismatch, but changing what gets signed risks breaking integrations that work
today, and it is unreachable while the path gate holds. Worth its own decision.
Tests
10 regression specs covering percent-encoded paths, encoded slashes, dot segments against an
anchored pattern, undecodable bytes, literal
+, and the negative cases that must still passthrough unvalidated.
Full suite green (377 examples, 0 failures); Rubocop clean on both files.
Notes
Tracked internally as SECOPS-25944. Affects current releases, not only the version named in the
report. Maintainers may want to consider a CVE and a GitHub Security Advisory alongside the release
that carries this.
🤖 Generated with Claude Code