Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Anemone95 opened this issue Mar 24, 2025 · 2 comments
Labels
acknowledged GitHub staff acknowledges this issue question Further information is requested

Comments

@Anemone95
Copy link

Anemone95 commented Mar 24, 2025

Hi,

I am using CodeQL 2.20.6, there is the code:

// {
    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:

{
    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:

"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 #18652 but it should be fixed in 2.20.6, shouldn't it?

@Anemone95 Anemone95 added the question Further information is requested label Mar 24, 2025
@asgerf
Copy link
Contributor

asgerf commented Mar 24, 2025

Hi @Anemone95,

Thanks for reporting this. The underlying issue here is that global variables are tracked less precisely than local variables, and the block statement turns t and r into local variables. We're the aware of the reduced precision for global variables.

@asgerf asgerf added the acknowledged GitHub staff acknowledges this issue label Mar 24, 2025
@Anemone95
Copy link
Author

Got it. Thank you for your answer~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged GitHub staff acknowledges this issue question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants