Skip to content

Commit

Permalink
fix: ensure dots in content script patterns aren't used as wildcards (#…
Browse files Browse the repository at this point in the history
…17594)

* fix: ensure dots in content script patterns aren't used as wildcards

* chore: santize all regex chars

* chore: extract to helper

* chore: fixup helper
  • Loading branch information
MarshallOfSound committed Mar 28, 2019
1 parent 9e12e8c commit d5bb0e9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/renderer/content-scripts-injector.js
Expand Up @@ -3,11 +3,15 @@
const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
const { runInThisContext } = require('vm')

const escapePattern = function (pattern) {
return pattern.replace(/[\\^$+?.()|[\]{}]/g, '\\$&')
}

// Check whether pattern matches.
// https://developer.chrome.com/extensions/match_patterns
const matchesPattern = function (pattern) {
if (pattern === '<all_urls>') return true
const regexp = new RegExp(`^${pattern.replace(/\*/g, '.*')}$`)
const regexp = new RegExp(`^${pattern.split('*').map(escapePattern).join('.*')}$`)
const url = `${location.protocol}//${location.host}${location.pathname}`
return url.match(regexp)
}
Expand Down

0 comments on commit d5bb0e9

Please sign in to comment.