Skip to content

fix(signature): return False for malformed timestamp, signature or body in SignatureVerifier.is_valid - #2075

Open
tony1233200 wants to merge 1 commit into
slackapi:mainfrom
tony1233200:fix/2067-signature-verifier-malformed-input
Open

tony1233200 wants to merge 1 commit into
slackapi:mainfrom
tony1233200:fix/2067-signature-verifier-malformed-input

Conversation

@tony1233200

Copy link
Copy Markdown

Summary

Fixes #2067.

SignatureVerifier.is_valid() (and is_valid_request()) returned False for missing values but raised for three kinds of malformed input that arrive straight from the X-Slack-Request-Timestamp / X-Slack-Signature headers and the request body, so in bolt-python such a request ended as a 500 instead of the 401 invalid request response:

  • non-numeric timestamp ("abc") → ValueError from int(timestamp)
  • non-ASCII signature ("v0=é") → TypeError from hmac.compare_digest, which only accepts ASCII strings
  • non-UTF-8 bytes body (b"\xff\xfe") → UnicodeDecodeError from body.decode("utf-8") in generate_signature

Fix: in is_valid(), each case now returns False — the non-numeric timestamp is caught around int(), a non-ASCII signature is rejected before compare_digest(), and a UnicodeDecodeError from generate_signature() is caught. No blanket try/except: the guards are scoped to the exact failing operations, and a valid signature still returns True.

Note: open PR #1968 already fixes the timestamp case only (no reference to #2067). This PR covers all three cases from #2067; if #1968 lands first, the timestamp hunk here becomes redundant.

Testing

New regression tests in tests/slack_sdk/signature/test_signature_verifier.py (test_is_valid_malformed_timestamp, test_is_valid_malformed_signature, test_is_valid_malformed_body, test_is_valid_request_malformed_inputs):

  • Before the fix: all 4 new tests fail (the three exceptions above, on both is_valid and is_valid_request); repro_2067.py shows the same three raises.
  • After the fix: pytest tests/slack_sdk/signature/test_signature_verifier.py — 16 passed (12 existing + 4 new); repro_2067.py — all 9 checks pass, including valid signature still True and missing values still False.

Other checks:

  • ruff format --check slack_sdk/signature/__init__.py tests/slack_sdk/signature/test_signature_verifier.py and ruff check slack_sdk/signature/ pass.
  • ./scripts/run_validation.sh was not run in full (it installs dependencies and runs the whole suite); the signature test file and the lint checks above were run instead.

Category

  • slack_sdk.signature (Request Signature Verifier)
  • tests/integration_tests (Automated tests for this library)

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 python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

…dy in SignatureVerifier.is_valid

Fixes slackapi#2067: is_valid() raised instead of returning False for malformed
inputs that arrive straight from request headers / body:
- non-numeric timestamp ("abc") raised ValueError from int(timestamp)
- non-ASCII signature ("v0=é") raised TypeError from hmac.compare_digest
- non-UTF-8 bytes body raised UnicodeDecodeError from body.decode("utf-8")

Each case now returns False, matching the existing contract for missing
values (test_is_valid_none). Valid signatures still return True.

Adds regression tests covering all three cases via is_valid() and
is_valid_request().
@tony1233200
tony1233200 requested a review from a team as a code owner November 20, 2026 10:37
@salesforce-cla

Copy link
Copy Markdown

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

@mwbrooks mwbrooks added the bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented label Nov 20, 2026
@mwbrooks mwbrooks added this to the 3.48.1 milestone Nov 20, 2026

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

Labels

bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented cla:signed security semver:patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SignatureVerifier.is_valid raises instead of returning False for a malformed timestamp, signature or body

3 participants