Skip to content

Commit ba571be

Browse files
committed
remove dependency
1 parent 187b013 commit ba571be

File tree

5 files changed

+31
-113
lines changed

5 files changed

+31
-113
lines changed

package-lock.json

Lines changed: 1 addition & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@
112112
"validator": "^13.12.0",
113113
"winston": "^3.13.0",
114114
"winston-cloudwatch": "^6.3.0",
115-
"yaml": "^2.4.2",
116-
"zod": "^3.25.76",
117-
"zod-validation-error": "^3.5.3"
115+
"yaml": "^2.4.2"
118116
},
119117
"devDependencies": {
120118
"@octokit/types": "^6.35.0",

src/services/db/GitFileSystemService.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import { NotFoundError } from "@errors/NotFoundError"
2020

2121
import tracer from "@utils/tracer"
2222

23-
import { createPathSchema } from "@validators/path"
24-
2523
import {
2624
EFS_VOL_PATH_STAGING,
2725
EFS_VOL_PATH_STAGING_LITE,
@@ -44,6 +42,7 @@ import type {
4442
import type { IsomerCommitMessage } from "@root/types/github"
4543
import { ALLOWED_FILE_EXTENSIONS } from "@root/utils/file-upload-utils"
4644
import { getPaginatedDirectoryContents } from "@root/utils/files"
45+
import { isSafePath } from "@root/validators/validators"
4746

4847
// methods that do not need to be wrapped for instrumentation
4948
const METHOD_INSTRUMENTATION_BLACKLIST = [
@@ -372,10 +371,9 @@ export default class GitFileSystemService {
372371
// traversal attacks
373372
const repoBaseDirectory = `${efsVolPath}/${repoName}`
374373
const fullFilePath = path.resolve(repoBaseDirectory, filePath)
375-
const pathSchema = createPathSchema({ basePath: repoBaseDirectory })
376-
const parsedPathResult = pathSchema.safeParse(fullFilePath)
374+
const isSafe = isSafePath(fullFilePath, repoBaseDirectory)
377375

378-
if (!parsedPathResult.success) {
376+
if (!isSafe) {
379377
logger.error(`Invalid file path: ${filePath} for repo: ${repoName}`)
380378
return errAsync(new BadRequestError("Invalid file path"))
381379
}

src/validators/path.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/validators/validators.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,35 @@ const isMediaPathValid = ({ path, isFile = false }) => {
3333

3434
const isPasswordValid = (password) => passwordRegexTest.test(password)
3535

36+
const isSafePath = (absPath, basePath) => {
37+
// check for poison null bytes
38+
if (absPath.indexOf("\0") !== -1) {
39+
return false
40+
}
41+
// check for backslashes
42+
if (absPath.indexOf("\\") !== -1) {
43+
return false
44+
}
45+
46+
// check for dot segments, even if they don't normalize to anything
47+
if (absPath.includes("..")) {
48+
return false
49+
}
50+
51+
// check if the normalized path is within the provided 'safe' base path
52+
if (path.resolve(basePath, path.relative(basePath, absPath)) !== absPath) {
53+
return false
54+
}
55+
if (absPath.indexOf(basePath) !== 0) {
56+
return false
57+
}
58+
return true
59+
}
60+
3661
module.exports = {
3762
hasSpecialCharInTitle,
3863
isDateValid,
3964
isMediaPathValid,
4065
isPasswordValid,
66+
isSafePath,
4167
}

0 commit comments

Comments
 (0)