CORS middleware reflects Origin with Allow-Credentials, enabling cross-origin attacks (CWE-346)
维护者通常 1 天内回复
评估
调研方向
先阅读所引用的 st2common/st2common/middleware/cors.py 第 65-69、88 和 91 行,并跟踪已配置的 origin 如何变为响应头。确认通配符 origin 不会获得 credentials,显式列入 allowlist 的 origin 会保留 credentials,并且硬编码的 localhost origin 不存在于生产默认值中。
由索引模型根据 Issue 内容生成。
描述
Summary
The CORS middleware reflects the request's Origin header back as Access-Control-Allow-Origin when the configured allow_origin contains *, while simultaneously setting Access-Control-Allow-Credentials: true. This is a well-known CORS misconfiguration that allows any website to make authenticated cross-origin requests to the StackStorm API.
Affected File
st2common/st2common/middleware/cors.py (lines 65-69, 88, 91)
if origin:
if "*" in origins:
origin_allowed = origin # reflects whatever the browser sends
else:
origin_allowed = origin if origin in origins else list(origins)[0]
# ...
headers["Access-Control-Allow-Origin"] = origin_allowed
# ...
headers["Access-Control-Allow-Credentials"] = "true" # always set
Additionally, the middleware hardcodes localhost development origins that are always allowed:
# Default gulp development server WebUI URL
origins.add("http://127.0.0.1:3000")
# By default WebUI simple http server listens on 8080
origins.add("http://localhost:8080")
origins.add("http://127.0.0.1:8080")
Impact
When allow_origin contains *:
Any website can make authenticated, credential-bearing requests to the StackStorm API from a user's browser. If a StackStorm user visits a malicious page while logged in, the attacker can:
- Read API responses (execution results, datastore values, pack configurations)
- Trigger action executions
- Modify rules and workflows
- Exfiltrate API keys and tokens
This is because the combination of a reflected Access-Control-Allow-Origin and Access-Control-Allow-Credentials: true tells the browser to include cookies/auth headers and allow the response to be read by the requesting page.
Hardcoded localhost origins:
If an attacker can run a web server on localhost:3000 or localhost:8080 on a machine where a StackStorm user has an active session, they can exploit these hardcoded origins. These should not be present in production builds.
Recommended Fix
-
Never reflect the
Originheader whenAccess-Control-Allow-Credentialsistrue. If wildcard origin is configured, either:- Set
Access-Control-Allow-Origin: *and removeAccess-Control-Allow-Credentials(allows unauthenticated CORS only) - Or reject the configuration and log a warning
- Set
-
Remove hardcoded localhost origins from the default allowed list. These should only be present in development configurations.
-
Only set
Access-Control-Allow-Credentials: truewhen the origin is explicitly whitelisted (not wildcarded).
if origin and origin in origins:
headers["Access-Control-Allow-Origin"] = origin
headers["Access-Control-Allow-Credentials"] = "true"
elif "*" in origins:
headers["Access-Control-Allow-Origin"] = "*"
# Do NOT set Allow-Credentials with wildcard origin
References
- CWE-346: Origin Validation Error
- PortSwigger: Exploiting CORS Misconfigurations
- Discovered via manual code review
- 主要语言
- Python
- 星标
- 6.5k
- 派生
- 794
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 5
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
StackStorm/st2 的其他 Issue
-
yaml.FullLoader used instead of SafeLoader in pack metadata parsing (CWE-502)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
StackStorm/st2#6393 · 1 条评论 ·
维护者通常 1 天内回复
-
Git worktree directories created with chmod 777 (CWE-732)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
StackStorm/st2#6392 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
StackStorm/st2#6389 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
StackStorm/st2#6387 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
StackStorm/st2#6416 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
google-agentic-commerce/AP2#388 ·
-
area:codegen backend:cuda backend:hip bug direction:input
难度 2/5 1-3 小时 新手友好度 78/100
CrossGL/crosstl#3061 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
rlaope/oh-my-hermes#2304 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
mochan-tk/agentic-dev-kit-for-codex#64 ·
维护者通常 1 天内回复
-
bug docs performance
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 3 天内回复