Skip to content

fix: Potential ReDoS Vulnerability or Inefficient Regular Expression in Project: Need for Assessment and Mitigation #7478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const generateWithPlugin = require('@vue/cli-test-utils/generateWithPlugin')
const HtmlPwaPlugin = require('../lib/HtmlPwaPlugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { performance } = require('perf_hooks')
global.performance = performance

test('inject import statement for service worker', async () => {
const { files } = await generateWithPlugin([
Expand Down Expand Up @@ -38,3 +42,42 @@ test('inject import statement for service worker (with TS)', async () => {

expect(files['src/main.ts']).toMatch(`import './registerServiceWorker'`)
})

test('ReDos test', async () => {
HtmlWebpackPlugin.getHooks = () => ({
beforeEmit: {
tapAsync: (id, handler) => {
const hugeHtml = '<link rel="icon"'.repeat(100000) + '\u0000'
const data = { html: hugeHtml }
handler(data, (_err, result) => {})
}
},
alterAssetTagGroups: {
tapAsync: () => {}
}
})
const plugin = new HtmlPwaPlugin()
const fakeCompiler = {
options: { output: { publicPath: '/' } },
hooks: {
compilation: {
tap: (_id, cb) => {
const fakeCompilation = {
hooks: {
processAssets: {
tap: (_opts, fn) => {}
}
}
}
cb(fakeCompilation)
}
}
}
}
const startTime = performance.now()
plugin.apply(fakeCompiler)
const endTime = performance.now()
const timeTaken = endTime - startTime
console.log(`time taken: ${timeTaken.toFixed(3)} ms`)
expect(timeTaken).toBeLessThan(3000)
}, 3000)
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = class HtmlPwaPlugin {
compiler.hooks.compilation.tap(ID, compilation => {
HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync(ID, (data, cb) => {
// wrap favicon in the base template with IE only comment
data.html = data.html.replace(/<link rel="icon"[^>]+>/, '<!--[if IE]>$&<![endif]-->')
data.html = data.html.replace(/<link rel="icon"(?!<link rel="icon")[^>]+>/, '<!--[if IE]>$&<![endif]-->')
cb(null, data)
})

Expand Down