slackapi / slackapi/bolt-python

`extract_team_id` crashes with `TypeError when payload["user"]` is a string (e.g. `member_joined_channel` events)

オープン 初心者向け
#1,447 コメント 9 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

auto-triage-skip bug security semver:major
主要言語
Python
スター
1.3k
フォーク
288
平均マージ
1日 8時間
マージ済み PR(30日)
10

説明

Reproducible in:
The slack_bolt version
slack-bolt==1.27.0
slack-sdk==3.39.0
Python runtime version
Python 3.14.0
OS info
ProductName:    macOS
ProductVersion: 26.3
BuildVersion:   25D125
Darwin Kernel Version 25.3.0: Wed Jan 28 20:53:05 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T6020
Steps to reproduce:
  1. Register a member_joined_channel listener in a Slack Bolt app:
@app.event("member_joined_channel")
def handle_channel_join(event, client, say):
    say("Hello!")
  1. Add the bot to any Slack channel.

  2. Observe the incoming event payload — Slack sends "user" as a plain string (the user ID):

{
  "type": "member_joined_channel",
  "user": "U0123456789",
  "channel": "C0123456789",
  "team": "T0123456789"
}
Expected result:

The listener is invoked normally.

Actual result:

The request crashes before the listener is reached, with:

TypeError: string indices must be integers, not 'str'

File "slack_bolt/adapter/aws_lambda/handler.py", line 87, in to_bolt_request
    return BoltRequest(
File "slack_bolt/request/request.py", line 69, in __init__
    self.context = build_context(BoltContext(context if context else {}), self.body)
File "slack_bolt/request/internals.py", line 276, in build_context
    team_id = extract_team_id(body)
File "slack_bolt/request/internals.py", line 116, in extract_team_id
    return payload["user"]["team_id"]
Root cause

extract_team_id in slack_bolt/request/internals.py assumes payload["user"] is always a dict:

if payload.get("user") is not None:
    return payload["user"]["team_id"]

But member_joined_channel sends "user" as a plain string (the user ID). Accessing "U0123456789"["team_id"] raises the TypeError.

The same function already handles payload["team"] correctly with an isinstance check:

if payload.get("team") is not None:
    team = payload.get("team")
    if isinstance(team, str):
        return team
    elif team and "id" in team:
        return team.get("id")

The same guard is missing for payload["user"]. This pattern (subscribing to member_joined_channel and checking if the joined user is the bot) is what maintainers recommend in #710, so users following that guidance will hit this bug.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

slack_bolt/request/internals.py の extract_team_id から始め、既存の payload["team"] の型処理を確認します。user に文字列値を指定した member_joined_channel payload を再現し、request の処理が TypeError なしで listener に到達することを確認します。user フィールドが文字列値の場合でも team ID の抽出でクラッシュせず、既存の payload 形式も引き続き動作すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
api, backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
72/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。