From a114b8036812b3dc3fb5fd011a28598431f30e49 Mon Sep 17 00:00:00 2001 From: Omkar Bandikatte Date: Thu, 26 Nov 2026 00:07:09 +0530 Subject: [PATCH 1/2] fix: parse form bodies whose values contain "payload" parse_body looks for the text "payload" in the raw body to detect interactivity requests. When the text was there but the body had no payload parameter, for example a slash command run as `/deploy show payload size`, it returned an empty dict instead of the form parameters it had already parsed, so no listener matched and the app responded with a 404. Return the parsed form parameters in that case. Fixes #1628 --- slack_bolt/request/internals.py | 2 +- tests/scenario_tests/test_slash_command.py | 20 ++++++++++++++++++ .../test_slash_command.py | 21 +++++++++++++++++++ tests/slack_bolt/request/test_internals.py | 17 +++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/slack_bolt/request/internals.py b/slack_bolt/request/internals.py index e0863a713..b8bc2d82d 100644 --- a/slack_bolt/request/internals.py +++ b/slack_bolt/request/internals.py @@ -36,7 +36,7 @@ def parse_body(body: str, content_type: Optional[str]) -> Dict[str, Any]: if payload is not None: return json.loads(payload) else: - return {} + return params else: return dict(parse_qsl(body, keep_blank_values=True)) diff --git a/tests/scenario_tests/test_slash_command.py b/tests/scenario_tests/test_slash_command.py index ae7e7c53b..94850c59e 100644 --- a/tests/scenario_tests/test_slash_command.py +++ b/tests/scenario_tests/test_slash_command.py @@ -121,6 +121,26 @@ def command_handler(ack): assert response.body == """{"error": "invalid request"}""" assert command_called is False + def test_text_containing_payload(self): + app = App( + client=self.web_client, + signing_secret=self.signing_secret, + ) + received_text = None + + def command_handler(ack, command): + nonlocal received_text + received_text = command["text"] + ack() + + app.command("/hello-world")(command_handler) + + timestamp, body = str(int(time())), slash_command_body.replace("&text=Hi", "&text=show+payload+size") + request = BoltRequest(body=body, headers=self.build_headers(timestamp, body)) + response = app.dispatch(request) + assert response.status == 200 + assert received_text == "show payload size" + slash_command_body = ( "token=verification_token" diff --git a/tests/scenario_tests_async/test_slash_command.py b/tests/scenario_tests_async/test_slash_command.py index 918ccba87..66c840cca 100644 --- a/tests/scenario_tests_async/test_slash_command.py +++ b/tests/scenario_tests_async/test_slash_command.py @@ -129,6 +129,27 @@ async def command_handler(ack): assert response.body == """{"error": "invalid request"}""" assert command_called is False + @pytest.mark.asyncio + async def test_text_containing_payload(self): + app = AsyncApp( + client=self.web_client, + signing_secret=self.signing_secret, + ) + received_text = None + + async def command_handler(ack, command): + nonlocal received_text + received_text = command["text"] + await ack() + + app.command("/hello-world")(command_handler) + + timestamp, body = str(int(time())), slash_command_body.replace("&text=Hi", "&text=show+payload+size") + request = AsyncBoltRequest(body=body, headers=self.build_headers(timestamp, body)) + response = await app.async_dispatch(request) + assert response.status == 200 + assert received_text == "show payload size" + slash_command_body = ( "token=verification_token" diff --git a/tests/slack_bolt/request/test_internals.py b/tests/slack_bolt/request/test_internals.py index 31ac35bdd..cc4af2a93 100644 --- a/tests/slack_bolt/request/test_internals.py +++ b/tests/slack_bolt/request/test_internals.py @@ -7,6 +7,7 @@ extract_user_id, extract_team_id, extract_enterprise_id, + parse_body, parse_query, extract_is_enterprise_install, extract_actor_enterprise_id, @@ -589,6 +590,22 @@ def test_actor_user_id(self): user_id = extract_actor_user_id(req) assert user_id is None + def test_parse_body_json(self): + assert parse_body('{"type": "event_callback"}', "application/json") == {"type": "event_callback"} + + def test_parse_body_payload_parameter(self): + body = "payload=%7B%22type%22%3A%22block_actions%22%7D" + assert parse_body(body, "application/x-www-form-urlencoded") == {"type": "block_actions"} + + def test_parse_body_form_value_containing_payload(self): + # "payload" appearing in a value must not be taken for the payload parameter + body = "command=%2Fdeploy&text=show+payload+size&user_id=W111" + assert parse_body(body, "application/x-www-form-urlencoded") == { + "command": "/deploy", + "text": "show payload size", + "user_id": "W111", + } + def test_parse_query(self): expected = {"foo": ["bar"], "baz": ["123"]} From 9acd351098d4a4ed71768fc991fcec9515d3fab5 Mon Sep 17 00:00:00 2001 From: Omkar Bandikatte Date: Thu, 26 Nov 2026 00:23:27 +0530 Subject: [PATCH 2/2] refactor: detect interactivity payloads by the parsed key Decide on the parsed payload parameter instead of looking for the text "payload" in the raw body. That substring check is what caused #1628, so form values containing the word can no longer reach this branch. --- slack_bolt/request/internals.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/slack_bolt/request/internals.py b/slack_bolt/request/internals.py index b8bc2d82d..9995e130e 100644 --- a/slack_bolt/request/internals.py +++ b/slack_bolt/request/internals.py @@ -30,15 +30,11 @@ def parse_body(body: str, content_type: Optional[str]) -> Dict[str, Any]: if (content_type is not None and content_type == "application/json") or body.startswith("{"): return json.loads(body) else: - if "payload" in body: # This is not JSON format yet - params = dict(parse_qsl(body, keep_blank_values=True)) - payload = params.get("payload") - if payload is not None: - return json.loads(payload) - else: - return params - else: - return dict(parse_qsl(body, keep_blank_values=True)) + params = dict(parse_qsl(body, keep_blank_values=True)) + payload = params.get("payload") + if payload is not None: # This is not JSON format yet + return json.loads(payload) + return params def extract_is_enterprise_install(payload: Dict[str, Any]) -> Optional[bool]: