Skip to content

Commit a978db9

Browse files
committed
Add iteration limit to path traversal loop
1 parent 23a4400 commit a978db9

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/utils/path-resolve.mts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ export function findBinPathDetailsSync(binName: string): {
5454

5555
export function findNpmDirPathSync(npmBinPath: string): string | undefined {
5656
const { WIN32 } = constants
57+
const MAX_ITERATIONS = 100
5758
let thePath = npmBinPath
59+
let iterations = 0
5860
while (true) {
61+
if (iterations >= MAX_ITERATIONS) {
62+
throw new Error(
63+
`path traversal exceeded maximum iterations of ${MAX_ITERATIONS}`,
64+
)
65+
}
66+
iterations += 1
5967
const libNmNpmPath = path.join(thePath, `lib/${NODE_MODULES}/${NPM}`)
6068
// mise, which uses opaque binaries, puts its npm bin in a path like:
6169
// /Users/SomeUsername/.local/share/mise/installs/node/vX.X.X/bin/npm.

0 commit comments

Comments
 (0)