I've asked this on Stack Overflow because it is related to a programming problem (how to mititgate vulnerabilities in code) but I do have some broader questions, and a lack of understanding about how to mitigate the vulnerability. Please note the update section below where I have put in place the mitigations in these linked questions here and here.

I've run a pen test tool (Burp) against my node(express)/angular application and it identified a reflected XSS vulnerability specifically when attempting a GET request for static assets (noticeably vulnerabilities were not found for any of the requests being made when a user interacts with the application).

The issue detail is:

The name of an arbitrarily supplied URL parameter is copied into a JavaScript expression which is not encapsulated in any quotation marks. The payload 41b68(a)184a9=1 was submitted in the name of an arbitrarily supplied URL parameter. This input was echoed unmodified in the application's response.

This behavior demonstrates that it is possible to inject JavaScript commands into the returned document. An attempt was made to identify a full proof-of-concept attack for injecting arbitrary JavaScript but this was not successful. You should manually examine the application's behavior and attempt to identify any unusual input validation or other obstacles that may be in place.

The vulnerability was tested by passing an arbitrary url parameter to the request like so:

GET /images/?41b68(a)184a9=1

The response was:

HTTP/1.1 404 Not Found
X-Content-Security-Policy: connect-src 'self'; default-src 'self'; font-src 'self'; frame-src; img-src 'self' *.google-analytics.com; media-src; object-src; script-src 'self' 'unsafe-eval' *.google-analytics.com; style-src 'self' 'unsafe-inline'
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
Strict-Transport-Security: max-age=10886400; includeSubDomains; preload
X-Download-Options: noopen
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 52
Date: Wed, 08 Oct 2015 10:46:43 GMT
Connection: close

Cannot GET /images/?41b68(a)184a9=1

You can see that I have CSP in place (using Helmet to implement) and other protections against exploits. The app is served over https, but no user auth is required. CSP restricts requests from the app's domain and google analytics.

The pen test report advises validating input (I am, but surely that would make requests including data sent by a user unsafe if I wasn't?), and encoding html which angular does by default, plus GET request urls are being escaped (see update below).

I'm really struggling to find a solution to preventing or mitigating this for those requests for static assets:

  • Should I whitelist all requests for my application under csp?
  • Can I even do this, or will it only whitelist domains?
  • Can/should all responses from node/express to requests for static assets be encoded in some way (see update on url escaping below)?
  • The report states that "The name of an arbitrarily supplied URL parameter is copied into a JavaScript expression which is not encapsulated in any quotation marks". Could this expression be somewhere in the express code that handles returning static assets?
  • Or that GET request param can somehow be evaluated in my application code?


Having done some investigation into this it seems that at least part of the mitigation is to escape data in url param values and sanitize the input in the url.

Escaping of the url is already in place so:

curl 'http://mydomain/images/?<script>alert('hello')</script>'


Cannot GET /images/?&lt;script&gt;alert(hello)&lt;/script&gt;

I've also put express-sanitized in place on top of this.

However, if I curl the original test the request param is still reflected back.

curl 'http://mydomain/images/?41b68(a)184a9=1'
Cannot GET /images/?41b68(a)184a9=1

Which you would expect because html is not being inserted into the url.

The responses to GET requests for static assets are all handled by app.use(express.static('static-dir')) so the query is passed into this. express.static is based on serve-static which depends on parseurl.


1 Answer 1


The cause of the issue is that for invalid GET requests express will return something like:

Cannot GET /pathname/?yourQueryString

Which in many cases is a valid response, even for serving static assets. However, in my case and I'm sure for others the only valid requests for static assets will be something like:

GET /pathname/your-file.jpg

I have a custom 404 handler that returns a data object:

var data = {
    status: 404,
    message: 'Not Found',
    description: description,
    url: req.url

This is only handled for invalid template requests in app.js with:

app.use('/template-path/*', function(req, res, next) {
    custom404.send404(req, res);

I've now added explicit handlers for requests to static folders:

app.use('/static-path/*', function(req, res, next) {
        custom404.send404(req, res);

Optionally I could also strip out request query params before the 404 is returned:

var data = {
    status: 404,
    message: 'Not Found',
    description: description,
    url: url.parse(req.url).pathname // needs a var url = require('url')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .