Skip to content
Snippets Groups Projects
Commit e1dcd5de authored by timothycarambat's avatar timothycarambat
Browse files

Normalize pfp path to prevent traversal

parent 026849df
No related branches found
No related tags found
No related merge requests found
...@@ -502,7 +502,8 @@ function systemEndpoints(app) { ...@@ -502,7 +502,8 @@ function systemEndpoints(app) {
} }
const userRecord = await User.get({ id: user.id }); const userRecord = await User.get({ id: user.id });
const oldPfpFilename = userRecord.pfpFilename; const oldPfpFilename = normalizePath(userRecord.pfpFilename);
console.log("oldPfpFilename", oldPfpFilename); console.log("oldPfpFilename", oldPfpFilename);
if (oldPfpFilename) { if (oldPfpFilename) {
const oldPfpPath = path.join( const oldPfpPath = path.join(
...@@ -536,7 +537,7 @@ function systemEndpoints(app) { ...@@ -536,7 +537,7 @@ function systemEndpoints(app) {
try { try {
const user = await userFromSession(request, response); const user = await userFromSession(request, response);
const userRecord = await User.get({ id: user.id }); const userRecord = await User.get({ id: user.id });
const oldPfpFilename = userRecord.pfpFilename; const oldPfpFilename = normalizePath(userRecord.pfpFilename);
console.log("oldPfpFilename", oldPfpFilename); console.log("oldPfpFilename", oldPfpFilename);
if (oldPfpFilename) { if (oldPfpFilename) {
const oldPfpPath = path.join( const oldPfpPath = path.join(
......
...@@ -2,6 +2,7 @@ const path = require("path"); ...@@ -2,6 +2,7 @@ const path = require("path");
const fs = require("fs"); const fs = require("fs");
const { getType } = require("mime"); const { getType } = require("mime");
const { User } = require("../../models/user"); const { User } = require("../../models/user");
const { normalizePath } = require(".");
function fetchPfp(pfpPath) { function fetchPfp(pfpPath) {
if (!fs.existsSync(pfpPath)) { if (!fs.existsSync(pfpPath)) {
...@@ -32,8 +33,7 @@ async function determinePfpFilepath(id) { ...@@ -32,8 +33,7 @@ async function determinePfpFilepath(id) {
const basePath = process.env.STORAGE_DIR const basePath = process.env.STORAGE_DIR
? path.join(process.env.STORAGE_DIR, "assets/pfp") ? path.join(process.env.STORAGE_DIR, "assets/pfp")
: path.join(__dirname, "../../storage/assets/pfp"); : path.join(__dirname, "../../storage/assets/pfp");
const pfpFilepath = path.join(basePath, pfpFilename); const pfpFilepath = path.join(basePath, normalizePath(pfpFilename));
if (!fs.existsSync(pfpFilepath)) return null; if (!fs.existsSync(pfpFilepath)) return null;
return pfpFilepath; return pfpFilepath;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment