Document ASGI-only requirement for BedrockAgentCoreContext

未關閉
#219 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
半天
新手友好度
45/100
Issue 類型
文件
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
python

研究方向

從 src/bedrock_agentcore/runtime/context.py:16-21 開始,然後檢視 src/bedrock_agentcore/runtime/app.py:299-347 中的 request context 設定。記錄 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 小時
30 天內合併 PR
22

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

aws/bedrock-agentcore-sdk-python 的其他 Issue

查看 aws/bedrock-agentcore-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。