Skip to content

Commit

Permalink
fix: prevent seeing subdirectories
Browse files Browse the repository at this point in the history
  • Loading branch information
TGRZiminiar committed Sep 11, 2024
1 parent 493f895 commit 703867d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ Thumbs.db
dist/**/*

# ignore yarn.lock
yarn.lock
yarn.lock
build.md
8 changes: 7 additions & 1 deletion src/controller/get-static-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import * as path from "path";
import { FastifyReply, FastifyRequest } from "fastify";

export async function GetStaticData(request: FastifyRequest<{ Params: { '*': string } }>, reply: FastifyReply) {
const fullPath = path.resolve(process.cwd(), 'data', request.params['*']);

// Ensure the requested path is within the base path
if ((request.params['*'].match(/\//g) || []).length >= 1) {
reply.status(403).send('Access denied: Too many subdirectories');
return;
}

const fullPath = path.resolve(process.cwd(), 'data', request.params['*']);
try {
const stats = await fs.promises.stat(fullPath);
if (stats.isDirectory()) {
Expand Down

0 comments on commit 703867d

Please sign in to comment.