-
Notifications
You must be signed in to change notification settings - Fork 151
Fix XSS vulnerability in search and reverse-lookup endpoints #904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| var t0 = Date.now(); | ||
|
|
||
| var bibref = require('./lib/bibref'); | ||
| var sanitizeHtml = require('sanitize-html'); | ||
| var helmet = require('helmet'); | ||
|
|
||
| var app = module.exports = require("express")(); | ||
|
|
||
|
|
@@ -10,6 +12,18 @@ if (process.env.NODE_ENV == "dev" || process.env.NODE_ENV == "development") { | |
| errorhandlerOptions.showStack = true; | ||
| } | ||
| app.enable("etag"); | ||
|
|
||
| app.use(helmet({ | ||
| contentSecurityPolicy: { | ||
| directives: { | ||
| defaultSrc: ["'self'"], | ||
| scriptSrc: ["'self'"], | ||
| objectSrc: ["'none'"] | ||
| } | ||
| }, | ||
| crossOriginEmbedderPolicy: false | ||
| })); | ||
|
|
||
| var bannedIPs = [ | ||
| // Palo Alto Networks bot | ||
| "34.96.130.0/24", "34.77.162.0/24", "34.86.35.0/24" | ||
|
|
@@ -35,7 +49,10 @@ app.get('/bibrefs', function (req, res, next) { | |
|
|
||
| // search | ||
| app.get('/search-refs', function (req, res, next) { | ||
| var q = (req.query["q"] || "").toLowerCase(); | ||
| var q = sanitizeHtml(req.query["q"] || "", { | ||
| allowedTags: [], | ||
| allowedAttributes: {} | ||
| }).toLowerCase(); | ||
|
Comment on lines
+52
to
+55
|
||
| if (q) { | ||
| var obj = {}; | ||
| var current, shortname; | ||
|
|
@@ -95,7 +112,13 @@ app.get('/reverse-lookup', function (req, res, next) { | |
| var refs, | ||
| urls = req.query["urls"]; | ||
| if (urls) { | ||
| refs = bibref.reverseLookup(urls.split(",")); | ||
| var sanitizedUrls = urls.split(",").map(function(url) { | ||
| return sanitizeHtml(url.trim(), { | ||
| allowedTags: [], | ||
| allowedAttributes: {} | ||
| }); | ||
| }); | ||
| refs = bibref.reverseLookup(sanitizedUrls); | ||
|
marcoscaceres marked this conversation as resolved.
|
||
| res.status(200).jsonp(refs); | ||
| } else { | ||
| res.status(400).jsonp({ message: "Missing urls parameter" }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.