Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DeltaZN opened this issue Jan 21, 2024 · 0 comments
Open

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

DeltaZN opened this issue Jan 21, 2024 · 0 comments

Comments

@DeltaZN
Copy link

DeltaZN commented Jan 21, 2024

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant