transformObjectKeys=true causes obfuscator to crash with "TypeError: Cannot read property 'type' of undefined" if input code contains object spread operator
See original GitHub issuevar JavaScriptObfuscator = require('javascript-obfuscator');
var obfuscationResult = JavaScriptObfuscator.obfuscate(
`
var obj1={
firstname:'John',
lastname:'Smith'
};
var obj2={
age:40,
country:'USA'
}
var user={...obj1, ...obj2}
console.log(user);
`,
{
transformObjectKeys: true,
}
);
console.log(obfuscationResult.getObfuscatedCode());
Expected Behavior
The normal ouput of this program is:
{firstname: "John", lastname: "Smith", age: 40, country: "USA"}
Current Behavior
The current behavior is:
/Users/vincent/dev/packager/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/node/NodeGuards.ts:270
return node.type === NodeType.ObjectPattern;
^
TypeError: Cannot read property 'type' of undefined
at Function.type (/Users/vincent/dev/packager/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/node/NodeGuards.ts:270:21)
at Function.isObjectPatternNode (/Users/vincent/dev/packager/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/node-transformers/converting-transformers/properties-extractors/AbstractPropertiesExtractor.ts:86:27)
at t.isProhibitedPattern (/Users/vincent/dev/packager/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/node-transformers/converting-transformers/properties-extractors/AbstractPropertiesExtractor.ts:120:45)
at t.extractPropertiesToExpressionStatements (/Users/vincent/dev/packager/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/node-transformers/converting-transformers/properties-extractors/AbstractPropertiesExtractor.ts:187:14)
at transformObjectExpressionNode (/Users/vincent/dev/packager/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/node-transformers/converting-transformers/properties-extractors/VariableDeclaratorPropertiesExtractor.ts:42:21)
at t.extract (/Users/vincent/dev/packager/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts:104:36)
at transformNode (/Users/vincent/dev/packager/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts:67:33)
at Controller.visitorFunction (/Users/vincent/dev/packager/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/node-transformers/TransformersRunner.ts:111:55)
at Controller.__execute (/Users/vincent/dev/packager/node_modules/estraverse/estraverse.js:397:31)
at Controller.replace (/Users/vincent/dev/packager/node_modules/estraverse/estraverse.js:637:27)
Steps to Reproduce (for bugs)
- create a file with the above code in a npm project
- run the code
- bug occurs
Your Environment
No related to environment, even on https://obfuscator.io/ it happens as well, the website does not obfuscate the code and displays TypeError: Cannot read property 'type' of undefined
Stack trace
See ‘Current Behavior’ section
Minimal working example that will help to reproduce issue
See code sample at top of bug report
Other notes
array spread operator like […arr1, …arr2] does not create this problem, only {…obj1, …obj2} does.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Javascript ES6 spread operator on undefined - Stack Overflow
When the spread operator is activated on undefined an error is raised, although when the undefined is inside an object, an empty object...
Read more >A spread, a rest and empty values - DEV Community
Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)). Unlike object spread, the array spread doesn't ...
Read more >You Can Safely Apply Object-Spread To Null And Undefined ...
Ben Nadel demonstrates that the Object-Spread operator in TypeScript 3.2.4 can be safely applied to both Null and Undefined values.
Read more >Javascript obfuscation techniques by example - Trickster Dev
We will experiment with some online tools that obfuscate the JS code. Hexadecimal string encoding. If we go to the uncreatively named Javascript ......
Read more >"Object spread" | Can I use... Support tables for HTML5, CSS3 ...
JavaScript operator: Spread syntax (...): Spread in object literals · Global · Chrome · Edge * · Safari · Firefox · Opera ·...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The bug is fixed by PR above.
Thank you! I will look into this tomorrow. Expect release with fix tomorrow.