Skip to content
XSS Disclosed report Intermediate

Improperly validated fields allows injection of arbitrary HTML via spoofed React objects

The report triage action's reference field and a trigger criterion's data field accept arbitrary JSON types instead of only strings. An attacker can set these fields to a spoofed React element object, causing the application to render arbitrary HTML and execute script when a victim views the report.

danlec Follow

Originally disclosed on HackerOne

Bounty$5,000 High View original
  • Triaged in 2 hours
  • Fixed in 17 days
  • Paid in 17 days
  • Disclosed after 18 days

Note: I haven't yet investigated the implications of this fully, so this may be more severe than I'm currently aware of. Right now the only exploits I'm aware of allow a team member to attack other team members.

I've found a couple fields that I'd expect to be limited to string values, but which actually accept data of arbitrary types. So far, I've found that these include:

  • The reference field on a report triage action
  • The data field of a trigger criterion

(There are several other fields that seem to accept an arbitrary type, but appear to be converted into strings. The above fields also come back from the server as non-strings.)

By manually crafting the JSON used when setting these fields, a malicious person can set them to non-string values, e.g. arrays or simple objects.

When these fields are rendered, they are assumed to be strings, and passed as the children argument when calling React.createElement. Unfortunately, that argument is allowed to be text content or a React child object. Since these fields can in fact be arbitrary objects, we can create an object that appears to be a React element, and which renders as something dangerous.

Proof of Concept

Here's how the exploit would work, using the reference field on a report:

As an attacker, open up a report and "triage" it, setting the reference field to an object that appears to be a React element. This can be done from the console using the following command:

$.ajax({ 
  url: "https://hackerone.com/reports/bulk", 
  method: 'post', 
  contentType: "application/json", 
  data: JSON.stringify({ 
    state: "open", 
    substate: "triaged", 
    report_ids: [… id of the report …], 
    reply_action: "change-state", 
    reference: {
      _isReactElement: true,
      _store: {},
      type:"body",
      props: {
        dangerouslySetInnerHTML: {
          __html:
            "<h1>Arbitrary HTML</h1><script>alert('No CSP Support :(')</script>"
        }
      }
    }   
  }) 
})

Now, as a victim, open the report and observe that arbitrary HTML has been inserted.

For the curious, here's what the fields in the fake React element do:

  • _isReactElement tricks React into thinking it's rendering an element
  • _store prevents a javascript error (React tries writing some properties of this field)
  • type is the type of element to be rendered
  • props is the properties of the spoofed element. dangerouslySetInnerHTML is a special field that lets you manually set the inner HTML for the element.

The original report as published on HackerOne, by danlec. 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. 5 min read.

Context

HackerOne's report pages include a triage workflow: a team member can change a report's state and substate, and can attach a reference to that triage action. Separately, the platform has trigger criteria, each of which carries a data field. Both fields are meant to hold string values and are rendered on the page as text.

The report describes a client-side injection issue in that rendering path. The researcher notes at the outset that the implications had not been fully investigated, so the issue may be more severe than what was known at the time. The only exploits the researcher was aware of allowed a team member to attack other team members.

Setup

The attack requires a team member account on the target, because the malicious values are set through the triage action on a report. The victim is another team member who opens the affected report. The researcher used the browser console to send the crafted request, so no special tooling beyond a logged-in session is needed.

Finding it

The researcher found a couple of fields that should be limited to string values but actually accept data of arbitrary types:

  • The reference field on a report triage action
  • The data field of a trigger criterion

Several other fields also seemed to accept an arbitrary type, but those appeared to be converted into strings. The two fields above also come back from the server as non-strings, which is what makes them useful.

By manually crafting the JSON used when setting these fields, a malicious person can set them to non-string values, such as arrays or simple objects.

When these fields are rendered, the application assumes they are strings and passes them as the children argument to React.createElement. That argument is allowed to be text content or a React child object. Because the fields can in fact be arbitrary objects, an attacker can create an object that looks like a React element and renders as something dangerous.

Exploitation

Step 1: Set the reference field to a spoofed React element

As an attacker, open a report and triage it, setting the reference field to an object that appears to be a React element. From the console:

JavaScript
$.ajax({
  url: "https://hackerone.com/reports/bulk",
  method: 'post',
  contentType: "application/json",
  data: JSON.stringify({
    state: "open",
    substate: "triaged",
    report_ids: [… id of the report …],
    reply_action: "change-state",
    reference: {
      _isReactElement: true,
      _store: {},
      type:"body",
      props: {
        dangerouslySetInnerHTML: {
          __html:
            "<h1>Arbitrary HTML</h1><script>alert('No CSP Support :(')</script>"
        }
      }
    }
  })
})

The request posts to the bulk reports endpoint with contentType: "application/json", so the body is sent as JSON rather than form-encoded. It sets state to open, substate to triaged, targets the report through report_ids, and uses reply_action: "change-state". The reference value is not a string but an object shaped like a React element.

The fields in the fake React element do the following:

  • _isReactElement tricks React into thinking it is rendering an element
  • _store prevents a JavaScript error, because React tries writing some properties of this field
  • type is the type of element to be rendered, here body
  • props holds the properties of the spoofed element; dangerouslySetInnerHTML is a special field that lets you manually set the inner HTML for the element

The injected HTML is an <h1> heading and a <script> that calls alert, with the message noting the absence of CSP support.

Step 2: Trigger rendering as the victim

As a victim, open the report. The arbitrary HTML has been inserted into the page.

Root cause

The server accepts non-string values for the reference field (and for the data field of a trigger criterion) and returns them as non-strings. The client then assumes these values are strings and passes them straight into React.createElement as children. React treats an object with the expected shape as a child element rather than as text, so the attacker controls the element type and its props, including dangerouslySetInnerHTML.

The payload's alert message refers to a lack of CSP support; the report does not say whether the script executed. The report does not describe any server-side type validation or output encoding that would have stopped the object from being stored or rendered.

Impact

A team member can attack other team members: the attacker sets the malicious value through triage, and any team member who opens the report renders the injected HTML. The researcher explicitly hedges that the implications had not been fully investigated and that this may be more severe than what was known at the time.

Fix

The implied requirement is to validate these fields as strings on the server, so that objects and arrays are rejected or coerced before storage, and to avoid passing unvalidated values as React children. A CSP would also have blocked the inline script in the payload.

Variants to test

  • Send an object instead of a string for any field that is rendered as text, and check whether the server returns it as an object. A positive result is a non-string value coming back from the API.
  • Try the same spoofed element shape (_isReactElement, _store, type, props) in other fields that reach React.createElement. A positive result is rendered HTML rather than the literal object.
  • Try the data field of a trigger criterion, the second field named in the report. A positive result is the same arbitrary HTML insertion when the criterion is displayed.
  • Try array values where strings are expected. A positive result is the array surviving the round trip and being rendered in an unexpected way.

Hunting notes

This kind of bug hides where a client framework renders server-supplied values as children and the server does not enforce types. The signal is an API that echoes back a value with a different type from the one you sent, or accepts a JSON body where the UI only ever sends strings. The researcher demonstrated impact by setting the value through a triage action and showing that a team member opening the report saw arbitrary HTML inserted.

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

What happened, in plain words

HackerOne is a website where security researchers report bugs to companies. Each report has a page, and team members can move a report through stages (for example from "open" to "triaged"). When they do that, they can attach a short note called a reference to the action.

The researcher found that this reference field, and a second field called data on something called a trigger criterion, were supposed to hold plain text. Instead, the server accepted more complicated values, such as lists or objects, and handed them back unchanged. When the page displayed those values, the code assumed they were text and passed them to a piece of software called React, which builds the page. React can be fooled: if you give it an object that looks like one of its own building blocks, it will render it as real page content. The researcher used this to make the page insert arbitrary HTML, including a script, into a report. Any team member who opened that report would see the injected HTML.

The researcher said at the start that the full implications had not been investigated, so the issue might be more severe than what was known at the time. The only attacks the researcher knew of let one team member attack other team members.

Background you need

A few ideas come up again and again, so here they are from scratch.

  • A web page and its server. Your browser asks a server for a page, the server sends back files, and the browser draws the page. Some pages also send small requests in the background to fetch or change data without reloading. Those background requests are what people call an API (application programming interface): a set of addresses the page can talk to, each expecting a particular kind of request.
  • JSON. When a page sends data to a server, it often writes it in JSON, a text format for structured values. A JSON value can be a piece of text in quotes (a string), a number, true or false, a list of values in square brackets (an array), or a set of named values in curly braces (an object). The important point here: a string is just text, while an object can carry a whole structure inside it.
  • The browser console. Every browser has a developer console where you can type commands that run inside the page you have open. It is a way to send requests by hand, without clicking through the interface.
  • React. React is a JavaScript library for building user interfaces. You describe what should appear on the page by calling a function, React.createElement, and React turns your description into real page elements. The description you pass in is called a React element. React also accepts plain text as the content of an element, and it decides which it has been given by looking at the shape of the value.
  • dangerouslySetInnerHTML. React normally escapes text so that HTML tags in it are shown as text rather than interpreted. This special property is the deliberate exception: it lets a developer hand React a block of raw HTML to insert as-is. The name is a warning.
  • CSP (Content Security Policy). A rule a website can send to the browser saying which sources of scripts are allowed. A strict policy blocks scripts that are written directly into the page, which is exactly the kind of script used in this attack.
  • Cross-site scripting (XSS). The general name for a bug where an attacker gets their own code, usually JavaScript, to run inside someone else's browser session on a website. The code then runs with the trust the site gives that page.

The setup

The attacker needs to be a team member on the target, because the malicious value is set through the triage action on a report. The victim is another team member who opens the affected report. The researcher sent the crafted request from the browser console, so nothing beyond a logged-in session is needed.

Finding it

The researcher found a couple of fields that should be limited to string values but actually accept data of arbitrary types:

  • The reference field on a report triage action
  • The data field of a trigger criterion

Several other fields also seemed to accept an arbitrary type, but those appeared to be converted into strings. The two fields above also come back from the server as non-strings, which is what makes them useful: the strange value survives the trip to the server and back.

By manually crafting the JSON used when setting these fields, a malicious person can set them to non-string values, such as arrays or simple objects.

When these fields are rendered, the application assumes they are strings and passes them as the children argument to React.createElement. That argument is allowed to be text content or a React child object. Because the fields can in fact be arbitrary objects, an attacker can create an object that looks like a React element and renders as something dangerous.

In everyday terms: the page expects a label to stick on a box, and the server lets you hand it a whole box instead. React sees a box and treats it as part of the page.

Exploitation

Step 1: Set the reference field to a spoofed React element

As an attacker, open a report and triage it, setting the reference field to an object that appears to be a React element. From the console:

JavaScript
$.ajax({
  url: "https://hackerone.com/reports/bulk",
  method: 'post',
  contentType: "application/json",
  data: JSON.stringify({
    state: "open",
    substate: "triaged",
    report_ids: [… id of the report …],
    reply_action: "change-state",
    reference: {
      _isReactElement: true,
      _store: {},
      type:"body",
      props: {
        dangerouslySetInnerHTML: {
          __html:
            "<h1>Arbitrary HTML</h1><script>alert('No CSP Support :(')</script>"
        }
      }
    }
  })
})

Line by line:

  1. $.ajax({ starts a request using jQuery's helper for talking to a server. Everything inside the braces describes the request.
  2. url: "https://hackerone.com/reports/bulk" is the address being called. It is the bulk reports endpoint, a single address that can act on several reports at once.
  3. method: 'post' says this request sends data to the server rather than just asking for a page.
  4. contentType: "application/json" tells the server the body is JSON, not the form format a browser normally submits. This matters because the attack depends on sending structured values, which forms cannot express.
  5. data: JSON.stringify({ converts a JavaScript object into a JSON string for the body, and opens that object.
  6. state: "open" and substate: "triaged" are the new state of the report, the same values the normal triage buttons would set.
  7. report_ids: [… id of the report …] is where the target report is named. The report shows this as a placeholder rather than a real number.
  8. reply_action: "change-state" says which triage action is being performed.
  9. reference: { is the field that should be a short piece of text. Instead it is an object, and that object is shaped to look like a React element.
  10. _isReactElement: true is the flag that makes React believe this object is one of its own elements.
  11. _store: {} is an empty object that stops a JavaScript error, because React tries to write some properties into this field.
  12. type:"body" is the kind of page element to create, here the page body.
  13. props: { holds the properties of that element.
  14. dangerouslySetInnerHTML: { and __html: together give React a block of raw HTML to insert without escaping it.
  15. The HTML itself is "<h1>Arbitrary HTML</h1><script>alert('No CSP Support :(')</script>": a large heading reading "Arbitrary HTML", followed by a script that pops up an alert box. The message in the alert refers to a lack of CSP support.
  16. The closing braces and brackets finish the object and the request.

The request posts to the bulk reports endpoint with contentType: "application/json", so the body is sent as JSON rather than form-encoded. It sets state to open, substate to triaged, targets the report through report_ids, and uses reply_action: "change-state". The reference value is not a string but an object shaped like a React element.

The fields in the fake React element do the following:

  • _isReactElement tricks React into thinking it is rendering an element
  • _store prevents a JavaScript error, because React tries writing some properties of this field
  • type is the type of element to be rendered, here body
  • props holds the properties of the spoofed element; dangerouslySetInnerHTML is a special field that lets you manually set the inner HTML for the element

The injected HTML is an <h1> heading and a <script> that calls alert, with the message noting the absence of CSP support.

Step 2: Trigger rendering as the victim

As a victim, open the report. The arbitrary HTML has been inserted into the page. No click on a link or download is needed: simply opening the report shows the inserted HTML.

Root cause

The server accepts non-string values for the reference field (and for the data field of a trigger criterion) and returns them as non-strings. The client then assumes these values are strings and passes them straight into React.createElement as children. React treats an object with the expected shape as a child element rather than as text, so the attacker controls the element type and its props, including dangerouslySetInnerHTML.

The payload's own alert message points at the missing defence: the injected script ran, which the researcher attributes to no CSP support. The report does not describe any server-side type validation or output encoding that would have stopped the object from being stored or rendered.

Impact

A team member can attack other team members: the attacker sets the malicious value through triage, and any team member who opens the report renders the injected HTML. The researcher explicitly hedges that the implications had not been fully investigated and that this may be more severe than what was known at the time. The report does not describe exploitation against users outside the team.

Fix

The implied requirement is to validate these fields as strings on the server, so that objects and arrays are rejected or coerced before storage, and to avoid passing unvalidated values as React children. A CSP would also have blocked the inline script in the payload.

Variants to test

  • Send an object instead of a string for any field that is rendered as text, and check whether the server returns it as an object. A positive result is a non-string value coming back from the API.
  • Try the same spoofed element shape (_isReactElement, _store, type, props) in other fields that reach React.createElement. A positive result is rendered HTML rather than the literal object.
  • Try the data field of a trigger criterion, the second field named in the report. A positive result is the same arbitrary HTML insertion when the criterion is displayed.
  • Try array values where strings are expected. A positive result is the array surviving the round trip and being rendered in an unexpected way.

Hunting notes

This kind of bug hides where a client framework renders server-supplied values as children and the server does not enforce types. The signal is an API that echoes back a value with a different type from the one you sent, or accepts a JSON body where the UI only ever sends strings. The researcher demonstrated impact by setting the value through a triage action and showing that a team member opening the report saw arbitrary HTML inserted.

Glossary

  • API: a set of addresses a web page uses to fetch or change data on a server in the background.
  • Array: a list of values written in square brackets in JSON.
  • Browser console: a panel in the browser where you can type commands that run inside the open page.
  • Content Security Policy (CSP): a rule sent by a website telling the browser which scripts are allowed to run, used to block injected scripts.
  • Cross-site scripting (XSS): a bug where an attacker's code runs inside another person's browser session on a website.
  • dangerouslySetInnerHTML: a React property that inserts raw HTML without escaping it.
  • Endpoint: a specific address on a server that accepts a particular kind of request.
  • JSON: a text format for structured data, with strings, numbers, booleans, arrays and objects.
  • Object: a set of named values written in curly braces in JSON.
  • React: a JavaScript library for building user interfaces out of elements.
  • React element: React's description of a piece of the page, created with React.createElement.
  • React.createElement: the React function that turns a description into a page element; its content argument is called children.
  • String: a piece of text, written in quotes in JSON.
  • Triage: the process of reviewing a report and moving it through stages such as open and triaged.
  • Trigger criterion: a condition on the platform that carries a data field, the second field named in the report.

More by danlec

View all

6 more disclosed reports, best first.

More from HackerOne

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.