javascript-obfuscator / webpack-obfuscator

javascript-obfuscator plugin for Webpack
https://github.com/javascript-obfuscator/javascript-obfuscator
BSD 2-Clause "Simplified" License
856 stars 84 forks source link

Filename hash will be affected #108

Closed sxzz closed 3 years ago

sxzz commented 3 years ago

When the following options are enabled, contenthash will be affected and failed to load chunks. (Webpack 5)

const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const WebpackObfuscator = require("webpack-obfuscator");

module.exports = {
  mode: "production",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].js",
    // chunkFilename: "[name].[chunkhash:8].js", // ✅
    chunkFilename: "[name].[contenthash:8].js", // ❌
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin(),
    new WebpackObfuscator(
      {
        splitStrings: true,
        splitStringsChunkLength: 5,

        stringArray: true,
        stringArrayEncoding: ["rc4"],
        stringArrayIndexShift: true,
        stringArrayWrappersCount: 5,
        stringArrayWrappersChainedCalls: true,
        stringArrayWrappersParametersMaxCount: 5,
        stringArrayWrappersType: "function",
        stringArrayThreshold: 1,
      },
      []
    ),
  ],
};

Reproduce repo: https://github.com/sxzz/webpack-obfuscator-test

sanex3339 commented 3 years ago

All stages here: https://github.com/webpack/webpack/blob/a16909c5fdb9efe9f1dd20226a1e7fc216160d1a/lib/Compilation.js#L3462-L3467

Content hash works when obfuscator runs after PROCESS_ASSETS_STAGE_OPTIMIZE_HASH stage. So, I think I have to use the latest stage PROCESS_ASSETS_STAGE_REPORT.

sanex3339 commented 3 years ago

Released as 3.3.0. Please try it.

sxzz commented 3 years ago

Already fixed! Thanks.

sanex3339 commented 3 years ago

Nice!

sanex3339 commented 3 years ago

I don't know if this change could produce any side-effects, so please let me know if you found any problems