Skip to content

fix(gateway): keep TLS verification when sending Feishu bot credentials - #1828

Open
tidytorch wants to merge 1 commit into
TencentCloud:developfrom
tidytorch:r1-feishu-tls-verification
Open

tidytorch wants to merge 1 commit into
TencentCloud:developfrom
tidytorch:r1-feishu-tls-verification

Conversation

@tidytorch

Copy link
Copy Markdown

Problem

During an internal security review of the bot-creator flow we found that _send_greeting in src/octop/infra/gateway/bot_creators/feishu_bot_creator.py disables certificate verification on its HTTPS calls:

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

The very first of these calls POSTs {"app_id": …, "app_secret": …} to <open_base>/open-apis/auth/v3/tenant_access_token/internal — i.e. a freshly minted app secret is transmitted over a connection that accepts any certificate, which is a realistic MITM credential-theft surface (the second call carries the tenant token).

Root cause

The context returned by ssl.create_default_context() was mutated to skip verification. There is no indication the endpoints involved need anything beyond standard verification (open.feishu.cn / open.larksuite.com serve publicly trusted certificates).

Fix

Use the default verifying context as-is (the two mutation lines are removed). No behavior change other than restored verification.

Verification

  • Added test_send_greeting_uses_verifying_tls_context, which stubs urlopen and asserts both greeting-flow calls use CERT_REQUIRED with hostname checking enabled — fails on the old code, passes with the fix.
  • pytest tests/unit/gateway/test_feishu_bot_creator.py: 7 passed; ruff check / ruff format --check clean on touched files.

- _send_greeting disabled certificate verification (CERT_NONE) on the same
  HTTPS calls that transmit the freshly created app_secret, exposing the
  credential to a network MITM; use the default verifying context instead
- add a regression test asserting both greeting calls use CERT_REQUIRED
  with hostname checking enabled

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant