Repository navigation
fix: parse request bodies after RequestVerification - #1630
Draft
WilliamBergamin wants to merge 8 commits into
Draft
WilliamBergamin wants to merge 8 commits into
WilliamBergamin wants to merge 8 commits into
Conversation
Unsigned bodies that are invalid JSON, a JSON array, or oddly shaped crash BoltRequest construction before RequestVerification can return 401. Refs #1447 Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
SslCheck runs before RequestVerification, so it should not depend on the fully parsed request body. ssl_check requests are form encoded, and parse_qsl never raises on untrusted input. Refs #1447 Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
A request created with defer_parsing=True keeps its raw body unparsed and its context unbuilt. The new built-in RequestParsing middleware completes both right after RequestVerification, so unsigned payloads are never parsed. Context values set after the request was created still win, and the per-request client gets the team_id it could not see earlier. The default stays eager, so code that builds a BoltRequest directly is unchanged. Refs #1447 Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Every HTTP adapter and the built-in dev servers pass defer_parsing=True where they hand the request to dispatch. The public to_bolt_request helpers keep eager parsing by default, and OAuth and Socket Mode paths are unchanged. Fixes #1447 Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
SignatureVerifier.is_valid raises on a non-numeric timestamp or a non-ASCII signature, which turned unsigned junk into a 500. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1630 +/- ##
==========================================
+ Coverage 91.57% 91.63% +0.06%
==========================================
Files 228 231 +3
Lines 7287 7330 +43
==========================================
+ Hits 6673 6717 +44
+ Misses 614 613 -1 ☔ View full report in Codecov by Harness. |
BoltRequest and AsyncBoltRequest no longer parse the body or build the context at construction. The RequestParsing middleware, which runs right after RequestVerification, is now the only parser, so every request that reaches dispatch is protected and the defer_parsing opt-in, its adapter plumbing, and its docs are gone. A request that is read without being dispatched now has an empty body; tests that do so run RequestParsing through a small helper. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
It is independent of parsing after verification. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
4 of 8 tasks
This branch has not been deployed
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.
Summary
Fixes #1447. Bolt parsed the body and built the context in
BoltRequest.__init__, beforeRequestVerificationran, so unsigned scanner traffic could crash an app before it was rejected with a 401. As discussed when closing #1586, this moves parsing after verification instead of hardening the extractors further.BoltRequestandAsyncBoltRequestno longer parse anything. The new built-inRequestParsingmiddleware runs right afterRequestVerification(even when verification is disabled) and is the only place where the body is parsed and the context is built from it.dispatch, so they are all covered.SslCheckreadsssl_checkfrom the raw form body.Release notes:
BoltRequestthat is read without being dispatched (for example in a unit test of a custom matcher or middleware) now hasbody == {}and a context that wasn't built from the body. Dispatch it, or runRequestParsingon it.context=now take precedence over values from the body.RequestVerification._can_skip(mode, body)always receives{}asbody. A subclass that overrides_init_middleware_listwithout callingsuper()no longer gets parsing.Testing
tests/scenario_tests{,_async}/test_request_parsing.pydispatches 41 signed payloads and asserts the samecontext,bodyandclient.default_paramsas a request parsed before dispatch. It also covers unsigned malformed bodies (401), adapter-set context winning over the body, a lazy listener readingbody,to_copyable, and ssl_check.tests/adapter_tests/aws/test_aws_lambda.pyruns the PoC fromextract_team_idcrashes withTypeError when payload["user"]is a string (e.g.member_joined_channelevents) #1447 through the Lambda handler. It fails onmainand passes here../scripts/run_tests.sh: 976 passed. Lint, format and mypy are clean.Category
slack_bolt.Appand/or its core componentsslack_bolt.async_app.AsyncAppand/or its core componentsslack_bolt.adapter/docsRequirements
./scripts/install_all_and_run_tests.shafter making the changes.🤖 Generated with Claude Code