github-code-scanning[bot] commented on code in PR #7582:
URL: https://github.com/apache/trafficcontrol/pull/7582#discussion_r1232681237
##########
experimental/traffic-portal/server.ts:
##########
@@ -57,6 +57,40 @@
server.set("view engine", "html");
server.set("views", serverConfig.browserFolder);
+ const typeMap = new Map([
+ ["js", "application/javascript"],
+ ["css", "text/css"],
+ ["ttf", "font/ttf"],
+ ["svg", "image/svg+xml"]
+ ]);
+ // Could just use express compression `server.use(compression())` but
that is calculated for each request
+ server.get("*.(js|css|ttf|svg)", function(req, res, next) {
+ const type = req.url.split(".").pop();
+ if (type === undefined) {
+ return next();
+ }
+ //br first as it's usually better compression
+ const compressionTypes = [["br", "br"], ["gzip", "gz"]];
+ const acceptedEncodings = req.acceptsEncodings();
+ for(const cType of compressionTypes) {
+ if(acceptedEncodings.indexOf(cType[0]) === -1 ) {
+ continue;
+ }
+ let newUrl = `${req.url}.${cType[1]}`;
+ newUrl = newUrl.substring(1, newUrl.length);
+ if (existsSync(join(serverConfig.browserFolder,
newUrl))) {
+ if (typeMap.has(type)) {
+ req.url = newUrl;
+ res.set("Content-Encoding", cType[0]);
+ res.set("Content-Type",
typeMap.get(type));
+ console.log(`Serving ${cType[0]}
compressed file ${newUrl}`);
+ return next();
+ }
+ console.log(`Unknown file type: ${type}, known:
${typeMap}`);
+ }
+ }
+ next();
+ });
Review Comment:
## Missing rate limiting
This route handler performs [a file system access](1), but is not
rate-limited.
[Show more
details](https://github.com/apache/trafficcontrol/security/code-scanning/281)
##########
experimental/traffic-portal/server.ts:
##########
@@ -57,6 +57,40 @@
server.set("view engine", "html");
server.set("views", serverConfig.browserFolder);
+ const typeMap = new Map([
+ ["js", "application/javascript"],
+ ["css", "text/css"],
+ ["ttf", "font/ttf"],
+ ["svg", "image/svg+xml"]
+ ]);
+ // Could just use express compression `server.use(compression())` but
that is calculated for each request
+ server.get("*.(js|css|ttf|svg)", function(req, res, next) {
+ const type = req.url.split(".").pop();
+ if (type === undefined) {
+ return next();
+ }
+ //br first as it's usually better compression
+ const compressionTypes = [["br", "br"], ["gzip", "gz"]];
+ const acceptedEncodings = req.acceptsEncodings();
+ for(const cType of compressionTypes) {
+ if(acceptedEncodings.indexOf(cType[0]) === -1 ) {
+ continue;
+ }
+ let newUrl = `${req.url}.${cType[1]}`;
+ newUrl = newUrl.substring(1, newUrl.length);
+ if (existsSync(join(serverConfig.browserFolder,
newUrl))) {
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more
details](https://github.com/apache/trafficcontrol/security/code-scanning/280)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]