Skip to content

Commit c881f70

Browse files
committed
Use a Set for the extension whitelist.
1 parent 65bc1a3 commit c881f70

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

conf/index.js

+39-39
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,45 @@ module.exports = {
3030
//
3131
// Requests to the cdnDomain will bypass this whitelist and proxy all file
3232
// types. Please keep this list alphabetized.
33-
extensionWhitelist: {
34-
'.appcache' : true,
35-
'.coffee' : true,
36-
'.css' : true,
37-
'.csv' : true,
38-
'.eot' : true,
39-
'.geojson' : true,
40-
'.handlebars': true,
41-
'.hbs' : true,
42-
'.htm' : true,
43-
'.html' : true,
44-
'.js' : true,
45-
'.json' : true,
46-
'.jsonld' : true,
47-
'.kml' : true,
48-
'.md' : true,
49-
'.n3' : true,
50-
'.nt' : true,
51-
'.otf' : true,
52-
'.owl' : true,
53-
'.pdf' : true,
54-
'.rdf' : true,
55-
'.rss' : true,
56-
'.svg' : true,
57-
'.swf' : true,
58-
'.ttc' : true,
59-
'.ttf' : true,
60-
'.ttl' : true,
61-
'.vtt' : true,
62-
'.woff' : true,
63-
'.woff2' : true,
64-
'.xht' : true,
65-
'.xhtml' : true,
66-
'.xml' : true,
67-
'.xsl' : true,
68-
'.xslt' : true,
69-
'.yaml' : true,
70-
'.yml' : true
71-
},
33+
extensionWhitelist: new Set([
34+
'.appcache',
35+
'.coffee',
36+
'.css',
37+
'.csv',
38+
'.eot',
39+
'.geojson',
40+
'.handlebars',
41+
'.hbs',
42+
'.htm',
43+
'.html',
44+
'.js',
45+
'.json',
46+
'.jsonld',
47+
'.kml',
48+
'.md',
49+
'.n3',
50+
'.nt',
51+
'.otf',
52+
'.owl',
53+
'.pdf',
54+
'.rdf',
55+
'.rss',
56+
'.svg',
57+
'.swf',
58+
'.ttc',
59+
'.ttf',
60+
'.ttl',
61+
'.vtt',
62+
'.woff',
63+
'.woff2',
64+
'.xht',
65+
'.xhtml',
66+
'.xml',
67+
'.xsl',
68+
'.xslt',
69+
'.yaml',
70+
'.yml',
71+
]),
7272

7373
// Whether we're running in a production environment (true) or
7474
// development/test (false).

lib/middleware/file-redirect.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
const config = require('../../conf');
44
const path = require('path');
55

6+
const { extensionWhitelist } = config;
7+
68
// Redirects requests for non-whitelisted file extensions directly to GitHub,
79
// since there's no value in proxying them.
810
module.exports = rootUrl => {
911
return (req, res, next) => {
10-
if (req.isCDN) {
12+
if (req.isCDN || req.path.endsWith('/')) {
1113
return void next();
1214
}
1315

14-
if (config.extensionWhitelist[path.extname(req.path).toLowerCase()]) {
15-
return void next();
16-
}
16+
let extension = path.extname(req.path).toLowerCase();
1717

18-
if (/\/$/.test(req.path)) {
18+
if (extensionWhitelist.has(extension)) {
1919
return void next();
2020
}
2121

0 commit comments

Comments
 (0)