Skip to content

fix: parse form bodies whose values contain "payload" - #1629

Open
omkarbandikatte wants to merge 2 commits into
slackapi:mainfrom
omkarbandikatte:fix/parse-body-payload-substring
Open

omkarbandikatte wants to merge 2 commits into
slackapi:mainfrom
omkarbandikatte:fix/parse-body-payload-substring

Conversation

@omkarbandikatte

Copy link
Copy Markdown

Summary

Fixes #1628.

parse_body checks for the text payload in the raw body to detect interactivity requests. When that text appeared in a form body without a payload parameter, for example a slash command run as /deploy show payload size, it returned {} instead of the form parameters it had already parsed. No listener matched the empty body, so the app responded with a 404.

This returns the parsed form parameters in that case, which is what the branch without the word payload already returns. Bodies with a payload parameter and JSON bodies are unchanged. AsyncBoltRequest uses the same parse_body, so this covers AsyncApp as well.

I saw in #1586 that the team plans to move body parsing into a middleware that runs after RequestVerification. This change is only to the parsing logic, so it should carry over to wherever parse_body ends up.

Testing

New tests:

  • tests/slack_bolt/request/test_internals.py: parse_body on a form value containing payload, which fails on main. Two more tests, for a JSON body and a payload parameter, cover the paths this change leaves alone and pass before and after.
  • tests/scenario_tests/test_slash_command.py and tests/scenario_tests_async/test_slash_command.py: a signed slash command with the text show payload size reaches its listener with that text. On main both get a 404.

On Python 3.13 I ran each step of ./scripts/install_all_and_run_tests.sh separately:

  • ./scripts/format.sh --no-install: no changes
  • ./scripts/lint.sh --no-install: all checks passed
  • ./scripts/run_tests.sh: 960 passed
  • ./scripts/run_mypy.sh --no-install: no issues found in 234 source files

To check by hand, the snippet in #1628 prints {} for the second body on main and the full form parameters with this change.

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.

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 slackapi#1628
@omkarbandikatte
omkarbandikatte requested a review from a team as a code owner November 25, 2026 18:37
@mwbrooks mwbrooks added bug Something isn't working semver:patch labels Nov 25, 2026
@mwbrooks mwbrooks added this to the next milestone Nov 25, 2026

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙇 Thanks @omkarbandikatte! 🎉 Congrats on your first contribution to bolt-python!

I reproduced the {} body on main and returning the parsed form here matches the branch without payload. The slash command tests on both App and AsyncApp are a nice touch.

CI is next, we'll get the workflows running shortly.

Comment thread slack_bolt/request/internals.py Outdated
return json.loads(payload)
else:
return {}
return params

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): Now that both branches return the parsed form, could we drop the "payload" in body check above and decide on the parsed key instead? That substring check is what caused #1628, so removing it means the next form value with the word in it can't trip it.

        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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mwbrooks, good call. Applied in 9acd351 as a separate commit.

To check it doesn't change anything else, I compared it with the previous commit on about 60,000 generated form bodies. The only inputs that differ are bodies whose key is percent-encoded, like pay%6Coad=.... That key now counts as the payload, since parse_qsl decodes it to payload.

Format, lint and mypy pass, and ./scripts/run_tests.sh gives 960 passed. The three new tests still fail on main.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @omkarbandikatte, that settles it! Treating an encoded pay%6Coad key as the payload is the right call too, since that's what parse_qsl hands us. 🙏

Decide on the parsed payload parameter instead of looking for the text
"payload" in the raw body. That substring check is what caused slackapi#1628,
so form values containing the word can no longer reach this branch.

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.

Form-encoded requests containing the word "payload" are parsed as an empty body

2 participants