Skip to content

Commit a974274

Browse files
antongolubwraithgar
authored andcommitted
fix: prevent directory.man referencing outside the package root (#104)
1 parent 191b521 commit a974274

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

lib/normalize.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ function isValidScopedPackageName (spec) {
103103
rest[1] === encodeURIComponent(rest[1])
104104
}
105105

106+
function securePath (ref) {
107+
return path.join('.', path.join('/', ref))
108+
}
109+
106110
// We don't want the `changes` array in here by default because this is a hot
107111
// path for parsing packuments during install. So the calling method passes it
108112
// in if it wants to track changes.
@@ -327,7 +331,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
327331
// expand directories.man
328332
if (steps.includes('mans') && !data.man && data.directories?.man) {
329333
const manDir = data.directories.man
330-
const cwd = path.resolve(pkg.path, manDir)
334+
const cwd = path.resolve(pkg.path, securePath(manDir))
331335
const files = await lazyLoadGlob()('**/*.[0-9]', { cwd })
332336
data.man = files.map(man =>
333337
path.relative(pkg.path, path.join(cwd, man)).split(path.sep).join('/')
@@ -340,7 +344,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
340344

341345
// expand "directories.bin"
342346
if (steps.includes('binDir') && data.directories?.bin && !data.bin) {
343-
const binsDir = path.resolve(pkg.path, path.join('.', path.join('/', data.directories.bin)))
347+
const binsDir = path.resolve(pkg.path, securePath(data.directories.bin))
344348
const bins = await lazyLoadGlob()('**', { cwd: binsDir })
345349
data.bin = bins.reduce((acc, binFile) => {
346350
if (binFile && !binFile.startsWith('.')) {

0 commit comments

Comments
 (0)