Sfoglia il codice sorgente

Disallow additional paths, closes #123

Jake 10 anni fa
parent
commit
f1fd92f1cf
4 ha cambiato i file con 37 aggiunte e 1 eliminazioni
  1. 9 0
      lib/routes/avatars.js
  2. 10 1
      lib/routes/capes.js
  3. 9 0
      lib/routes/renders.js
  4. 9 0
      lib/routes/skins.js

+ 9 - 0
lib/routes/avatars.js

@@ -33,6 +33,15 @@ module.exports = function(req, callback) {
   var def = req.url.query.default;
   var def = req.url.query.default;
   var helm = req.url.query.hasOwnProperty("helm");
   var helm = req.url.query.hasOwnProperty("helm");
 
 
+  // check for extra paths
+  if (req.url.path_list.length > 2) {
+    callback({
+      status: -2,
+      body: "Invalid URL Path"
+    });
+    return;
+  }
+
   // Prevent app from crashing/freezing
   // Prevent app from crashing/freezing
   if (size < config.min_size || size > config.max_size) {
   if (size < config.min_size || size > config.max_size) {
     // "Unprocessable Entity", valid request, but semantically erroneous:
     // "Unprocessable Entity", valid request, but semantically erroneous:

+ 10 - 1
lib/routes/capes.js

@@ -4,10 +4,19 @@ var cache = require("../cache");
 
 
 // GET cape request
 // GET cape request
 module.exports = function(req, callback) {
 module.exports = function(req, callback) {
-  var userId = (req.url.pathname.split("/")[2] || "").split(".")[0];
+  var userId = (req.url.path_list[1] || "").split(".")[0];
   var def = req.url.query.default;
   var def = req.url.query.default;
   var rid = req.id;
   var rid = req.id;
 
 
+  // check for extra paths
+  if (req.url.path_list.length > 2) {
+    callback({
+      status: -2,
+      body: "Invalid URL Path"
+    });
+    return;
+  }
+
   if (!helpers.id_valid(userId)) {
   if (!helpers.id_valid(userId)) {
     callback({
     callback({
       status: -2,
       status: -2,

+ 9 - 0
lib/routes/renders.js

@@ -47,6 +47,15 @@ module.exports = function(req, callback) {
   var scale = parseInt(req.url.query.scale) || config.default_scale;
   var scale = parseInt(req.url.query.scale) || config.default_scale;
   var helm = req.url.query.hasOwnProperty("helm");
   var helm = req.url.query.hasOwnProperty("helm");
 
 
+  // check for extra paths
+  if (req.url.path_list.length > 3) {
+    callback({
+      status: -2,
+      body: "Invalid URL Path"
+    });
+    return;
+  }
+
   // validate type
   // validate type
   if (raw_type !== "body" && raw_type !== "head") {
   if (raw_type !== "body" && raw_type !== "head") {
     callback({
     callback({

+ 9 - 0
lib/routes/skins.js

@@ -40,6 +40,15 @@ module.exports = function(req, callback) {
   var def = req.url.query.default;
   var def = req.url.query.default;
   var rid = req.id;
   var rid = req.id;
 
 
+  // check for extra paths
+  if (req.url.path_list.length > 2) {
+    callback({
+      status: -2,
+      body: "Invalid URL Path"
+    });
+    return;
+  }
+
   if (!helpers.id_valid(userId)) {
   if (!helpers.id_valid(userId)) {
     callback({
     callback({
       status: -2,
       status: -2,