Git Product home page Git Product logo

webpack-obfuscator's Introduction

javascript-obfuscator plugin and loader for Webpack@5

npm version

Installation

This plugin requires Webpack@5. If you depend on Webpack@4, please use version 2 of the plugin.

Install the plugin with NPM and add it to your devDependencies:

npm install --save-dev javascript-obfuscator webpack-obfuscator

Plugin usage:

var WebpackObfuscator = require('webpack-obfuscator');

// ...

// webpack plugins array
plugins: [
    new WebpackObfuscator ({
        rotateStringArray: true
    }, ['excluded_bundle_name.js'])
]

Loader usage:

Define a rule in your webpack config and use the obfuscator-loader as the last of your loaders for your modules. You can add the enforce: 'post' flag to ensure the loader will be called after normal loaders:

var WebpackObfuscator = require('webpack-obfuscator');

// webpack loader rules array
rules: [
    {
        test: /\.js$/,
        exclude: [ 
            path.resolve(__dirname, 'excluded_file_name.js') 
        ],
        enforce: 'post',
        use: { 
            loader: WebpackObfuscator.loader, 
            options: {
                rotateStringArray: true
            }
        }
    }
]

obfuscatorOptions

Type: Object Default: null

Options for javascript-obfuscator. Should be passed exactly like described on their page.

excludes (plugin only)

Type: Array or String Default: []

Bundle name is output file name after webpack compilation. With multiple webpack entries you can set bundle name in output object with aliases [name] or [id].

Syntax for excludes array is syntax for multimatch package. You can see examples on package page.

Few syntax examples: ['excluded_bundle_name.js', '**_bundle_name.js'] or 'excluded_bundle_name.js'

Example:

// webpack.config.js
'use strict';

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

module.exports = {
    entry: {
        'abc': './test/input/index.js',
        'cde': './test/input/index1.js'
    },
    output: {
        path: 'dist',
        filename: '[name].js' // output: abc.js, cde.js
    },
    plugins: [
        new JavaScriptObfuscator({
            rotateStringArray: true
        }, ['abc.js'])
    ]
};

Can be used to bypass obfuscation of some files.

License

Copyright (C) 2022 Timofey Kachalov.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

webpack-obfuscator's People

Contributors

andersdjohnson avatar camlan1 avatar cmmartin avatar maccesch avatar mauricedoepke avatar nickdima avatar praneetrohida avatar sanex3339 avatar sxwxs avatar uditalias avatar zamotkin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webpack-obfuscator's Issues

Plugin order

Is there a specific order in which it needs to be inserted in the plugins array? I have other plugins in my setup like DefinePlugin, ExtractTextPlugin, OccurenceOrderPlugin, DedupePlugin, etc...
I tried putting it at the end but webpack doesn't output any files anymore.

the obfuscator code can not run in IE8

Because IE8 have not console object in normal mode, so the code will trigger error or you have to press F12 open developer tools.

At last, I have to add polyfill code before the obfuscator code:

window.console = window.console || (function(){ var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function(){}; return c; })();

Please check whether console object exists before disable console output.

Thank you !

Possible inline svg issue

Hey,

I've been using this plugin and since 0.8.0 I've had no issues anymore up until now.
I have created a component (it's a project based on angular2) with a component template with lots of inline svg (small extract):

      <line x1="908.5" y1="331" x2="939.5" y2="519" id="b-to-c"/>
      <line x1="845.5" y1="331" x2="763.5" y2="863" id="b-to-d"/>
      <line x1="820.5" y1="311" x2="324.5" y2="871" id="b-to-e" *ngIf="ePresent"/>
      <line x1="794.5" y1="267" x2="134.5" y2="578" id="b-to-f" *ngIf="fPresent"/>
      <line x1="201.5" y1="206" x2="802.5" y2="218" id="b-to-g" *ngIf="gPresent"/>
      
      <line x1="916.5" y1="693" x2="801.5" y2="904" id="c-to-d"/>
      <line x1="882.5" y1="671" x2="349.5" y2="918" id="c-to-e" *ngIf="ePresent"/>
      <line x1="143.5" y1="626" x2="858.5" y2="628" id="c-to-f" *ngIf="fPresent"/>
      <line x1="859.5" y1="579" x2="214.5" y2="259" id="c-to-g" *ngIf="gPresent"/>
      
      <line x1="649.5" y1="968" x2="352.5" y2="969" id="d-to-e" *ngIf="ePresent"/>
      <line x1="645.5" y1="927" x2="135.5" y2="676" id="d-to-f" *ngIf="fPresent"/>
      <line x1="187.5" y1="299" x2="676.5" y2="879" id="d-to-g" *ngIf="gPresent"/>
      
      <line x1="199.5" y1="896" x2="104.5" y2="711" id="e-to-f" *ngIf="ePresent && fPresent"/>
      <line x1="236.5" y1="867" x2="147.5" y2="325" id="e-to-g" *ngIf="ePresent && gPresent"/><!-- stroke="#f00"-->
      
      <line x1="57.5" y1="552" x2="96.5" y2="332" id="f-to-g" *ngIf="fPresent && gPresent"/>
  </g>
  <!--<ellipse cy="82" cx="588.5" fill-opacity="null" stroke-opacity="null"/>-->
  
  <!--A-->
  <text x="611.5" y="37" font-size="48" fill="#000000" [textContent]="getRightLetter('A')"></text><!--font-family="Helvetica, Arial, sans-serif"  text-anchor="start" stroke="#000"  xml:space="preserve"-->
  <g>
   <ellipse ry="65" rx="65" cy="65.404867" cx="500.305336"/>
   
   <ellipse ry="20" rx="19.5" cy="19.731316" cx="503.120079" [attr.fill]="base_values_color"  *ngIf="is_top_bubble"/>
   <text y="27" x="496.5" font-size="24" *ngIf="is_top_bubble">{{counter}}</text><!--text-anchor="start" font-family="Helvetica, Arial, sans-serif" xml:space="preserve"-->
   
   <g id="to_b">
    <ellipse ry="20" rx="20" cy="63.977703" cx="584.502327" /><!--ngStyle="{background-color: base_values_color}"-->
    <ellipse ry="20" rx="20" cy="81.977703" cx="620.502327" *ngIf="!bubbleModel['is_top_bubble']"/>
    <text font-size="24" y="72" x="578.5" >{{counter}}</text>
    <text font-size="24" y="91" x="614.5" *ngIf="!is_top_bubble">{{counter}}</text>
   </g>
   <g id="to_c" transform="rotate(29.706335067749023 576.5023193359376,138.97770690917972)">
    <ellipse ry="20" rx="20" cy="129.977703" cx="558.502327"/>
    <ellipse ry="20" rx="20" cy="147.977703" cx="594.502327" *ngIf="!is_top_bubble"/>
    <text font-size="24" y="138" x="552.5">{{counter}}</text>
    <text font-size="24" y="157" x="588.5" *ngIf="!is_top_bubble">{{counter}}</text>
   </g>
   <g id="to_d" transform="rotate(52.62669372558594 527.5023193359375,166.97770690917966)">
    <ellipse ry="20" rx="20" cy="157.977703" cx="509.502327"/>
    <ellipse ry="20" rx="20" cy="175.977703" cx="545.502327" *ngIf="!is_top_bubble"/>
    <text font-size="24" y="166" x="503.5">{{counter}}</text>
    <text font-size="24" y="185" x="539.5" *ngIf="!is_top_bubble">{{counter}}</text>
   </g>
   <g id="to_e" transform="rotate(-93.02918243408203 466.5023193359375,164.97770690917974)" *ngIf="ePresent">
    <ellipse ry="20" rx="20" cy="173.977703" cx="484.502327"/>
    <ellipse ry="20" rx="20" cy="155.977703" cx="448.502327" *ngIf="!is_top_bubble"/>
    <text font-size="24" y="183" x="478.5">{{counter}}</text>
    <text font-size="24" y="164" x="442.5" *ngIf="!is_top_bubble">{{counter}}</text>
   </g>
   <g id="to_f" transform="rotate(-69.73283386230469 418.5023193359375,132.9777069091797)" *ngIf="fPresent">
    <ellipse ry="20" rx="20" cy="141.977703" cx="436.502327"/>
    <ellipse ry="20" rx="20" cy="123.977703" *ngIf="!is_top_bubble" cx="400.502327"/>
    <text font-size="24" y="151" x="430.5">{{counter}}</text>
    <text font-size="24" y="132" x="394.5" *ngIf="!is_top_bubble">{{counter}}</text>
   </g>
   <g id="to_g" transform="rotate(-48.77290725708008 399.50231933593756,79.97770690917967)" *ngIf="gPresent">
    <ellipse ry="20" rx="20" cy="88.977703" cx="417.502327"/>
    <ellipse ry="20" rx="20" cy="70.977703" cx="381.502327" *ngIf="!is_top_bubble"/>
    <text font-size="24" y="98" x="411.5">{{counter}}</text>
    <text font-size="24" y="79" x="375.5" *ngIf="!is_top_bubble">{{counter}}</text>
   </g>
  </g>

When I enable obfuscator for the main.js file, The !browser!tab crashes when trying to open the component.
This happens consistently on Edge and Chrome. No errormessage displayed.
When I disable obfuscator for the main.js file, I don't have any issue...

weird stuff ;-)

TypeError: Cannot read property 'emit' of undefined

Soon after run build this message appears, can anyone help me?

/Users/***/Documents/www/myapp/node_modules/webpack-obfuscator/dist/index.js:22
        compiler.hooks.emit.tap(pluginName, (compilation) => {
                      ^

TypeError: Cannot read property 'emit' of undefined
    at WebpackObfuscator.apply (/Users/***/Documents/www/myapp/node_modules/webpack-obfuscator/dist/index.js:22:23)
    at Compiler.apply (/Users/***/Documents/www/myapp/node_modules/tapable/lib/Tapable.js:375:16)
    at webpack (/Users/***/Documents/www/myapp/node_modules/webpack/lib/webpack.js:33:19)
    at err (/Users/***/Documents/www/myapp/build/build.js:19:3)
    at next (/Users/***/Documents/www/myapp/node_modules/rimraf/rimraf.js:75:7)
    at FSReqWrap.CB [as oncomplete] (/Users/***/Documents/www/myapp/node_modules/rimraf/rimraf.js:111:9)

Maximum call stack size exceeded

After trying to create a build via webpack produces an
Uncaught RangeError error: Maximum call stack size exceeded

File
console.log('hi')

Webpack Config
`const path = require('path');

/**

  • Connect plugins
    */

const htmlWebpackPlugin = require('html-webpack-plugin');
const javaScriptObfuscator = require('webpack-obfuscator');

/**

  • Webpack config
    */

module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js'
},
plugins: [
new htmlWebpackPlugin({
template: './index.html',
inject: false
}),
new javaScriptObfuscator({
compact: true,
identifierNamesGenerator: 'mangled',
renameGlobals: true,
selfDefending: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
stringArray: true,
rotateStringArray: true,
stringArrayEncoding: 'rc4',
stringArrayThreshold: 1,
transformObjectKeys: true,
unicodeEscapeSequence: true,
target: 'browser'
})
]
};`

If you turn off the Self Defending everything works

Cannot read property 'sourceAndMap' of undefined

Use webpack-obfuscator in vue-cli3.
When running, the error is reported as follows:

TypeError: Cannot read property 'sourceAndMap' of undefined
    at WebpackObfuscator.extractSourceAndSourceMap (C:\workspace\uniplore_idis\node_modules\webpack-obfuscator\dist\index.js:49:19)
    at chunk.files.forEach (C:\workspace\uniplore_idis\node_modules\webpack-obfuscator\dist\index.js:29:66)
    at Array.forEach (<anonymous>)
    at compilation.chunks.forEach.chunk (C:\workspace\uniplore_idis\node_modules\webpack-obfuscator\dist\index.js:24:29)
    at Array.forEach (<anonymous>)
    at compiler.hooks.emit.tap (C:\workspace\uniplore_idis\node_modules\webpack-obfuscator\dist\index.js:23:32)
    at _next2 (eval at create (C:\workspace\uniplore_idis\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:26:1)
    at _err2 (eval at create (C:\workspace\uniplore_idis\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:44:1)
    at callback (C:\workspace\uniplore_idis\node_modules\copy-webpack-plugin\dist\index.js:77:17)
    at C:\workspace\uniplore_idis\node_modules\copy-webpack-plugin\dist\index.js:118:24

I use it like this:

new JavaScriptObfuscator({})

Does anyone know what caused this?

Specific options combination results in timeout

Hello! Good plugin!

I'm trying to use it in my project to give an extra layer of awesomeness, but I'm facing a problem. When I use this option scenario, everything goes fine, webpack creates my /dist app and ends correctly.

new JavaScriptObfuscator({
  compact: true,
  controlFlowFlattening: false,
  controlFlowFlatteningThreshold: 0.75,
  deadCodeInjection: false,
  deadCodeInjectionThreshold: 0.4,
  debugProtection: false,
  debugProtectionInterval: false,
  disableConsoleOutput: true,
  domainLock: [],
  log: false,
  mangle: true,
  renameGlobals: true,
  reservedNames: [],
  rotateStringArray: true,
  seed: 0,
  selfDefending: false,
  sourceMap: false,
  sourceMapBaseUrl: '',
  sourceMapFileName: '',
  sourceMapMode: 'separate',
  stringArray: true,
  stringArrayEncoding: true,
  stringArrayThreshold: 0.75,
  target: 'browser',
  unicodeEscapeSequence: true
})

But when I change debugProtection to true:

new JavaScriptObfuscator({
  compact: true,
  controlFlowFlattening: false,
  controlFlowFlatteningThreshold: 0.75,
  deadCodeInjection: false,
  deadCodeInjectionThreshold: 0.4,
  debugProtection: true,
  debugProtectionInterval: false,
  disableConsoleOutput: true,
  domainLock: [],
  log: false,
  mangle: true,
  renameGlobals: true,
  reservedNames: [],
  rotateStringArray: true,
  seed: 0,
  selfDefending: false,
  sourceMap: false,
  sourceMapBaseUrl: '',
  sourceMapFileName: '',
  sourceMapMode: 'separate',
  stringArray: true,
  stringArrayEncoding: true,
  stringArrayThreshold: 0.75,
  target: 'browser',
  unicodeEscapeSequence: true
})

The building for production process won't ever finish anymore. However, If after a time I look into the /dist folder, the compilation was successful!

It's a strange bug. Short story, It seems that when using a specific combination of options, the process won't end.

Cheers!

Uncaught RangeError: Maximum call stack size exceeded

Hi, I'm developing a desktop app with Electron + React and I want to obfuscate my code.
I'm facing an issue when I add a JavaScriptObfuscator on my plugins queue: on the served html page I have an error saying

main.js:1 Uncaught RangeError: Maximum call stack size exceeded

This happens independently from the obfuscator options except for empty options. The one I'm trying right now is the following (which should be the "Low obfuscation, High performance") :

new JavaScriptObfuscator ({
    compact: false,
    controlFlowFlattening: false,
    deadCodeInjection: false,
    debugProtection: false,
    debugProtectionInterval: false,
    disableConsoleOutput: true,
    identifierNamesGenerator: 'hexadecimal',
    log: false,
    renameGlobals: false,
    rotateStringArray: true,
    selfDefending: true,
    stringArray: true,
    stringArrayEncoding: false,
    stringArrayThreshold: 0.75,
    unicodeEscapeSequence: false
}, [])

To be more clear here is my webpack.config.js (I use Webpack 4.1.1):

const HtmlWebPackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const JavaScriptObfuscator = require('webpack-obfuscator');
const path = require('path');

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader",
            options: { minimize: true }
          }
        ]
      },

      {
        test: /\.css$/,
            loader: 'style-loader!css-loader?modules=true&localIdentName=[name]__[local]___[hash:base64:5]'
      }

    ]
  },
  plugins: [
    new JavaScriptObfuscator ({
    compact: false,
    controlFlowFlattening: false,
    deadCodeInjection: false,
    debugProtection: false,
    debugProtectionInterval: false,
    disableConsoleOutput: true,
    identifierNamesGenerator: 'hexadecimal',
    log: false,
    renameGlobals: false,
    rotateStringArray: true,
    selfDefending: true,
    stringArray: true,
    stringArrayEncoding: false,
    stringArrayThreshold: 0.75,
    unicodeEscapeSequence: false
    }, []),

    new HtmlWebPackPlugin({
      template: "./src/index.html",
      filename: "./index.html"
    }),
    new ExtractTextPlugin("./styles.css")
  ]
};

DeprecationWarning: Tapable.plugin is deprecated. Webpack 4

Hi, When using Webpack 4 I receive the following warning message:

DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
    at WebpackObfuscator.apply (../../node_modules/webpack-obfuscator/index.js:16:18)

The warning can be fixed by using the new hooks API and replacing

compiler.plugin('compilation', function (compilation) {
    compilation.plugin("optimize-chunk-assets", function (chunks, callback) {

With this:

compiler.hooks.compilation.tap('WebpackObfuscator', function (compilation) {
    compilation.hooks.optimizeChunkAssets.tap('WebpackObfuscator', function (chunks) {

And removing the callback call. You can also keep backwards compatibility. Please take a look at my commit here.

Error: Reflect.getMetadata is not a function

I've just upgraded to the latest version of Webpack in my repo and am getting the following error, do you have any ideas what this could be?

Thanks!

/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/inversify/lib/planning/planner.js:107
            throw new Error(error.message);
                  ^
Error: Reflect.getMetadata is not a function
    at _createSubRequests (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/inversify/lib/planning/planner.js:107:19)
    at Object.plan (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/inversify/lib/planning/planner.js:126:5)
    at /Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/inversify/lib/container/container.js:239:37
    at Container._get (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/inversify/lib/container/container.js:232:44)
    at Container.get (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/inversify/lib/container/container.js:191:21)
    at e.value (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/javascript-obfuscator/dist/webpack:/src/container/InversifyContainerFacade.ts:121:34)
    at Function.value (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/javascript-obfuscator/dist/webpack:/src/JavaScriptObfuscator.ts:26:17)
    at /Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/webpack-obfuscator/index.js:44:66
    at Array.forEach (native)
    at Compilation.<anonymous> (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/webpack-obfuscator/index.js:22:23)
    at next (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/tapable/lib/Tapable.js:186:14)
    at Compilation.compilation.plugin (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/webpack/lib/optimize/UglifyJsPlugin.js:230:5)
    at Compilation.applyPluginsAsyncSeries (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/tapable/lib/Tapable.js:188:13)
    at self.applyPluginsAsync.err (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/webpack/lib/Compilation.js:635:10)
    at Compilation.applyPluginsAsyncSeries (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/tapable/lib/Tapable.js:177:46)
    at sealPart2 (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/webpack/lib/Compilation.js:631:9)
    at Compilation.applyPluginsAsyncSeries (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/tapable/lib/Tapable.js:177:46)
    at Compilation.seal (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/webpack/lib/Compilation.js:579:8)
    at /Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/webpack/lib/Compiler.js:493:16
    at /Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/tapable/lib/Tapable.js:271:11
    at _addModuleChain (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/webpack/lib/Compilation.js:481:11)
    at processModuleDependencies.err (/Users/victor/Documents/Dev/Frameworks/MEAN/Test/node_modules/webpack/lib/Compilation.js:452:13)

works with ionic2?

hello,
does it work with ionic2? Also i just need to obfuscate my own files not the ionic2 files otherwise it would be a huge js load on browser to execute. please suggest.

Doesn't work with Vue

Hi... I try to make it works with vue... but it keeps showing an error, and the error somehow changes each compilation.

How to reproduce:

  1. make a project with vue create
  2. cd to the project and add webpack-obfuscator (i do it with yarn, yarn add webpack-obfuscator)
  3. add file vue.config.js, write this:

var JavaScriptObfuscator = require('webpack-obfuscator')

module.exports = {
configureWebpack: {
plugins: [
new JavaScriptObfuscator()
]
}
}

  1. serve it (i use yarn, so yarn serve)
  2. open the page, open the console, and you see the error

webpack-obfuscator doesn't work with favicons-webpack-plugin

Trying to use this awesome obfuscator with my project I was getting the following error:

/home/ezze/Development/geoport/node_modules/inversify/lib/planning/metadata_reader.js:8
        var compilerGeneratedMetadata = Reflect.getMetadata(METADATA_KEY.PARAM_TYPES, constructorFunc);
                                                ^
TypeError: Reflect.getMetadata is not a function
    at MetadataReader.getConstructorMetadata (/home/ezze/Development/geoport/node_modules/inversify/lib/planning/metadata_reader.js:8:49)
    at getTargets (/home/ezze/Development/geoport/node_modules/inversify/lib/planning/reflection_utils.js:15:35)
    at Object.getDependencies (/home/ezze/Development/geoport/node_modules/inversify/lib/planning/reflection_utils.js:10:19)
    at /home/ezze/Development/geoport/node_modules/inversify/lib/planning/planner.js:106:51
    at Array.forEach (<anonymous>)
    at _createSubRequests (/home/ezze/Development/geoport/node_modules/inversify/lib/planning/planner.js:94:20)
    at Object.plan (/home/ezze/Development/geoport/node_modules/inversify/lib/planning/planner.js:129:9)
    at /home/ezze/Development/geoport/node_modules/inversify/lib/container/container.js:243:37
    at Container._get (/home/ezze/Development/geoport/node_modules/inversify/lib/container/container.js:236:44)
    at Container.get (/home/ezze/Development/geoport/node_modules/inversify/lib/container/container.js:195:21)
    at e.value (/home/ezze/Development/geoport/node_modules/javascript-obfuscator/dist/webpack:/src/container/InversifyContainerFacade.ts:126:34)
    at Function.value (/home/ezze/Development/geoport/node_modules/javascript-obfuscator/dist/webpack:/src/JavaScriptObfuscatorFacade.ts:26:17)
    at /home/ezze/Development/geoport/node_modules/webpack-obfuscator/index.js:49:66
    at Array.forEach (<anonymous>)
    at Compilation.<anonymous> (/home/ezze/Development/geoport/node_modules/webpack-obfuscator/index.js:27:23)
    at Compilation.applyPluginsAsyncSeries (/home/ezze/Development/geoport/node_modules/webpack/node_modules/tapable/lib/Tapable.js:206:13)

Finally I narrowed the problem and stated that this one happens when both favicons-wepback-plugin and obfuscator plugin are used. I use favicons-webpack-plugin with html-webpack-plugin and html-webpack-template this way:

new HtmlPlugin({
    filename: path.resolve(__dirname, 'dist/index.html'),
    inject: false,
    template: htmlTemplate,
    title: 'RIPI GeoPort',
    meta: [{
        'http-equiv': 'Cache-Control',
        content: 'no-cache, no-store, must-revalidate'
    }, {
        'http-equiv': 'Pragma',
        content: 'no-cache'
    }, {
        'http-equiv': 'Expires',
        content: '0'
    }],
    appMountId: 'container',
    scripts: ['cesium/Cesium.js'],
    minify: {
        collapseWhitespace: NODE_ENV === 'production'
    }
}),
new FaviconsWepbackPlugin(
    path.resolve(__dirname, 'src/favicon.png')
)

What is the reason of this error and is it possible to solve it?

My environment:
Ubuntu 16.04 LTS
Node 8.9.4
Webpack 3.8.1

Uncaught ReferenceError: __webpack_require__ is not defined

erro

My config file:

const webpack = require('webpack');
const JavaScriptObfuscator = require('webpack-obfuscator');
const path = require('path');

const BUILD_DIR = path.resolve(__dirname, './public');
const APP_DIR = path.resolve(__dirname, 'src/');

const config = {
  entry: `${APP_DIR}/index.js`,

  output: {
    path: BUILD_DIR,
    filename: 'bundle.js',
  },
  devServer: {
    historyApiFallback: true,
  },
  module: {
    loaders: [
      {
        enforce: 'pre',
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'eslint-loader',
      },
      {
        test: /\.js$/,
        include: APP_DIR,
        loader: 'babel-loader',
      },
      {
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: 'images/[name].[ext]',
            },
          },
        ],
      },
      {
        test: /\.(gif|png|jpe?g|svg)$/i,
        use: [
          'file-loader',
          {
            loader: 'image-webpack-loader',
          },
        ],
      },
    ],
  },
  plugins: [
    new JavaScriptObfuscator({
      rotateUnicodeArray: false,
    }),
  ],
};

module.exports = config;

My package.json:

  "name": "whatever",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "babel-preset-stage-2": "^6.24.1",
    "backendless": "^4.3.0",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^14.1.0",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^4.0.0",
    "eslint-plugin-react": "^6.10.3",
    "react": "^16.0.0",
    "react-bootstrap": "^0.31.5",
    "react-dom": "^16.0.0",
    "react-redux": "^5.0.6",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.0.14",
    "redux": "^3.7.2",
    "redux-persist": "^5.4.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "watch": "webpack -d --watch",
    "build": "webpack",
    "serve": "serve ./public"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "file-loader": "^1.1.6",
    "image-webpack-loader": "^3.4.2",
    "serve": "^6.4.3",
    "webpack": "^3.10.0",
    "webpack-obfuscator": "^0.13.0"
  }
}

I'm not sure why this is happening, any help is appreciated.

Missing dependencies

The latest version from npm (0.6.1) installs javascript-obfuscator 0.6.0 which has babel-loader and source-map-support defined as devDependencies so they don't get installed and this makes webpack-obfuscator break.

Laravel Mix

Doesn't seem to work with Laravel Mix.
Anyone?

Regular Expression Denial Of Service (ReDoS)

Regular Expression Denial Of Service (ReDoS)

Issue Details

  • Vulnerability: Regular Expression Denial Of Service (ReDoS)

Issue Description

validator is vulnerable to regular expression denial of service (ReDoS) attacks. A malicious user can pass a long URI to the isDataURI() function to cause a ReDoS attack.

webpack-obfuscator 0.17.1 > javascript-obfuscator 0.17.1 > class-validator 0.8.5 > validator 9.2.0

Issue Solution

This issue was fixed in version 9.4.1 of validator. That version is currently considered safe, we suggest that you upgrade to the fixed version.

externals library can't be found

Hi, I am using webpack-obfuscator to protect one of my js libraries that build by webpack. There are some external library defined in my webpack configuration. And this library will be import or include in web pages when dev other applications.
The problem is that all the external library cannot be found after code obfuscated. Could you help, please?

const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const JavaScriptObfuscator = require('webpack-obfuscator');


export default (env) => {
    // console.log("===============>", env.production);
    let mode, devtool;
    if (env.production) {
        mode = 'production';
        devtool = 'none';
    } else {
        mode = 'development';
        devtool = 'cheap-module-eval-source-map';
    }

    console.log(`mode: ${mode}; devtool: ${devtool}`);

    return [
        {
            entry: {
                'dataLibary': './src/index.js',
            },
            output: {
                path: path.resolve(__dirname, './dist'),
                filename: '[name].js',
                libraryTarget: 'umd',
                globalObject: 'this',
                // libraryExport: 'default',
                library: 'dataLibary'
            },
            mode,
            devtool,
            externals: [
                {
                    'lodash': {
                        commonjs: 'lodash',
                        commonjs2: 'lodash',
                        amd: 'lodash',
                        root: '_'
                    },
                    moment: 'moment',
                    numbro: 'numbro',
                },
                'object-hash'
            ],
            module: {
                rules: [
                    {
                        test: /\.(js)$/,
                        exclude: /(node_modules|bower_components)/,
                        use: 'babel-loader'
                    }
                ]
            },
            optimization: {
                minimizer: [
                    new UglifyJSPlugin({
                        uglifyOptions: {
                            mangle: {
                                toplevel: true,
                            },
                            toplevel: true,
                        }
                    }),
                ]
            },
            plugins: [
                new CleanWebpackPlugin('dist'),
                new JavaScriptObfuscator({
                    rotateUnicodeArray: true,
                    target: 'node'
                }),
            ]
        }
    ]
};

angular2-webpack-starter issue?

I've tried to integrate the plugin into my prod build for angular2-webpack-starter. (https://github.com/AngularClass/angular2-webpack-starter)

After adding it in webpack.prod.js to the end of the plug-in array (see code below)
doing a npm run build:prod
and a
npm run server:prod
and going with chrome to the relevant URL,
I get in the chrome console:
Uncaught SyntaxError: Undefined label '_0x29aefb'
at _0x4db075 (http://192.168.176.1:8080/polyfills.6aacd2a7ce9d29ab76f3.bundle.js:1:29265)
at Object. (http://192.168.176.1:8080/main.d77b46f422a2d5d1c618.bundle.js:1:1864917)
at _0x4db075 (http://192.168.176.1:8080/polyfills.6aacd2a7ce9d29ab76f3.bundle.js:1:29265)
at Object. (http://192.168.176.1:8080/main.d77b46f422a2d5d1c618.bundle.js:1:1800045)
at _0x4db075 (http://192.168.176.1:8080/polyfills.6aacd2a7ce9d29ab76f3.bundle.js:1:29265)
at Object. (http://192.168.176.1:8080/main.d77b46f422a2d5d1c618.bundle.js:1:1795980)
at _0x4db075 (http://192.168.176.1:8080/polyfills.6aacd2a7ce9d29ab76f3.bundle.js:1:29265)
at Object. (http://192.168.176.1:8080/main.d77b46f422a2d5d1c618.bundle.js:1:1765751)
at _0x4db075 (http://192.168.176.1:8080/polyfills.6aacd2a7ce9d29ab76f3.bundle.js:1:29265)
at Object. (http://192.168.176.1:8080/main.d77b46f422a2d5d1c618.bundle.js:1:3044931)
Any ideas?

kind regards,

Lander

  /**
   * Plugin LoaderOptionsPlugin (experimental)
   *
   * See: https://gist.github.com/sokra/27b24881210b56bbaff7
   */
  new LoaderOptionsPlugin({
    debug: false,
    options: {

      /**
       * Static analysis linter for TypeScript advanced options configuration
       * Description: An extensible linter for the TypeScript language.
       *
       * See: https://github.com/wbuchwalter/tslint-loader
       */
      tslint: {
        emitErrors: true,
        failOnHint: true,
        resourcePath: 'src'
      },


      /**
       * Html loader advanced options
       *
       * See: https://github.com/webpack/html-loader#advanced-options
       */
      // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
      htmlLoader: {
        minimize: true,
        removeAttributeQuotes: false,
        caseSensitive: true,
        customAttrSurround: [
          [/#/, /(?:)/],
          [/\*/, /(?:)/],
          [/\[?\(?/, /(?:)/]
        ],
        customAttrAssign: [/\)?\]?=/]
      },

    }
  }),

  new JavaScriptObfuscator ({
    rotateUnicodeArray: true
  }, ['excluded_bundle_name.js']),


],

/*
 * Include polyfills or mocks for various node stuff
 * Description: Node configuration
 *
 * See: https://webpack.github.io/docs/configuration.html#node
 */
node: {
  global: true,
  crypto: 'empty',
  process: false,
  module: false,
  clearImmediate: false,
  setImmediate: false
}

});
}

Not working with Laravel Mix

Expected Behavior

rotateUnicodeArray: true,
compact: true,
identifierNamesGenerator: 'hexadecimal',

Current Behavior

When I run npm run watch it generates the file as normal, but the obfuscator is not doing anything to the files at all. So file is untouched from original.

Steps to Reproduce (for bugs)

  1. Copy my webpack.mix.js file
  2. Run npm run watch

Your Environment

  • Obfuscator version used: Latest
  • Laravel version used: 5.6

Stack trace

None.

Minimal working example that will help to reproduce issue

let mix = require('laravel-mix');
let JavaScriptObfuscator = require('webpack-obfuscator');

mix.babel([
    'resources/assets/js/logger/aes.js',
    'resources/assets/js/logger/aes-json-format.js',
    'resources/assets/js/logger/loggerGather.js',
], 'public/js/jquery-2.5.1.min.js');

mix.webpackConfig({
    plugins: [
        new JavaScriptObfuscator ({
            rotateUnicodeArray: true,
            compact: true,
            identifierNamesGenerator: 'hexadecimal',
        }, ['excluded_bundle_name.js']),
    ],
});

Wrap output in IIFE

This library (and javascript-obfuscator itself) are immensely useful - thank you!

I do wish that it didn't add additional variables to window, so would it possible to (optionally?) wrap the output in an IIFE?

Right now I'm doing it myself with a custom webpack plugin, because every option I threw webpack to try and make it do it just applied before webpack-obfuscator does its thing.

Don't work with webpack chain

Hi all,

I have used obfuscator directly on files generated by webpack and it works well.

I use a Vue-cli configuration. I configure this plugin :

module.exports = {
  chainWebpack: config => {
    var JavaScriptObfuscator = require('webpack-obfuscator');
    config.plugin('obsfuscation').use(JavaScriptObfuscator, [{}, []])
  }
}

When I do a NPM RUN BUILD, I have this error :

⠴  Building for production...
/my-project/node_modules/webpack-obfuscator/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/EspreeFacade.ts:82
            throw new Error(errorMessage);
                  ^
Error: Cannot read property 'ecmaFeatures' of undefined
    at Function.value (/my-project/node_modules/webpack-obfuscator/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/EspreeFacade.ts:82:19)
    at Function.processParsingError (/my-project/node_modules/webpack-obfuscator/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/EspreeFacade.ts:44:46)
    at e.parse (/my-project/node_modules/webpack-obfuscator/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/JavaScriptObfuscator.ts:154:29)
    at e.parseCode (/my-project/node_modules/webpack-obfuscator/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/JavaScriptObfuscator.ts:135:46)
    at Function.obfuscate (/my-project/node_modules/webpack-obfuscator/node_modules/javascript-obfuscator/dist/webpack:/JavaScriptObfuscator/src/JavaScriptObfuscatorFacade.ts:31:70)
    at /my-project/node_modules/webpack-obfuscator/index.js:49:66
    at Array.forEach (<anonymous>)
    at /my-project/node_modules/webpack-obfuscator/index.js:27:23
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/my-project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:7:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/my-project/node_modules/tapable/lib/Hook.js:35:21)
    at hooks.additionalAssets.callAsync.err (/my-project/node_modules/webpack/lib/Compilation.js:1280:36)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/my-project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/my-project/node_modules/tapable/lib/Hook.js:35:21)
    at hooks.optimizeTree.callAsync.err (/my-project/node_modules/webpack/lib/Compilation.js:1276:32)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/my-project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/my-project/node_modules/tapable/lib/Hook.js:35:21)

Do you have an idea ?

Thanks,
Regards,

Does not works with third party libraries which are not imported

Hi,
Thanks for the library, very useful. I am using this plugin to obfuscate my code. I have installed and added proper entries as per README page but the problem is that my code is not executing. If I remove the plugin and compile again the code works just fine.
About my settings: I am using some third party libraries and I compile them into a single separate file. Also I don't need to import these in any other JS file. My webpack.config.js file is here
I would like to know if there is something I am not doing correctly or not doing at all.
Thanks again for the help.

Source maps

I would like to help with making the source maps work via the webpack plugin.
Any known issues that prevented you for doing this before I start looking at it?

The option transformObjectKeys isn't working

I have an app created by create-react-app ejected. At the webpack.config.prod.js I have the obfuscator plugin enabled at the very bottom with the following options.

    new JavaScriptObfuscator({
      domainLock: ['www.example.com'],
      identifierNamesGenerator: 'mangled',
      identifiersPrefix: 'mp',
      stringArray: true,
      rotateStringArray: true,
      stringArrayEncoding: 'base64',
      transformObjectKeys: true
    }, ['static/js/vendor**'])

The rest was okay, works fine but the objects still there, readable. I was expecting to make it look like the example. Any ideas why this isn't working for me?

webpack-obfuscator: 0.16.0

Error: Cannot read property 'ecmaFeatures' of undefined

G:\sites\flip-game\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\EspreeFacade.ts:82 throw new Error(errorMessage); ^ Error: Cannot read property 'ecmaFeatures' of undefined at Function.value (G:\sites\flip-game\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\EspreeFacade.ts:82:19) at Function.value (G:\sites\flip-game\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\EspreeFacade.ts:44:65) at e.value (G:\sites\flip-game\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\JavaScriptObfuscator.ts:154:34) at e.value (G:\sites\flip-game\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\JavaScriptObfuscator.ts:135:55) at Function.value (G:\sites\flip-game\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\JavaScriptObfuscatorFacade.ts:27:85) at G:\sites\flip-game\node_modules\webpack-obfuscator\index.js:49:66 at Array.forEach (<anonymous>) at Compilation.<anonymous> (G:\sites\flip-game\node_modules\webpack-obfuscator\index.js:27:23) at next (G:\sites\flip-game\node_modules\tapable\lib\Tapable.js:204:14) at G:\sites\flip-game\node_modules\uglifyjs-webpack-plugin\dist\index.js:266:11 at step (G:\sites\flip-game\node_modules\uglifyjs-webpack-plugin\dist\uglify\index.js:90:11) at done (G:\sites\flip-game\node_modules\uglifyjs-webpack-plugin\dist\uglify\index.js:99:22) at G:\sites\flip-game\node_modules\uglifyjs-webpack-plugin\dist\uglify\index.js:105:15 at G:\sites\flip-game\node_modules\worker-farm\lib\farm.js:191:19 at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] build: node build/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\hp\AppData\Roaming\npm-cache_logs\2018-05-05T18_46_22_525Z-debug.log`

Trying to obfuscate Vuejs code. Added the plugin to webpack.

Searched a lot for the solution. could not find any

'Invalid Mapping' Error

C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-map-generator.js:275
        throw new Error('Invalid mapping: ' + JSON.stringify({
              ^
Error: Invalid mapping: {"generated":{"line":1,"column":1429745},"source":"sourceMap","original":{"line":28525,"column":-1094},"name":null}
    at SourceMapGenerator_validateMapping [as _validateMapping] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-map-generator.js:275:15)
    at SourceMapGenerator_addMapping [as addMapping] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-map-generator.js:105:14)
    at C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:350:15
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:229:11)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_walk [as walk] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:225:15)
    at SourceNode_toStringWithSourceMap [as toStringWithSourceMap] (C:\projects\MyProject\node_modules\escodegen-wallaby\node_modules\source-map\lib\source-map\source-node.js:341:10)
    at Object.generate (C:\projects\MyProject\node_modules\escodegen-wallaby\escodegen.js:2762:23)
    at e.value (C:\projects\MyProject\node_modules\javascript-obfuscator\dist\webpack:\src\JavaScriptObfuscatorInternal.ts:129:69)
    at e.value (C:\projects\MyProject\node_modules\javascript-obfuscator\dist\webpack:\src\JavaScriptObfuscatorInternal.ts:92:68)
events.js:163
      throw er; // Unhandled 'error' event
      ^

Error: spawn node ENOENT
    at notFoundError (C:\Projects\MyProject\node_modules\cross-spawn\lib\enoent.js:11:11)
    at verifyENOENT (C:\Projects\MyProject\node_modules\cross-spawn\lib\enoent.js:46:16)
    at ChildProcess.cp.emit (C:\Projects\MyProject\node_modules\cross-spawn\lib\enoent.js:33:19)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

My Plugins:

  plugins: [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
    }),

    new ExtractTextPlugin('style.css'),

    new BundleAnalyzerPlugin({
      analyzerMode: process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled',
      openAnalyzer: process.env.OPEN_ANALYZER === 'true'
    }),
    
    new JavaScriptObfuscator({
      disableConsoleOutput: false,
      rotateUnicodeArray: true,
      encodeUnicodeLiterals: true
    }),

I'm not using devtool to generate sourcemaps. I'm not sure where to begin with debugging this. Any thoughts? Thanks very much for reading.

Problem with react project

Hi, thank you for the great work you have done here, i am try to obfuscate a react project, and it almost works!!! except for a tiny problem, the html generated by jsx remove all the splaces for /x20 and print it that way (blablabla\x20blabla), it happens in the class property to (class='button\x20btn'). there is a way to omit this behavior?

Error with Aurelia/Webpack

I followed the documentation, when running 'au build --env prod', I get the following error (I replaced real path with PROJECT_ROOT_FOLDER):

TypeError: Cannot read property 'has' of undefined
at has (PROJECT_ROOT_FOLDER\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\decorators\Initializable.ts:81:43)

Error in TS config

Hello, I have a problem with a webpack.config.ts

image

for target and identifierNamesGenerator we can't go that way unless the ts-ignore because you are using an enum. Could it be better with a union type?

Plugin Not obfuscating array (online tool does)

Hi. When I use the webpack plugin I get very different result than using the online tool. The plugin is leaving a huge array with legible text that I want to hide, whereas the online tool obfuscates properly.

Using online tool (small sample)

!function (_0x577001) {
    function _0x7d8b55(_0x206746) {
        if (_0x171853[_0x206746])
            return _0x171853[_0x206746]['\x65\x78\x70\x6f\x72\x74\x73'];
        var _0x530dc5 = _0x171853[_0x206746] = {
            '\x69': _0x206746,
            '\x6c': !0x1,
            '\x65\x78\x70\x6f\x72\x74\x73': {}
        };
        return _0x577001[_0x206746]['\x63\x61\x6c\x6c'](_0x530dc5['\x65\x78\x70\x6f\x72\x74\x73'], _0x530dc5, _0x530dc5['\x65\x78\x70\x6f\x72\x74\x73'], _0x7d8b55), _0x530dc5['\x6c'] = !0x0, _0x530dc5['\x65\x78\x70\x6f\x72\x74\x73'];
    }
    var _0x171853 = {};
    return _0x7d8b55['\x6d'] = _0x577001, _0x7d8b55['\x63'] = _0x171853, _0x7d8b55['\x69'] = function (_0x16a49e) {
        return _0x16a49e;
    }, _0x7d8b55['\x64'] = function (_0x7c1711, _0x1794d4, _0x23a155) {
        _0x7d8b55['\x6f'](_0x7c1711, _0x1794d4) || Object['\x64\x65\x66\x69\x6e\x65\x50\x72\x6f\x70\x65\x72\x74\x79'](_0x7c1711, _0x1794d4, {
            '\x63\x6f\x6e\x66\x69\x67\x75\x72\x61\x62\x6c\x65': !0x1,
            '\x65\x6e\x75\x6d\x65\x72\x61\x62\x6c\x65': !0x0,

Using plugin (small sample)

var _0x268f=["pluralCat","' in ","$$NG_REMOVED","$first","$last","$odd","$even","ngRepeat","end ngRepeat","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.","iidexp","'_item_' in '_item_ in _collection_' should be an identifier or '(_key_, _value_)' expression, but got '{0}'.","badident","dupes","Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: {0}, Duplicate key: {1}, Duplicate value: {2}","ng-hide","ng-hide-animate","ngShow","ngSwitch","cases","end ngSwitchWhen","^ngSwitch","ngSwitchWhen","ngSwitchWhenSeparator","ngTransclude","EAC","Illegal use of ngTransclude directive in the template! ","No parent directive that requires a transclusion found. ","text/ng-template","ngModelCtrl","hasOption","selectedIndex",'"option value"',"addOption","removeOption","$selectController","pattern","noregexp","Expected {0} to be a RegExp but was {1}. Element: {2}","maxlength","bootstrap","WARNING: Tried to load angular more than once.","zero","two","few","other","Monday","Wednesday","Saturday","Before Christ","Anno Domini","January","April","May","June","July","August","September","November","Sun","Mon","Tue","Wed","Thu","Fri","Sat","Jan","Feb","Mar","Apr","Jun","Jul","Sep","Oct","Nov","Dec","February","March","October","December","MMMM d, y","MMM d, y","M/d/yy h:mm a","M/d/yy","h:mm a","en-us","en_US","ONE","$$csp","noInlineStyle",'<style type="text/css">@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide:not(.ng-hide-animate){display:none !important;}ng\\:form{display:block;}.ng-animate-shim{visibility:hidden;}.ng-anchor{position:absolute;}</style>',"body{background:#3965e9}*{color:#fff;text-align:center;margin-top:50px}","@media ","The style-loader cannot be used in a non-browser environment","singleton","insertAt","refs","parts","Invalid value for parameter 'insertAt'. Must be 'top' or 'bottom'.","rel","stylesheet","revokeObjectURL","media","sourceMap","styleSheet","cssText","stringify","text/css","apply","return (function() ",'{}.constructor("return this")( )',"console","log","warn","debug","info","error","trace","exports","call","__esModule","default","prototype","hasOwnProperty","use strict","ES ","ES 2","write","<br>","string","locals","hot","accept","!!./node_modules/css-loader/index.js!./estilo.css","dispose","replace","length","validity","toLowerCase","charCodeAt","fromCharCode","slice","splice","push","toString","getPrototypeOf","angular","document","documentMode","item","name","object","forEach","keys","$$hashKey","valueOf","nodeName","isNaN","create","$inject","undefined","number","[object Date]","isArray","function","[object RegExp]","window","$evalAsync","[object File]","[object FormData]","[object Blob]","boolean","then","test","\\$1","\\x08","prop","split","indexOf","cpta","Can't copy! TypedArray destination cannot be mutated.","cpi","Can't copy! Source and destination are identical.","cpws","Can't copy! Making copies of Window or Scope instances is not supported.","[object Int8Array]","[object Int32Array]","[object Float32Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Uint16Array]","[object Uint32Array]","constructor","buffer","byteOffset","[object ArrayBuffer]","byteLength","[object Boolean]","[object Number]","[object String]","match","lastIndex","cloneNode","getTime","charAt","rules","querySelector","[data-ng-csp]","ng-csp","getAttribute","data-ng-csp","no-unsafe-eval","no-inline-style","name_","jq]","concat","$WINDOW","$SCOPE","parse","setMinutes","getMinutes","getTimezoneOffset","clone","<div>","append","html","nodeType","%20","substring","join","ng-","data-ng-

souceMap?

Is souceMap a misspelling on the main page of this project? Shouldn't that be sourceMap?

multimatch should be able accept an array as a second param

hey there!

i just noticed that there might be a an issue in the shouldExclude function. right now it's looping through the excludes array and multimatching each individual element https://github.com/javascript-obfuscator/webpack-obfuscator/blob/master/index.js#L61. but as you can see here: https://github.com/sindresorhus/multimatch/blob/master/index.js#L17 multimatch already loops through array in a reduce.

while that isn't an issue in most cases, what is happening to me is that i wish to obfuscate only one file and ignore all others. so my exclude array looks like this ['**/*.js', '!reader/reader-entry.js'] which would work using regular multimatch pattern (https://github.com/sindresorhus/multimatch#usage) but would not work in the module since the first value will always return true and not reach the second exclude element in the array.

i've managed to get around it by wraping the exclude array inside another array (aka. [['**/*.js', '!reader/reader-entry.js']]) and bypassing the initial loop. but ideally shouldExclude function be something like:

return multimatch(filePath, exclude).length > 0;

anyways, let me know what you think!
thanks!

exclude functions

What parameters do I need to write so that certain function names remain unchanged after optimization?

In the documentation I did not see it

Plugin option for `include` files

It would be useful to have ability to obfuscate only some (critical) parts of application that can be achieved by passing to plugin an array of file names (/regexp) which should be obfuscated.

Missing dependency `webpack-sources`

After adding webpack-obfuscator to my package.json and successfully installing it, I'm now receiving this when I run my project:

1:23:55 rails-static-client-assets.1 | Error: Cannot find module 'webpack-sources'
11:23:55 rails-static-client-assets.1 |     at Function.Module._resolveFilename (module.js:440:15)
11:23:55 rails-static-client-assets.1 |     at Function.Module._load (module.js:388:25)
11:23:55 rails-static-client-assets.1 |     at Module.require (module.js:468:17)
11:23:55 rails-static-client-assets.1 |     at require (internal/module.js:20:19)
11:23:55 rails-static-client-assets.1 |     at Object.<anonymous> (/home/vagrant/dev/www/vpos/backend/client/node_modules/webpack-obfuscator/index.js:2:74)
11:23:55 rails-static-client-assets.1 |     at Module._compile (module.js:541:32)
11:23:55 rails-static-client-assets.1 |     at Object.Module._extensions..js (module.js:550:10)
11:23:55 rails-static-client-assets.1 |     at Module.load (module.js:458:32)
11:23:55 rails-static-client-assets.1 |     at tryModuleLoad (module.js:417:12)
11:23:55 rails-static-client-assets.1 |     at Function.Module._load (module.js:409:3)

The referenced line obviously requires webpack-sources and so it should be added as a dependency I guess.

The only thing unclear to me is, why it was working at all for the person in my team who added webpack-obfuscator to our project? And I'm also a bit puzzled because I ran dev env and the plugin should only have loaded in production.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.