11import { COMPILER_REVISION , REVISION_CHANGES } from '../base' ;
22import Exception from '../exception' ;
3- import { isArray } from '../utils' ;
3+ import { isArray , sanitizeDepth } from '../utils' ;
44import CodeGen from './code-gen' ;
55
66function Literal ( value ) {
@@ -469,7 +469,7 @@ JavaScriptCompiler.prototype = {
469469 //
470470 // Set the value of the `lastContext` compiler value to the depth
471471 getContext : function ( depth ) {
472- this . lastContext = depth ;
472+ this . lastContext = sanitizeDepth ( depth ) ;
473473 } ,
474474
475475 // [pushContext]
@@ -513,7 +513,13 @@ JavaScriptCompiler.prototype = {
513513 lookupBlockParam : function ( blockParamId , parts ) {
514514 this . useBlockParams = true ;
515515
516- this . push ( [ 'blockParams[' , blockParamId [ 0 ] , '][' , blockParamId [ 1 ] , ']' ] ) ;
516+ this . push ( [
517+ 'blockParams[' ,
518+ Number ( blockParamId [ 0 ] ) ,
519+ '][' ,
520+ Number ( blockParamId [ 1 ] ) ,
521+ ']'
522+ ] ) ;
517523 this . resolvePath ( 'context' , parts , 1 ) ;
518524 } ,
519525
@@ -527,7 +533,9 @@ JavaScriptCompiler.prototype = {
527533 if ( ! depth ) {
528534 this . pushStackLiteral ( 'data' ) ;
529535 } else {
530- this . pushStackLiteral ( 'container.data(data, ' + depth + ')' ) ;
536+ this . pushStackLiteral (
537+ 'container.data(data, ' + sanitizeDepth ( depth ) + ')'
538+ ) ;
531539 }
532540
533541 this . resolvePath ( 'data' , parts , 0 , true , strict ) ;
@@ -659,6 +667,28 @@ JavaScriptCompiler.prototype = {
659667 this . pushStackLiteral ( value ) ;
660668 } ,
661669
670+ // [pushNumber]
671+ //
672+ // On stack, before: ...
673+ // On stack, after: number, ...
674+ //
675+ // Pushes a numeric value onto the stack, coercing via Number()
676+ // to prevent code injection through type-confused AST nodes.
677+ pushNumber : function ( value ) {
678+ this . pushStackLiteral ( Number ( value ) ) ;
679+ } ,
680+
681+ // [pushBoolean]
682+ //
683+ // On stack, before: ...
684+ // On stack, after: boolean, ...
685+ //
686+ // Pushes a boolean value onto the stack, strictly coercing
687+ // to prevent code injection through type-confused AST nodes.
688+ pushBoolean : function ( value ) {
689+ this . pushStackLiteral ( value === true ? 'true' : 'false' ) ;
690+ } ,
691+
662692 // [pushProgram]
663693 //
664694 // On stack, before: ...
0 commit comments