Thanks to visit codestin.com
Credit goes to github.com

Skip to content

transformObjectKeys: true shadows outer scope variable in some cases #1232

@DeltaZN

Description

@DeltaZN

Expected Behavior

Generated variable name should not shadow outer scope variable

Current Behavior

Generated variable name might shadow outer scope variable
Source code:

[].forEach(a => a === { a: 1 });

Obfuscated code result:

[]['forEach'](aO=>aO===aO);}

Steps to Reproduce

See "Minimal working example that will help to reproduce issue"

Your Environment

  • Obfuscator version used: 4.1.0
  • Node version used: v18.17.1

Stack trace

Minimal working example that will help to reproduce issue

const JavaScriptObfuscator = require('javascript-obfuscator');

const options = {
	stringArray: false,
	identifierNamesGenerator: 'mangled',
	transformObjectKeys: true,
};

const fileContent = `
() => {
${new Array(100).fill(0).map((_, i) => `const var${i} = 1;`).join('\n')}
[].forEach(a => a === { a: 1 }); 
}
`;
const obfuscationResult = JavaScriptObfuscator.obfuscate(fileContent, options)._obfuscatedCode;
console.log(obfuscationResult)
const idx = obfuscationResult.indexOf('forEach') + 14; 
const [a, b] = obfuscationResult.substring(idx, idx + 7).split('===');
console.log(a, b, a === b)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions