@@ -309,17 +309,41 @@ function getNestedValue(obj: any, path: string): unknown {
309309 return path . split ( "." ) . reduce ( ( curr , key ) => curr ?. [ key ] , obj ) ;
310310}
311311
312+ // Guard against prototype pollution by blocking dangerous keys
313+ function isUnsafeKey ( key : string ) : boolean {
314+ return key === "__proto__" || key === "constructor" || key === "prototype" ;
315+ }
316+
312317// Helper to set nested value in object
313318function setNestedValue ( obj : any , path : string , value : unknown ) : void {
314319 const parts = path . split ( "." ) ;
315- let current = obj ;
320+ let current : any = obj ;
321+
316322 for ( let i = 0 ; i < parts . length - 1 ; i ++ ) {
317- if ( current [ parts [ i ] ] === undefined ) {
318- current [ parts [ i ] ] = { } ;
323+ const part = parts [ i ] ;
324+
325+ // Prevent prototype pollution via unsafe keys
326+ if ( isUnsafeKey ( part ) ) {
327+ return ;
328+ }
329+
330+ if ( current [ part ] === undefined || current [ part ] === null ) {
331+ current [ part ] = { } ;
332+ }
333+
334+ current = current [ part ] ;
335+ if ( typeof current !== "object" ) {
336+ // Cannot safely nest further into non-object
337+ return ;
319338 }
320- current = current [ parts [ i ] ] ;
321339 }
322- current [ parts [ parts . length - 1 ] ] = value ;
340+
341+ const lastPart = parts [ parts . length - 1 ] ;
342+ if ( isUnsafeKey ( lastPart ) ) {
343+ return ;
344+ }
345+
346+ current [ lastPart ] = value ;
323347}
324348
325349export default ScormViewer ;
0 commit comments