使用了jsencrypt
对数据进行加密,导致再渗透测试中会检测出一个关于yui
的漏洞。排查后发现,由于jsencrypt
中的一个yahoo.js
文件里面有一个
http://developer.yahoo.com/yui/license.html
的注释。所以可以通过webpack的插件机制解决
,即在打包的时候把这个注释去掉就行了
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
module.exports = function (source) {
// 去掉注释的正则表达式
const content = source.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '')
return content
}
const RemoveCommentsPlugin = require('./removeCommentsPlugin')
module.exports = {
// ...其他配置
plugins: [new RemoveCommentsPlugin()],
}