Skip to content

Commit f3135f5

Browse files
committed
Improved property assignment from untrusted value
1 parent 3b35d1c commit f3135f5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/componentDetection.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,25 @@ export default class ComponentDetection {
331331
): DependencyGraphs {
332332
// Resolve the base directory from filePathInput (relative to cwd if not absolute)
333333
const baseDir = path.resolve(process.cwd(), filePathInput);
334-
const normalized: DependencyGraphs = {};
334+
// Use a null-prototype object to avoid prototype pollution
335+
const normalized: DependencyGraphs = Object.create(null);
335336
for (const absPath in dependencyGraphs) {
337+
// Only process own properties
338+
if (!Object.prototype.hasOwnProperty.call(dependencyGraphs, absPath)) continue;
336339
// Make the path relative to the baseDir
337340
let relPath = path.relative(baseDir, absPath).replace(/\\/g, '/');
338-
normalized[relPath] = dependencyGraphs[absPath];
341+
// Guard against special keys that could lead to prototype injection
342+
if (relPath === '__proto__' || relPath === 'constructor' || relPath === 'prototype') {
343+
console.warn(`Skipping unsafe manifest key: ${relPath}`);
344+
continue;
345+
}
346+
// Define property safely
347+
Object.defineProperty(normalized, relPath, {
348+
value: dependencyGraphs[absPath],
349+
enumerable: true,
350+
configurable: false,
351+
writable: false,
352+
});
339353
}
340354
return normalized;
341355
}

0 commit comments

Comments
 (0)