cherrypy: fix handling of raw application/x-www-form-urlencoded traffic - #54901
Merged
dwoz merged 14 commits intoAug 6, 2020
Merged
Conversation
dwoz
requested changes
Oct 7, 2019
ghost
requested a review
from dwoz
December 6, 2019 15:12
Contributor
Author
|
@dwoz added test and all tests passing |
Contributor
Author
|
@dwoz @sagetherage assuming these tests pass (I'm going to bed), can this PR get some love? I think we're coming up on 11 months from the original PR date and I keep having to track to new formats and tests. |
dwoz
approved these changes
Aug 6, 2020
3 tasks
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 does this PR do?
handle the preservation of raw application/x-www-form-urlencoded traffic in cherrypy
What issues does this PR fix or reference?
N/A
Previous Behavior
cherrypy natively parsed the incoming x-www-form-urlencoded traffic into a dictionary, which was then put into the
postkey when the event fired. theraw_bodywas manually set to an empty string, because cherrypy will leaveraw_bodyasNonewhen parsing x-www-form-urlencoded traffic. therefore, thebodykey of the event was always an empty string in the case of x-www-form-urlencoded traffic, where that key would normally contain the raw request when processing other types of traffic.I consider this "broken" because it doesn't provide a way to handle the raw data at all when parsing x-www-form-urlencoded traffic. This functionality is required when attempting to validate Slack webhooks since the raw x-www-form-urlencoded string is hashed for a signature and cannot be deserialized because it will destroy the order of the parameters and provide no mechanism to validate the traffic.
New Behavior
instead of using the native cherrypy parsing, which throws away the raw request when creating the
paramsdictionary, we read the raw data into a string (which ends up in thebodykey in the event) and then perform manual parsing of the tokens into a dictionary using parse_qsl to set the contents of thepostkey in the event. since thepostkey output functionality isn't changed and thebodykey was always empty and therefore wasn't relied on, this is a low impact change.Tests written?
Yes
Commits signed with GPG?
Yes