diff --git a/.gitignore b/.gitignore index 6036ee477..b71c7c1c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /build/* -/src/drivers/**/apps.json +/src/drivers/**/technologies.json /src/drivers/**/wappalyzer.js /src/drivers/webextension/images/icons/converted/* diff --git a/src/drivers/webextension/js/driver.js b/src/drivers/webextension/js/driver.js index 113863668..1e93aec82 100644 --- a/src/drivers/webextension/js/driver.js +++ b/src/drivers/webextension/js/driver.js @@ -1,6 +1,6 @@ 'use strict' /* eslint-env browser */ -/* globals chrome, Wappalyzer, Utils */ +/* globals chrome, browser, Wappalyzer, Utils */ const { setTechnologies, @@ -57,12 +57,18 @@ const Driver = { chrome.browserAction.setBadgeBackgroundColor({ color: '#6B39BD' }, () => {}) - chrome.webRequest.onCompleted.addListener( - Driver.onWebRequestComplete, + chrome.webRequest.onHeadersReceived.addListener( + Driver.onHeadersReceived, { urls: ['http://*/*', 'https://*/*'], types: ['main_frame'] }, - ['responseHeaders'] + ['responseHeaders', 'blocking'] ) + // chrome.webRequest.onCompleted.addListener( + // Driver.onWebRequestComplete, + // { urls: ['http://*/*', 'https://*/*'], types: ['main_frame'] }, + // ['responseHeaders'] + // ) + chrome.tabs.onRemoved.addListener((id) => (Driver.cache.tabs[id] = null)) // Enable messaging between scripts @@ -184,7 +190,7 @@ const Driver = { * Analyse response headers * @param {Object} request */ - async onWebRequestComplete(request) { + async onHeadersReceived(request) { if (await Driver.isDisabledDomain(request.url)) { return } @@ -208,11 +214,32 @@ const Driver = { ) }) + let certIssuer = '' + + if (browser) { + // Currently only works in Firefox + // See https://stackoverflow.com/a/50484642 + const { certificates } = await browser.webRequest.getSecurityInfo( + request.requestId, + { + certificateChain: true, + rawDER: false, + } + ) + + if (certificates && certificates.length) { + certIssuer = certificates[0].issuer.replace( + /^.*CN=([^,]+).*$/, + '$1' + ) + } + } + if ( headers['content-type'] && /\/x?html/.test(headers['content-type'][0]) ) { - await Driver.onDetect(request.url, analyze({ headers })) + await Driver.onDetect(request.url, analyze({ headers, certIssuer })) } } } catch (error) { diff --git a/src/drivers/webextension/manifest.json b/src/drivers/webextension/manifest.json index 4ed10e271..d9ed82e58 100644 --- a/src/drivers/webextension/manifest.json +++ b/src/drivers/webextension/manifest.json @@ -64,8 +64,9 @@ "tabs", "webRequest", "webNavigation", + "webRequestBlocking", "http://*/*", "https://*/*" ], "content_security_policy": "script-src 'self'; object-src 'self'" -} \ No newline at end of file +}