Skip to content

fix(aws_lambda): handle null headers, query string, and body in API Gateway events - #1587

Open
sahiljagtap08 wants to merge 1 commit into
slackapi:mainfrom
sahiljagtap08:fix/aws-lambda-null-event-fields
Open

sahiljagtap08 wants to merge 1 commit into
slackapi:mainfrom
sahiljagtap08:fix/aws-lambda-null-event-fields

Conversation

@sahiljagtap08

Copy link
Copy Markdown

Summary

API Gateway sends null, not a missing key, for request fields that have no value. For a REST API (payload format v1) headers, multiValueHeaders, and queryStringParameters are all null when the request has none of them. The AWS Lambda adapter assumed these were always dicts and raised AttributeError inside to_bolt_request, before the request reached the middleware chain.

Two related edge cases were fixed at the same time:

  • isBase64Encoded missing from the event raised KeyError. This happens when the function is invoked by test tooling or a custom integration that does not set the flag.
  • isBase64Encoded: true with a null body raised TypeError from base64.b64decode.

Changes in slack_bolt/adapter/aws_lambda/handler.py:

  • Every event field lookup treats None the same as a missing key.
  • The base64 decode only runs when the flag is true and a body is present.
  • The headers dict is copied before the cookie header is added, so the caller's event is left untouched.
  • A short comment explains why the null handling is there.

Testing

New tests in tests/adapter_tests/aws/test_aws_lambda.py:

  • test_null_fields_in_api_gateway_event: null headers, multiValueHeaders, and queryStringParameters now produce a 401 (no signature) instead of a crash, and the original event is not modified.
  • test_missing_is_base64_encoded_and_null_body: covers the missing flag and the null body with the flag set.
  • test_base64_encoded_body: a properly signed base64-encoded body is decoded and handled with a 200.

Both crash tests fail on main and pass with this change. Ran ./scripts/format.sh, ./scripts/lint.sh, ./scripts/run_mypy.sh, and the adapter test suite.

Category

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • 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've run ./scripts/install_all_and_run_tests.sh after making the changes.

…ateway events

API Gateway sends null, not a missing key, for request fields that have
no value. For example "headers", "multiValueHeaders" and
"queryStringParameters" are null when the request has none of them.
The Lambda adapter assumed these were always dicts and raised
AttributeError before the request was dispatched. It also raised
KeyError when "isBase64Encoded" was absent, and TypeError when the
flag was true but the body was null.

- Treat None the same as a missing key for every event field
- Copy the headers dict so the caller's event is not modified
- Add tests for null fields, a missing base64 flag, and a real
  base64-encoded body
@sahiljagtap08
sahiljagtap08 requested a review from a team as a code owner October 7, 2026 00:11
@salesforce-cla

salesforce-cla Bot commented Oct 7, 2026

Copy link
Copy Markdown

Thanks for the contribution! Before we can merge this, we need @sahiljagtap08 to sign the Salesforce Inc. Contributor License Agreement.

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.

1 participant