javascript-obfuscator / javascript-obfuscator/webpack-obfuscator

identifierNamesCache not working as expected

Open
#127 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
928
Forks
92
PR merge metrics
No merged PRs in 30d

Description

Hi,

I was trying this plugin with WebPack 5 and found that `identifierNamesCache` is not working properly to obfuscate multiple files that depends on each other.

I modified the built `index.js` to fix this issue.

**Old code:**

```js
obfuscate(javascript, fileName, identifiersPrefixCounter) {
const obfuscationResult = javascript_obfuscator_1.default.obfuscate(javascript, Object.assign({ identifiersPrefix: `${WebpackObfuscatorPlugin.baseIdentifiersPrefix}${identifiersPrefixCounter}`, inputFileName: fileName, sourceMapMode: 'separate', sourceMapFileName: fileName + '.map' }, this.options));
return {
obfuscatedSource: obfuscationResult.getObfuscatedCode(),
obfuscationSourceMap: obfuscationResult.getSourceMap()
};
}
```

**New code:**

```js
obfuscate(javascript, fileName, identifiersPrefixCounter) {
const obfuscationResult = javascript_obfuscator_1.default.obfuscate(javascript, Object.assign({ identifiersPrefix: `${WebpackObfuscatorPlugin.baseIdentifiersPrefix}${identifiersPrefixCounter}`, inputFileName: fileName, sourceMapMode: 'separate', sourceMapFileName: fileName + '.map' }, this.options));
this.options.identifierNamesCache = obfuscationResult.getIdentifierNamesCache();
return {
obfuscatedSource: obfuscationResult.getObfuscatedCode(),
obfuscationSourceMap: obfuscationResult.getSourceMap()
};
}
```

I justed add `this.options.identifierNamesCache = obfuscationResult.getIdentifierNamesCache();` and now it works correctly.

PS: I'm not sure if the issue is in this plugin or `javascript-obfuscator` itself.

Thanks.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting the obfuscate method in the built index.js and the identifierNamesCache option flow. Reproduce the issue with Webpack 5 across multiple dependent files, then verify that the cache is carried between obfuscation results and that the files are obfuscated consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.