File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Original file line Diff line number Diff line change 1# History
1# History
2
2
3
3
4+ ## not yet released, version 0.10.6
5+
6+ - Fixed a security issue allowing to execute aritrary JavaScript code via a
7+ specially prepared function name of a typed function. Thanks Masato Kinugawa.
8+
9+
4## 2016-11-18, version 0.10.5
10## 2016-11-18, version 0.10.5
5
11
6- Fixed the use of multi-layered use of ` any ` type. See #8 .
12- Fixed the use of multi-layered use of ` any ` type. See #8 .
Original file line number Original file line Diff line number Diff line change 1+ var assert = require ( 'assert' ) ;
2+ var typed = require ( '../typed-function' ) ;
3+
4+ describe ( 'security' , function ( ) {
5+
6+ it ( 'should not allow bad code in the function name' , function ( ) {
7+ // simple example:
8+ // var fn = typed("(){}+console.log('hacked...');function a", {
9+ // "": function () {}
10+ // });
11+
12+ // example resulting in throwing an error
13+ var fn = typed ( "(){}+(function(){throw new Error('Hacked... should not have executed this function!!!')})();function a" , {
14+ "" : function ( ) { }
15+ } ) ;
16+ } )
17+ } )
Original file line number Original file line Diff line number Diff line change 1096 //console.log(util.inspect(node, { depth: null }));
1096 //console.log(util.inspect(node, { depth: null }));
1097
1097
1098 // generate code for the typed function
1098 // generate code for the typed function
1099+ // safeName is a conservative replacement of characters
1100+ // to prevend being able to inject JS code at the place of the function name
1101+ // the name is useful for stack trackes therefore we want have it there
1099 var code = [ ] ;
1102 var code = [ ] ;
1100- var _name = name || '' ;
1103+ var safeName = ( name || '' ) . replace ( / [ ^ a - z A - Z 0 - 9 _ $ ] / g , '_' )
1101- var _args = getArgs ( maxParams ( _signatures ) ) ;
1104+ var args = getArgs ( maxParams ( _signatures ) ) ;
1102- code . push ( 'function ' + _name + '(' + _args . join ( ', ' ) + ') {' ) ;
1105+ code . push ( 'function ' + safeName + '(' + args . join ( ', ' ) + ') {' ) ;
1103 code . push ( ' "use strict";' ) ;
1106 code . push ( ' "use strict";' ) ;
1104- code . push ( ' var name = \'' + _name + '\ ';') ;
1107+ code . push ( ' var name = ' + JSON . stringify ( name || '' ) + ';' ) ;
1105 code . push ( node . toCode ( refs , ' ' , false ) ) ;
1108 code . push ( node . toCode ( refs , ' ' , false ) ) ;
1106 code . push ( '}' ) ;
1109 code . push ( '}' ) ;
1107
1110
You can’t perform that action at this time.
0 commit comments