fix(feishu): fail-closed on missing encrypt_key and empty card-action token#14627
Open
Subway2023 wants to merge 1 commit into
Open
fix(feishu): fail-closed on missing encrypt_key and empty card-action token#14627Subway2023 wants to merge 1 commit into
Subway2023 wants to merge 1 commit into
Conversation
…is absent or token is empty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(feishu): fail-closed on missing encrypt_key and empty card-action token
What does this PR do?
Feishu webhook mode had two fail-open authentication paths that allowed unauthenticated requests to reach command dispatch:
Webhook signature bypass:
_handle_webhook_requestonly ran signature verification whenself._encrypt_keywas truthy. WhenFEISHU_ENCRYPT_KEYwas unset (defaulting to""), the entire check was short-circuited, accepting any request. Additionally,_is_webhook_signature_validdid not guard against an empty key, meaning an attacker who knew the key was absent could craft a valid HMAC over an empty string and still pass if the guard was ever reached.Card-action empty token accepted:
_handle_card_action_eventguarded the dedup check withif token and …, so a card-action callback with an emptytokenbypassed deduplication entirely and proceeded to command dispatch.This PR makes both paths fail-closed:
_is_webhook_signature_validnow returnsFalseimmediately whenencrypt_keyis empty.if self._encrypt_key and not …toif not …, so verification always runs._handle_card_action_eventnow explicitly drops events with a missing or empty token before the dedup check.Related Issue
Fixes #
Type of Change
Changes Made
gateway/platforms/feishu.py: add earlyif not self._encrypt_key: return Falseguard at the top of_is_webhook_signature_validgateway/platforms/feishu.py: changeif self._encrypt_key and not self._is_webhook_signature_valid(…)→if not self._is_webhook_signature_valid(…)in_handle_webhook_requestgateway/platforms/feishu.py: addif not token: returnbefore the dedup check in_handle_card_action_eventtests/gateway/test_feishu.py: addTestWebhookFailClosed(2 cases) andTestCardActionSecurity(3 cases) covering the new fail-closed behaviourtests/gateway/test_feishu.py: updatetest_webhook_request_uses_same_message_dispatch_pathto supply a valid signature, as it previously relied on the fail-open behaviourHow to Test
FEISHU_ENCRYPT_KEYunset and webhook mode enabled.HTTP 401."token": ""— confirm the event is dropped and no command is dispatched.pytest tests/gateway/test_feishu.py -q— all tests should pass.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs