Skip to content

Commit

Permalink
Merge pull request #1687 from transcom/rk-163599170-swagger-ui-expose…
Browse files Browse the repository at this point in the history
…d-tspstagingmovemil

Filter out url parameter when a non-relative path is provided. Also a…
  • Loading branch information
Ryan-Koch committed Feb 4, 2019
2 parents 39b49d7 + d1267be commit 8f762f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/copy_swagger_ui.sh
Expand Up @@ -5,4 +5,4 @@
# will need to be manually updated based on node_modules/swagger-ui-dist/index.html
# if it ever changes.
cp node_modules/swagger-ui-dist/{*.js,*.css,*.png} public/swagger-ui
cp node_modules/js-cookie/src/js.cookie.js public/swagger-ui
cp node_modules/js-cookie/src/js.cookie.js public/swagger-ui
9 changes: 9 additions & 0 deletions public/swagger-ui/api.html
Expand Up @@ -82,6 +82,15 @@
console.warn('Unable to retrieve CSRF Token from cookie');
}
}
// Add check for protocol so that we know if someone tries to throw a non-relative path in the url parameter.
// This is here to prevent malicious actors using the parameter to execute arbitrary malicious code on an
// unsuspecting user (swagger-ui behavior causes this to happen otherwise).
var protocolRegex = /(http|https):*/;
var isNonRelativePath = protocolRegex.test(req['url']);
if (isNonRelativePath) {
req['url'] = null;
}

return req;
};

Expand Down
9 changes: 9 additions & 0 deletions public/swagger-ui/internal.html
Expand Up @@ -82,6 +82,15 @@
console.warn('Unable to retrieve CSRF Token from cookie');
}
}
// Add check for protocol so that we know if someone tries to throw a non-relative path in the url parameter.
// This is here to prevent malicious actors using the parameter to execute arbitrary malicious code on an
// unsuspecting user (swagger-ui behavior causes this to happen otherwise).
var protocolRegex = /(http|https):*/;
var isNonRelativePath = protocolRegex.test(req['url']);
if (isNonRelativePath) {
req['url'] = null;
}

return req;
};

Expand Down

0 comments on commit 8f762f2

Please sign in to comment.