Skip to content
XSS Write-up Beginner

Persisting on Pornhub

Andy Gill Follow

Published on blog.zsec.uk

Bounty$1,500 View original

This guy again? More Pornhub bounty things?

Andy Gill (@ZephrFish), on blog.zsec.uk

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.

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. 4 min read.

Context

Pornhub's core site (pornhub.com) has a profile feature called the stream, a per-user feed where the account owner can post content. The stream accepts BBCode-style markup, so a user can post links that are rendered on their own profile page. The report covers a stored cross-site scripting issue in that stream function: a crafted BBCode URL containing JavaScript was persisted and executed when another user moused over the rendered link.

The author rates the difficulty as low and the risk as high, and notes that the high-risk rating reflects the affected demographic and the impact of the payloads. The affected URL is pornhub.com.

Persisting on Pornhub
Persisting on Pornhub From the original on blog.zsec.uk

Setup

No special tooling, accounts or versions are described. The precondition is simply an account that can post to its own stream, plus a victim who views the profile and interacts with the link. The report was filed on HackerOne as report 138075.

Timeline as given in the report:

Event Date
Reported on HackerOne to Pornhub 11 May 2016
Issue marked as duplicate 12 May 2016
Issue reopened as closed in error 20 July 2016
Issue resolved 17 August 2016
Pornhub awarded $1500 bounty 12 September 2016
Issue disclosed 24 September 2016
ranked
ranked From the original on blog.zsec.uk

Finding it

The researcher identified that malicious BBCode URLs could be crafted on the stream function, producing persistent (stored) cross-site scripting.

Exploitation

The payload posted to the stream was the following BBCode string:

Text
[url=http://www.pornhub.com/"onmouseover="alert(document.domain)" ] target="_blank">http://[url=http://www.pornhub.com/"/onmouseover="alert(document.domain)"/]http://a/"[/url]

The payload embeds onmouseover="alert(document.domain)" in the URL; when the link is rendered on the profile, mousing over it shows an alert containing the document domain. The nested [url] and the trailing http://a/" are part of the same string as posted. When the resulting link is rendered on the profile, mousing over it fires the handler and shows an alert containing the document domain.

User Stream XSS
User Stream XSS From the original on blog.zsec.uk

The screenshot shows the link present in the user's stream and the alert box displayed, confirming both that the link is valid and that the handler executes.

Step 1: open the stream composer

Navigate to the user profile stream page and select "post to your stream".

Step 1
Step 1 From the original on blog.zsec.uk

Step 2: select Post

Select "Post".

Step 2
Step 2 From the original on blog.zsec.uk

Step 3: inject the payload

Inject a payload string similar to the one shown above into the stream post.

Step 3
Step 3 From the original on blog.zsec.uk

Step 4: submit and inspect the request

Click post/submit. The captured snippet of the POST request shows the payload included twice. The report does not reproduce the request itself, only the screenshot of it.

Step 4
Step 4 From the original on blog.zsec.uk

Steps 5 and 6: the payload lies dormant, then fires

The payload URL sits in the stream until an unsuspecting user mouses over the link, at which point the handler executes.

Step 5
Step 5 From the original on blog.zsec.uk
Step 5
Step 5

Root cause

The stream's BBCode renderer builds an anchor from the [url=...] value without correctly encoding or validating the URL before placing it into the attribute. Because the value is inserted into markup, a double quote in the URL terminates the attribute and lets the poster add a new one, here onmouseover. The stream is persistent, so the posted link remains on the profile and fires when a user mouses over it. The report does not describe the server-side code, so the exact escaping routine that failed is not stated; .

Impact

The issue is stored: any user could post malicious links to their stream, and the payload executes when another user mouses over the link on the profile. The report demonstrates execution with alert(document.domain) and notes that more weaponised payloads could have been used, such as a BeEF hook. The report demonstrates script execution with alert(document.domain) and notes that more weaponised payloads could have been used, such as a BeEF hook. The author rated the risk high given the affected demographic and the impact of the payloads. The report does not quantify how many users were exposed or whether any additional conditions (such as authentication state) were required beyond viewing the profile.

Fix

Pornhub patched the issue, and the report states that the method is no longer a working way to deliver the exploit. The specific code change is not described.

Variants to test

  1. Other BBCode attributes that take a URL or free text, such as image sources or quote attributions. A positive result is a stored post whose rendered markup contains an event handler or a broken-out attribute.
  2. Quote and angle-bracket characters in the URL field, including single quotes and backticks. A positive result is an alert or a visibly altered DOM attribute on mouseover.
  3. The same payload submitted through different entry points (API, mobile client, direct POST) to see whether validation is applied consistently. A positive result is a payload that is rejected in the web form but accepted and rendered through another path.
  4. Re-submission and editing of an existing stream post. A positive result is a payload that survives an edit round-trip and still fires on view.

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.

What happened, in plain words

Pornhub is a website. Like most large sites, it lets each registered user have a personal page, and on that page there is a small feed called the stream. Think of the stream as a personal noticeboard: the account owner can pin short posts to it, and anyone who visits the profile can read them. The stream accepts a simple formatting language called BBCode, which is a way of writing text with square brackets to add links, images and other formatting. For example, [url=...] is how you tell the site "make this a clickable link".

A security researcher found that malicious BBCode URLs could be crafted on the stream, producing stored cross-site scripting. He could put extra characters into that address so that, when the site turned his post into a real web page, the browser was tricked into running a small piece of JavaScript (a programming language that runs inside your browser) whenever someone moved their mouse over the link. Because the post is saved on the profile, an unsuspecting user who mouses over the link triggers it. This kind of bug is called stored cross-site scripting, or stored XSS for short.

Persisting on Pornhub
Persisting on Pornhub From the original on blog.zsec.uk

The author describes the difficulty as Low and the risk as High. The affected address is pornhub.com. The report was filed on HackerOne, a website where security researchers report bugs to companies, under report number 138075. It was reported on 11 May 2016, made public on 24 September 2016, and paid a bounty (a reward) of $1500. The high-risk label, the author explains, reflects the kind of audience the site has and how damaging the payloads could have been.

ranked
ranked From the original on blog.zsec.uk

Timeline of events

A timeline is useful here because it shows how a bug report moves through a company's process. "Duplicate" means someone else had already reported the same bug. "Reopened" means the report was closed by mistake and then brought back. "Resolved" means the company fixed it. "Disclosed" means the details were made public.

Event Date
Reported on HackerOne to Pornhub 11 May 2016
Issue marked as duplicate 12 May 2016
Issue reopened as closed in error 20 July 2016
Issue resolved 17 August 2016
Pornhub awarded $1500 bounty 12 September 2016
Issue disclosed 24 September 2016

How the bug worked

The researcher found that he could build a malicious BBCode link on the stream. BBCode is a simple markup language: you write something like [url=...] and the site converts it into a real HTML link (HTML is the language browsers use to build pages). The problem was that a crafted BBCode URL with JavaScript embedded in it was accepted and rendered as a link on the profile. If you put a double quote character (") inside that address, you could end the part of the HTML that holds the address and start a new part of your own. That is how the researcher could sneak in an instruction that the browser would treat as code.

Before the fix, a user could post a link like the one below, which has JavaScript embedded in the URL:

Text
[url=http://www.pornhub.com/"onmouseover="alert(document.domain)" ] target="_blank">http://[url=http://www.pornhub.com/"/onmouseover="alert(document.domain)"/]http://a/"[/url]

Let us walk through this string piece by piece, because the whole trick lives in the punctuation:

  • [url= starts a BBCode link. Everything up to the closing ] is meant to be the address the link points to.
  • http://www.pornhub.com/ is the start of a normal-looking address. It makes the post look harmless.
  • " is a double quote. In HTML, attributes (the extra settings on a tag, like the address of a link) are wrapped in quotes. This quote is the researcher's way of saying "the address ends here".
  • onmouseover= is the name of an HTML event handler. An event handler is a small instruction that the browser runs when something happens, in this case when the mouse moves over the element.
  • "alert(document.domain)" is the instruction itself. alert(...) opens a pop-up box, and document.domain is the address of the page you are on. So the pop-up shows the site's own address, which proves the code is running as if it belonged to the site.
  • [url=http://www.pornhub.com/"/onmouseover="alert(document.domain)"/]http://a/" is a second, nested copy of the same trick. The report notes that the payload ends up in the request twice.
  • [/url] closes the BBCode link.

When the site turned this into a real link on the profile, the browser saw a link whose address ended early and whose extra setting said "run this code on mouseover". The result was a link that looked normal but fired a pop-up as soon as someone hovered over it.

User Stream XSS
User Stream XSS From the original on blog.zsec.uk

The screenshot shows the link sitting in the user's stream and the pop-up box appearing, which confirms two things: the link is accepted as valid, and the code really runs.

Step 1: open the stream composer

The researcher went to his own profile's stream page and chose the option to post to his stream. This is the same button any normal user would click to write a post.

Step 1
Step 1 From the original on blog.zsec.uk

Step 2: select Post

He then selected "Post".

Step 2
Step 2 From the original on blog.zsec.uk

Step 3: inject the payload

He pasted the payload string shown earlier into the post. The word inject here simply means "put in". The point of this step is to see whether the site accepts the strange characters without complaint.

Step 3
Step 3 From the original on blog.zsec.uk

Step 4: submit and inspect the request

He clicked post/submit. When you submit a form on a website, your browser sends a request to the server: a message saying "here is what I typed, please save it". The screenshot shows a snippet of that request, and the payload appears in it twice. The report does not reproduce the request text itself, only the screenshot of it.

Step 4
Step 4 From the original on blog.zsec.uk

Steps 5 and 6: the payload lies dormant, then fires

After the post is saved, the link sits quietly on the profile. It does nothing until an unsuspecting visitor moves their mouse over it. At that moment the browser runs the onmouseover instruction and the pop-up appears. This is why the bug is called stored: the dangerous content is saved and fires when another user mouses over the link.

Step 5
Step 5 From the original on blog.zsec.uk
Step 5
Step 5

Why it happened

When the site converts BBCode into HTML, it builds a link tag and puts the address from [url=...] inside it. If the address is not cleaned up first, a double quote in the address ends the attribute early, and anything after it becomes a new attribute of the poster's choosing. Here the new attribute was onmouseover. Because the stream is saved and shown to everyone who visits the profile, the code runs in each visitor's browser, on the site's own pages. The report does not describe the server-side code, so the exact cleaning routine that failed is not stated.

What the impact was

Any user could post a malicious link to their stream, and the code ran when another user hovered over it. The researcher used alert(document.domain) only to prove the point: a pop-up is harmless, but the same trick could have loaded a more serious tool, such as a BeEF hook. BeEF is a framework that lets an attacker control a victim's browser once code is running in it. The researcher used alert(document.domain) to prove the point, and the author rated the risk high given the affected demographic and the impact of the payloads. The report does not say how many users were exposed, or whether any extra conditions, such as being logged in, were needed beyond viewing the profile.

The fix

Pornhub patched the issue, and the report states that the method no longer works. The specific code change is not described.

Other places to look

If you were testing a site like this yourself, these are the variations worth trying. Each one is a way of asking the same question: does the site clean up this input everywhere it is used?

  1. Other BBCode attributes that take an address or free text, such as image sources or quote attributions. A positive result is a saved post whose page contains an event handler or a broken-out attribute.
  2. Quote and angle-bracket characters in the address field, including single quotes and backticks. A positive result is a pop-up or a visibly altered attribute when you hover.
  3. The same payload sent through different entry points (an API, a mobile app, a direct form submission) to see whether the checks are applied everywhere. An API is a way for programs to talk to a site without using its web pages. A positive result is a payload that the web form rejects but another path accepts and shows.
  4. Re-submitting and editing an existing stream post. A positive result is a payload that survives an edit and still fires when viewed.

Glossary

  • API: a way for one program to talk to another over the internet, usually without a human clicking through web pages.
  • Attribute: an extra setting on an HTML tag, such as the address of a link or the text shown when you hover.
  • BBCode: a simple formatting language that uses square brackets, like [url=...], to add links and other formatting to posts.
  • BeEF: a tool that lets an attacker control a victim's browser once malicious code is running in it.
  • Bounty: a reward a company pays a researcher for reporting a security bug.
  • Browser: the program you use to view websites, such as Chrome, Firefox or Safari.
  • Cross-site scripting (XSS): a bug where a site lets an attacker's code run in another user's browser as if it belonged to the site.
  • Disclosed: made public, usually after the company has fixed the bug.
  • DOM: the browser's in-memory model of the page, which scripts can read and change.
  • Duplicate: a bug report that describes the same issue as one already filed.
  • Event handler: a small instruction attached to an element that runs when something happens, such as a mouse moving over it.
  • HackerOne: a website where researchers report security bugs to companies and can earn bounties.
  • HTML: the language browsers use to build web pages.
  • JavaScript: the programming language that runs inside browsers and makes pages interactive.
  • Payload: the piece of text or code an attacker sends to try to trigger a bug.
  • Persistent / stored: a bug where the malicious content is saved on the server and shown to every visitor, not just the person who submitted it.
  • Request: a message your browser sends to a server, for example when you submit a form.
  • Resolved: marked as fixed by the company.
  • Stream: the personal feed on a Pornhub profile where the account owner can post content.
  • URL: the address of a page or resource on the web, such as http://www.pornhub.com/.
  • XSS: short for cross-site scripting.

More by Andy Gill

View all

4 more disclosed reports, best first.

More from PornHub

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.