File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments