Document ASGI-only requirement for BedrockAgentCoreContext

オープン
#219 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

難易度
2/5
見積もり時間
半日
初心者へのやさしさ
45/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python

調査の方向性

src/bedrock_agentcore/runtime/context.py:16-21 から始め、続いて src/bedrock_agentcore/runtime/app.py:299-347 のリクエストコンテキストの設定を確認してください。BedrockAgentCoreContext は ASGI での使用を意図していることを文書化し、WSGI における ContextVar の分離リスクを説明してください。その確認で特定した README または主要なドキュメントの場所を更新してください。完了とは、ユーザーが ASGI 専用要件とセキュリティ上の影響を明確に確認できる状態です。

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

説明

documentation

Summary

BedrockAgentCoreContext uses ContextVar for storing request-scoped sensitive data (workload access tokens, OAuth2 callback URLs, authorization headers). While this is safe for ASGI web frameworks, it creates a critical security vulnerability if used with WSGI frameworks.

Problem

ContextVar isolation behavior:

  • ✅ ASGI frameworks (Starlette, FastAPI, Quart): Automatically isolated per async task (each HTTP request)
  • ❌ WSGI frameworks (Flask, Django WSGI): NOT automatically isolated - threads are reused across requests

Security risk with WSGI:

# WSGI thread pool scenario
# Request A (Thread 1) → BedrockAgentCoreContext.set_workload_access_token("USER_A_TOKEN")
# Request B (Thread 1) → BedrockAgentCoreContext.get_workload_access_token() 
#                     → Returns "USER_A_TOKEN" ❌ (LEAKED!)

This causes:

  • Token leakage between requests
  • Authorization bypass vulnerabilities
  • Data access from one user by another

Current Status

The AgentCore SDK correctly uses Starlette (ASGI), making it safe. However, there's no documentation warning against using BedrockAgentCoreContext in non-ASGI environments.

Recommendation

Add documentation to explicitly state:

  1. In src/bedrock_agentcore/runtime/context.py docstring:

    • BedrockAgentCoreContext is designed for ASGI web frameworks only
    • Using with WSGI frameworks creates security vulnerabilities
    • ContextVars rely on async task isolation, not thread isolation
  2. In README or main documentation:

    • Note that the SDK requires ASGI (already uses Starlette)
    • If users want to integrate with Flask/WSGI, they need alternative approaches (Flask's g object, thread-local storage with manual cleanup)
  3. Consider adding a runtime check (optional):

    • Detect if running in WSGI context
    • Emit warning about unsafe usage

References

  • BedrockAgentCoreContext implementation: src/bedrock_agentcore/runtime/context.py:16-21
  • Context initialization in request handler: src/bedrock_agentcore/runtime/app.py:299-347
  • Python ContextVar documentation: https://docs.python.org/3/library/contextvars.html

Impact

  • Severity: High (security vulnerability if misused)
  • Likelihood: Low (SDK uses Starlette, but users might try to reuse context pattern)
  • Action: Documentation update to prevent misuse
主要言語
Python
スター
786
フォーク
163
平均マージ
4時間
マージ済み PR(30日)
22

環境構築

はじめの一歩

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

aws/bedrock-agentcore-sdk-python のほかの issue

aws/bedrock-agentcore-sdk-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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