Repository navigation
fix: reject malformed unsigned requests instead of crashing before signature check - #1586
Open
sahiljagtap08 wants to merge 1 commit into
Open
sahiljagtap08 wants to merge 1 commit into
sahiljagtap08 wants to merge 1 commit into
Conversation
|
Thanks for the contribution! Before we can merge this, we need @sahiljagtap08 to sign the Salesforce Inc. Contributor License Agreement. |
Contributor
|
thank you for opening this PR @sahiljagtap08 💟 looking pretty good! i'll give it a more thorough review once the CLA is signed and CI passes 😸 |
Author
|
recheck |
…gnature check Non-Slack clients (scanners, bots) can send any JSON shape to a public endpoint. Building the request context happens before the RequestVerification middleware runs, so a body with unexpected value types, a JSON array, or broken JSON used to raise TypeError, AttributeError, or JSONDecodeError. That turned an unsigned request into a 500 instead of the expected 401. - Every extract_* helper now checks the value type before using it - parse_body treats non-object or invalid JSON as an empty body - build_context / build_async_context guard the response_urls shape - Add unit tests for the malformed shapes and end-to-end tests that assert a 401 for both App and AsyncApp Fixes slackapi#1447
sahiljagtap08
force-pushed
the
fix/robust-context-extraction-1447
branch
from
October 8, 2026 00:09
9acb04f to
afd575d
Compare
Author
|
@srtaalej thanks for taking a look! The CLA is signed now and the check is passing. Let me know if you'd like any changes. |
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
Public endpoints get hit by scanners and bots that send any JSON shape. Bolt builds the request context (team id, user id, and so on) when the
BoltRequestis created, which is before theRequestVerificationmiddleware runs. A body with the wrong value types, a JSON array, or broken JSON raisedTypeError,AttributeError, orJSONDecodeError. The result was a 500 for a request that should have been a 401.This follows the non-breaking approach suggested in the issue thread: make the context extraction robust instead of moving it behind the middleware.
Changes:
extract_*helper inslack_bolt/request/internals.pychecks the value type before using it (authorizations,enterprise,team,user,channel,event).parse_bodytreats non-object JSON (array, string, number, null) and invalid JSON as an empty body, so the request still reaches the signature check and is rejected there.build_contextandbuild_async_contextguard the shape ofresponse_urls.Testing
tests/slack_bolt/request/test_internals.pycover the malformed shapes for every extractor,build_context, andparse_body.tests/scenario_tests/test_app.pyandtests/scenario_tests_async/test_app.pysend unsigned malformed bodies toAppandAsyncAppand assert a 401 (previously an exception)../scripts/format.sh,./scripts/lint.sh,./scripts/run_mypy.sh, and the full test suite. All existing tests pass.Category
Requirements
./scripts/install_all_and_run_tests.shafter making the changes.