js-confuser icon indicating copy to clipboard operation
js-confuser copied to clipboard

ForInStatement of a variable in window

Open fixfell7 opened this issue 3 months ago • 3 comments

Describe the bug:

The program enters an infinite loop and does not produce the expected output.

Config and Small code sample

Version 2.0.0

Config:

{
  target: "node",
  preset: "medium"
}

Code:

window.list = {
  test1: 0,
};
function test() {
  for (scene in window.list) {
    console.log('test');
  };
}
test();

Expected behavior

Should obfuscate my code.

Actual behavior

Error message:

TypeError: Property left of ForInStatement expected node to be of a type ["VariableDeclaration","LVal"] but instead got "CallExpression" at Object.s [as validate]

Additional context

2.0.0 Low Preset does not do the error 1.7.3 does not do the error at all

fixfell7 avatar Aug 01 '25 11:08 fixfell7

Looks to be the "Global Concealing" option

fixfell7 avatar Aug 01 '25 11:08 fixfell7

Thanks, great find. The problem was Global Concealing on non-defined identifiers in For-In/For-Of statements. Fixed for next release.

I would recommend defining every variable you use, the obfuscator handles them better. Ex:

window.list = {
  test1: 0,
};
function test2() {
  var scene; // <- Define variable to avoid this
  for (scene in window.list) {
    console.log("test");
  }
}
test2();
// "test"

MichaelXF avatar Aug 02 '25 02:08 MichaelXF

Fixed on development version of JS-Confuser.com: Demo link.

MichaelXF avatar Aug 03 '25 03:08 MichaelXF