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 中的请求上下文设置。记录 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 摘要。