Skip to content

Commit

Permalink
Protect against escaped evil escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Oct 21, 2018
1 parent 1574a84 commit d0fa7c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## 1.0.1 (Unreleased)

Bug Fixes

- Protect against escaped evil escaping.

**A note on security:** Turbo Combine Reducers uses `new Function` dynamic function evaluation (i.e. an `eval` equivalent) to pre-compile the state value reducer. The risk surface area is limited to reducer property names. Most applications will never (and _should never_) include a dynamic, user-input value as a reducer key and thus would not be exposed to any risk, including in prior releases. The changes in this release more aggressively sanitize reducer keys to offer protection even in the limited use-case where an unsafe user-input reducer key would be intended to be used.

## 1.0.0 (2018-10-20)

- Initial release
12 changes: 9 additions & 3 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ describe( 'combineReducers', () => {
} );

it( 'is not susceptible to evil', () => {
combineReducers( {
'\':(function(){throw "EVIL";})(),\'a': () => 0,
} );
try {
combineReducers( {
'\\\':(function(){throw "EVIL"})()};//': () => 0,
} )();
} catch ( error ) {
if ( error === 'EVIL' ) {
throw error;
}
}
} );
} );
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ function combineReducers( reducers ) {
// used as string literals of the object properties. To ensure that
// the property would not prematurely terminate the string literal
// token, and considering termination by its ending single quote,
// escape all single quotes of the key.
// remove any single quotes of the key.
//
// "A string literal is zero or more Unicode code points enclosed
// in single or double quotes."
//
// See: https://www.ecma-international.org/ecma-262/9.0/index.html#sec-literals-string-literals
key = keys[ i ].replace( /'/g, '\\\'' );
key = keys[ i ].replace( /'/g, '' );

fn += '\'' + key + '\':r[\'' + key + '\'](s[\'' + key + '\'],a),';
}
Expand Down

0 comments on commit d0fa7c4

Please sign in to comment.