File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,15 +60,17 @@ export class JitEvaluator {
6060 evaluateCode (
6161 sourceUrl : string ,
6262 ctx : EmitterVisitorContext ,
63- vars : { [ key : string ] : any } ,
63+ vars : Record < string , any > ,
6464 createSourceMap : boolean ,
6565 ) : any {
6666 let fnBody = `"use strict";${ ctx . toSource ( ) } \n//# sourceURL=${ sourceUrl } ` ;
6767 const fnArgNames : string [ ] = [ ] ;
6868 const fnArgValues : any [ ] = [ ] ;
6969 for ( const argName in vars ) {
70- fnArgValues . push ( vars [ argName ] ) ;
71- fnArgNames . push ( argName ) ;
70+ if ( Object . hasOwn ( vars , argName ) ) {
71+ fnArgValues . push ( vars [ argName ] ) ;
72+ fnArgNames . push ( argName ) ;
73+ }
7274 }
7375 if ( createSourceMap ) {
7476 // using `new Function(...)` generates a header, 1 line of no arguments, 2 lines otherwise
Original file line number Diff line number Diff line change @@ -95,6 +95,8 @@ function trustedScriptFromString(script: string): TrustedScript | string {
9595 return getPolicy ( ) ?. createScript ( script ) || script ;
9696}
9797
98+ const PARAM_NAME_PATTERN = / ^ [ A - Z a - z _ $ ] [ \w $ ] * $ / ;
99+
98100/**
99101 * Unsafely call the Function constructor with the given string arguments.
100102 * @security This is a security-sensitive function; any use of this function
@@ -113,9 +115,16 @@ export function newTrustedFunctionForJIT(...args: string[]): Function {
113115 // constructor. The following implements the workaround proposed on the page
114116 // below, where the Chromium bug is also referenced:
115117 // https://github.com/w3c/webappsec-trusted-types/wiki/Trusted-Types-for-function-constructor
116- const fnArgs = args . slice ( 0 , - 1 ) . join ( ',' ) ;
117118 const fnBody = args [ args . length - 1 ] ;
118- const body = `(function anonymous(${ fnArgs }
119+ const fnParams = args . slice ( 0 , - 1 ) ;
120+
121+ for ( const param of fnParams ) {
122+ if ( ! PARAM_NAME_PATTERN . test ( param ) ) {
123+ throw new Error ( `newTrustedFunctionForJIT: invalid parameter name "${ param } "` ) ;
124+ }
125+ }
126+
127+ const body = `(function anonymous(${ fnParams . join ( ',' ) }
119128) { ${ fnBody }
120129})` ;
121130
Original file line number Diff line number Diff line change @@ -213,10 +213,10 @@ export function identifierName(
213213 return null ;
214214 }
215215 const ref = compileIdentifier . reference ;
216- if ( ref [ '__anonymousType' ] ) {
216+ if ( Object . hasOwn ( ref , '__anonymousType' ) ) {
217217 return ref [ '__anonymousType' ] ;
218218 }
219- if ( ref [ '__forward_ref__' ] ) {
219+ if ( Object . hasOwn ( ref , '__forward_ref__' ) ) {
220220 // We do not want to try to stringify a `forwardRef()` function because that would cause the
221221 // inner function to be evaluated too early, defeating the whole point of the `forwardRef`.
222222 return '__forward_ref__' ;
You can’t perform that action at this time.
0 commit comments