logo
blog
readme
Back to Blog
Back to Blog
Back to Blog

‌

‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌

© 2025 linzhe. All rights reserved.

TODO:编辑

webpack自定义plugin

使用了jsencrypt对数据进行加密,导致再渗透测试中会检测出一个关于yui的漏洞。排查后发现,由于jsencrypt中的一个yahoo.js文件里面有一个 http://developer.yahoo.com/yui/license.html的注释。所以可以通过webpack的插件机制解决,即在打包的时候把这个注释去掉就行了

1、自定义webpack plugin

js
removeYuiPlugin.js
const path = require('path')
class RemoveYuiPlugin {
  apply(compiler) {
    compiler.hooks.compilation.tap('RemoveYuiPlugin', (compilation) => {
      compilation.hooks.buildModule.tap('RemoveYuiPlugin', (module) => {
        if (
          module.resource?.includes('node_modules') &&
          module.resource?.includes('jsencrypt') &&
          module.resource?.includes('yahoo.js')
        ) {
          module.loaders.push({
            loader: path.resolve(__dirname, './remove-yui-comments-loader.js'),
          })
        }
      })
    })
  }
}

module.exports = RemoveYuiPlugin
js
remove-yui-comments-loader.js
module.exports = function (source) {
  // 去掉注释的正则表达式
  const content = source.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '')
  return content
}

2、使用自定义插件

js
webpack.config.js
const RemoveCommentsPlugin = require('./removeCommentsPlugin')
module.exports = {
  // ...其他配置
  plugins: [new RemoveCommentsPlugin()],
}