--- title: "JavaScript Execution XS Leak" section: "Web Pentesting" sectionSlug: "pentesting-web" sourcePath: "src/pentesting-web/xs-search/javascript-execution-xs-leak.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/xs-search/javascript-execution-xs-leak.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0" --- # JavaScript Execution XS Leak This XS-Search primitive turns **whether a cross-origin response executes as JavaScript** into a **Boolean oracle**.[[1]](#references) The usual setup is: - **Positive state**: the target returns attacker-controlled text or sensitive content that does **not** execute as attacker JavaScript. - **Negative state**: the target reflects attacker-controlled text into a place that is parsed as valid JavaScript, so the attacker can force a callback such as `window.parent.foo()`. - **Leak**: load the target with a classic `

hello2

` res.send(page) }) ``` Main page that generates iframes to the previous `/guessing` page to test each possibility: ```html

hello

``` The attacker logic is:[[2]](#references) 1. Start every candidate as "good". 2. Load the target response as a script. 3. If the response executes `window.parent.foo()`, mark the candidate as wrong. 4. If no callback fires, keep the candidate and continue brute-forcing. ## Minimal Probe Pattern In many real targets, an iframe is not required. A direct script inclusion is enough:[[1]](#references) ```html ``` If the "wrong guess" branch reflects `miss()`, then: - `probe(...) === false` means the callback executed or the load failed - `probe(...) === true` means the script loaded without running the attacker callback For reliability, use a **fresh script element per probe** and add a **cache-buster** such as `?r=${crypto.randomUUID()}`. ## Modern Caveats ### It must be a classic script This primitive relies on the browser fetching the resource as a **classic script**. A plain `