@@ -25,7 +25,7 @@ const webpackSchema =
2525 * @property {string } path the path in the config
2626 */
2727
28- /** @typedef {"unknown-argument" | "unexpected-non-array-in-path" | "unexpected-non-object-in-path" | "multiple-values-unexpected" | "invalid-value" } ProblemType */
28+ /** @typedef {"unknown-argument" | "unexpected-non-array-in-path" | "unexpected-non-object-in-path" | "prototype-pollution-in-path" | " multiple-values-unexpected" | "invalid-value" } ProblemType */
2929
3030/** @typedef {string | number | boolean | RegExp } Value */
3131
@@ -449,6 +449,14 @@ const cliAddedItems = new WeakMap();
449449
450450/** @typedef {string | number } Property */
451451
452+ /**
453+ * Whether a path segment would walk into the prototype chain.
454+ * @param {string } name path segment
455+ * @returns {boolean } true when the segment is unsafe to write through
456+ */
457+ const isUnsafeKey = ( name ) =>
458+ name === "__proto__" || name === "constructor" || name === "prototype" ;
459+
452460/**
453461 * Gets object and property.
454462 * @param {ObjectConfiguration } config configuration
@@ -465,6 +473,14 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
465473 for ( const part of parts ) {
466474 const isArray = part . endsWith ( "[]" ) ;
467475 const name = isArray ? part . slice ( 0 , - 2 ) : part ;
476+ if ( isUnsafeKey ( name ) ) {
477+ return {
478+ problem : {
479+ type : "prototype-pollution-in-path" ,
480+ path : parts . slice ( 0 , i ) . join ( "." )
481+ }
482+ } ;
483+ }
468484 let value = current [ name ] ;
469485 if ( isArray ) {
470486 if ( value === undefined ) {
@@ -511,6 +527,14 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
511527 current = value ;
512528 i ++ ;
513529 }
530+ if ( isUnsafeKey ( property . endsWith ( "[]" ) ? property . slice ( 0 , - 2 ) : property ) ) {
531+ return {
532+ problem : {
533+ type : "prototype-pollution-in-path" ,
534+ path : parts . join ( "." )
535+ }
536+ } ;
537+ }
514538 const value = current [ property ] ;
515539 if ( property . endsWith ( "[]" ) ) {
516540 const name = property . slice ( 0 , - 2 ) ;
0 commit comments