Create tes1t.html#26
Conversation
⏭️ Hacktron Security Check — SkippedReason: PR review limit reached for this billing period. Spillover billing is available for this org but is not enabled.
|
There was a problem hiding this comment.
🔴 High: DOM-based XSS via insecure postMessage handling in tes1t.html
The application implements a message event listener in tes1t.html that fails to validate the event.origin property. It then directly takes the event.data and assigns it to the DOM using innerHTML. This allows an attacker to send a cross-origin message containing malicious HTML/JavaScript, which will be executed in the context of the page.
Evidence: tes1t.html:32-38
- Line 32:
window.addEventListener('message', (event) => { - Line 37:
const incoming = typeof event.data === 'string' ? event.data : JSON.stringify(event.data); - Line 38:
document.getElementById('output').innerHTML = incoming;
Steps to Reproduce
- Open
tes1t.htmlin a browser. - Open the browser console on a different origin (e.g.,
example.com). - Execute:
window.opener.postMessage('<img src=x onerror=alert(1)>', '*'); - An alert will trigger on the vulnerable page.
Fix with AI
Fix the following security vulnerability found by Hacktron.
File: tes1t.html
Severity: high
Vulnerability: DOM-based XSS via insecure postMessage handling in tes1t.html
Description:
The application implements a `message` event listener in `tes1t.html` that fails to validate the `event.origin` property. It then directly takes the `event.data` and assigns it to the DOM using `innerHTML`. This allows an attacker to send a cross-origin message containing malicious HTML/JavaScript, which will be executed in the context of the page.
Evidence: [tes1t.html:32-38](./testerror/tes1t.html:32-38)
- Line 32: `window.addEventListener('message', (event) => {`
- Line 37: `const incoming = typeof event.data === 'string' ? event.data : JSON.stringify(event.data);`
- Line 38: `document.getElementById('output').innerHTML = incoming;`
Proof of Concept:
1. Open `tes1t.html` in a browser.
2. Open the browser console on a different origin (e.g., `example.com`).
3. Execute: `window.opener.postMessage('<img src=x onerror=alert(1)>', '*');`
4. An alert will trigger on the vulnerable page.
Fix this vulnerability. Only change what's necessary - don't modify unrelated code.
Triage: Reply !fp <reason> (false positive), !valid (confirmed), or !accepted_risk <reason>. Reason is optional but improves future scans — e.g. !fp internal endpoint, not user-facing. Any other reply is saved as a triage note.
No description provided.