Skip to content

Commit

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

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

* chore: sanitise all regexp special chars

* chore: extract to helper

* chore: fixup helper
  • Loading branch information
MarshallOfSound authored and kiku-jw committed May 16, 2019
1 parent 931ac9d commit 14772dd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/renderer/content-scripts-injector.ts
Expand Up @@ -21,11 +21,15 @@ const getIsolatedWorldIdForInstance = () => {
return isolatedWorldIds++
}

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

// Check whether pattern matches.
// https://developer.chrome.com/extensions/match_patterns
const matchesPattern = function (pattern: string) {
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 14772dd

Please sign in to comment.