The purpose of this application is to demonstrate vulnerabilities when using React. Since React is a front-end framework, most of the vulnerabilities are going to be DOM XSS related. Some of these examples are created to mimic architectural patterns observed in single-page applications developed using a variety of front-end frameworks.
Most output using React is escaped by default. It generally requires using the dangerouslySetInnerHTML
attribute to bypass React's escaping mechanism. It is also possible to write directly into the DOM via non-React DOM manipulation methods.
The API serves the backend portions of the test application. To run it, execute the following commands in a terminal:
cd api
npm install
npm start
The server starts and listens for connections on port 9000.
The React application demonstrates various vulnerabilities. To run the React application, execute the following commands in a terminal:
cd client
npm install
npm start
These are spots where vulnerabilities should be detected.
This is a base class for many React components in the project. This line should be detected as a location where a vulnerability is found:
<div dangerouslySetInnerHTML={{ __html: this.props.genericInput }} />
The InnerElement
function is a React component that has a vulnerability in these lines:
<div className="result" dangerouslySetInnerHTML={{ __html: script }} />
<div dangerouslySetInnerHTML={{ __html: props.genericInput }} />
This may not be considered a vulnerability considering the source
Places a value in href. These lines contain vulnerabilities:
<a className="result" href={this.state.href}>ClickMe</a>
div dangerouslySetInnerHTML={{ __html: this.props.genericInput }} />
There are no vulnerabilities in this file.
These lines contain vulnerabilities:
<div className="result" dangerouslySetInnerHTML={{ __html: this.state.submittedFormValue }} />
<div dangerouslySetInnerHTML={{ __html: this.props.genericInput }} />
There are no vulnerabilities in this file.
These lines contain vulnerabilities:
<div className="result" dangerouslySetInnerHTML={{ __html: this.state.submittedFormValue }} />
<div dangerouslySetInnerHTML={{ __html: this.props.genericInput }} />
There are no vulnerabilities in this file.
There are no vulnerabilities in this file.
There are no vulnerabilities in this file.
These lines contain vulnerabilities:
--><div dangerouslySetInnerHTML={{ __html: props.injectable }} /><--
These lines contain vulnerabilities:
--><div dangerouslySetInnerHTML={{ __html: props.injectable }} /><--
These lines contain vulnerabilities:
document.getElementById('targetDiv').innerHTML = this.state.formValue;
In the function UnsafeRenderFunc
these lines contain vulnerabilities:
Unsafe: <div className="result" dangerouslySetInnerHTML={{ __html: props.val }} />
<div dangerouslySetInnerHTML={{__html: props.genericInput}}/>
There are no vulnerabilities in this file.
These lines contain vulnerabilities:
<div className="result" dangerouslySetInnerHTML={{ __html: this.state.injected }} />
<div dangerouslySetInnerHTML={{__html: this.props.genericInput}} />