Skip to content

fix: parse request bodies after RequestVerification - #1630

Draft
WilliamBergamin wants to merge 8 commits into
mainfrom
fix/defer-parsing-after-verification
Draft

WilliamBergamin wants to merge 8 commits into
mainfrom
fix/defer-parsing-after-verification

Conversation

@WilliamBergamin

@WilliamBergamin WilliamBergamin commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1447. Bolt parsed the body and built the context in BoltRequest.__init__, before RequestVerification ran, 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.

  • BoltRequest and AsyncBoltRequest no longer parse anything. The new built-in RequestParsing middleware runs right after RequestVerification (even when verification is disabled) and is the only place where the body is parsed and the context is built from it.
  • No new API and no adapter changes: every adapter, custom adapter, and the dev servers go through dispatch, so they are all covered.
  • SslCheck reads ssl_check from the raw form body.

Release notes:

  • A BoltRequest that is read without being dispatched (for example in a unit test of a custom matcher or middleware) now has body == {} and a context that wasn't built from the body. Dispatch it, or run RequestParsing on it.
  • Keys passed through the constructor's context= now take precedence over values from the body.
  • RequestVerification._can_skip(mode, body) always receives {} as body. A subclass that overrides _init_middleware_list without calling super() no longer gets parsing.

Testing

  • tests/scenario_tests{,_async}/test_request_parsing.py dispatches 41 signed payloads and asserts the same context, body and client.default_params as a request parsed before dispatch. It also covers unsigned malformed bodies (401), adapter-set context winning over the body, a lazy listener reading body, to_copyable, and ssl_check.
  • tests/adapter_tests/aws/test_aws_lambda.py runs the PoC from extract_team_id crashes with TypeError when payload["user"] is a string (e.g. member_joined_channel events) #1447 through the Lambda handler. It fails on main and passes here.
  • ./scripts/run_tests.sh: 976 passed. Lint, format and mypy are clean.

Category

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I have signed the Salesforce CLA (required before your PR can be reviewed or merged).
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

🤖 Generated with Claude Code

WilliamBergamin and others added 6 commits November 26, 2026 10:46
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

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.63%. Comparing base (16056a4) to head (1a21eeb).
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract_team_id crashes with TypeError when payload["user"] is a string (e.g. member_joined_channel events)

1 participant