Repository navigation
fix: reject malformed unsigned requests instead of crashing before signature check - #1586
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. |
|
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 😸 |
|
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
9acb04f to
afd575d
Compare
|
@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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1586 +/- ##
==========================================
+ Coverage 91.54% 91.59% +0.04%
==========================================
Files 228 228
Lines 7285 7303 +18
==========================================
+ Hits 6669 6689 +20
+ Misses 616 614 -2 ☔ View full report in Codecov by Harness. |
|
thanks @sahiljagtap08 for putting this together, and signing the CLA 🙏 we tested it locally, and it does what it says: malformed unsigned bodies that return a after talking it over as a team, though, we've decided to take a different approach, so we're going to close this PR. we'd rather fix the order of operations so unsigned payloads are never parsed. that means moving body parsing and context building into a middleware that runs after |
|
Thanks for testing it and for the explanation @srtaalej. Moving the parsing behind RequestVerification makes sense. Happy to help with that change if useful. |
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.