github / github/codeql

Missing "Cross-window communication with unrestricted target origin" because of wrapping by (javascript) blockstatement

未关闭
#19,100 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
acknowledged question
主要语言
CodeQL
星标
10.1k
派生
2.1k
平均合并
2 天 15 小时
30 天内合并 PR
141

描述

Hi,

I am using CodeQL 2.20.6, there is the code:
```js
// {
const t = {};
const r = localStorage.getItem("pw_uuid");
r && JSON.parse(r).data && (t.uuid = JSON.parse(r).data);
window.parent.postMessage(JSON.stringify({
type: "_pwUserDataReady",
key: "",
data: t
}), "*");
// }
```
Where CodeQL should give me a "Cross-window communication with unrestricted target origin" alert but it doesn't.

If I remove the first and last line comments, i.e., wrapping by a block as the code is:
```js
{
const t = {};
const r = localStorage.getItem("pw_uuid");
r && JSON.parse(r).data && (t.uuid = JSON.parse(r).data);
window.parent.postMessage(JSON.stringify({
type: "_pwUserDataReady",
key: "",
data: t
}), "*");
}
```

It does give me one:
```csv
"Cross-window communication with unrestricted target origin", "When sending sensitive information to another window using `postMessage`, the origin of the target window should be restricted to avoid unintentional information leaks.", "error","[[""Sensitive data""|""relative:///iframe.js:3:15:3:45""]] is sent to another window without origin restriction.","/iframe.js", "5", "31", "9", "6"
```

This issue looks the same with but it should be fixed in 2.20.6, shouldn't it?

贡献指南

打开贡献指南

调研方向

Reproduce the report in CodeQL 2.20.6 using the two JavaScript variants, with and without the block wrapper, and compare the results at the reported /iframe.js locations. Read related issue #18652 for context. Done means the unrestricted postMessage is reported in both forms, or the supported limitation is documented.

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
security
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。