github / github/codeql

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

Aperta
#19,100 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
acknowledged question
Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 15h
PR unite (30g)
141

Descrizione

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?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Riproduci il report in CodeQL 2.20.6 con le due varianti JavaScript, con e senza il wrapper di blocco, e confronta i risultati nelle posizioni /iframe.js indicate nel report. Leggi l’issue correlata #18652 per il contesto. Il lavoro è completato quando il postMessage senza restrizioni viene segnalato in entrambe le forme, oppure viene documentata la limitazione supportata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
security
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.