From c5f899c5c319ed5fc4d2d9b480df81015c449e55 Mon Sep 17 00:00:00 2001 From: davtur19 Date: Thu, 31 Aug 2023 14:00:35 +0200 Subject: [PATCH] Fixed urls checked twice --- dotgit.js | 76 +++++++++++++++++++++++++++++++-------------------- manifest.json | 2 +- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/dotgit.js b/dotgit.js index a97d20d..36f90cd 100644 --- a/dotgit.js +++ b/dotgit.js @@ -655,7 +655,9 @@ chrome.storage.local.get(["checked", "withExposedGit", "options"], function (res set_options(result.options); - chrome.webRequest.onHeadersReceived.addListener(details => processListener(details), {urls: [""]}); + chrome.webRequest.onHeadersReceived.addListener(async function (details) { + await processListener(details) + }, {urls: [""]}); chrome.webRequest.onErrorOccurred.addListener(details => checkDomtakeover(details, result), {urls: [""]}); }); @@ -666,47 +668,56 @@ chrome.storage.local.set({ }); -function processListener(details) { +async function processListener(details) { if (!(check_git || check_svn || check_hg || check_env)) { return; } let origin = new URL(details["url"])["origin"]; - if (queue_req.isEmpty() === true) { - chrome.storage.local.get(["checked", "withExposedGit"], result => processSearch(result, origin)); - } else { - queue_listener.enqueue(origin); - } + await processSearch(origin); } -function checkUrl(storage, origin) { +function checkUrl(origin, callback) { let hostname = new URL(origin)["hostname"]; if (origin.startsWith("chrome-extension")) { - return false; + callback(false); + return; } - return (storage.checked.includes(origin) === false && checkBlacklist(hostname) === false); + + chrome.storage.local.get(["checked"], function (result) { + if (result.checked && !result.checked.includes(origin) && checkBlacklist(hostname) === false) { + callback(true); + } else { + callback(false); + } + }); } -async function processSearch(storage, origin) { - if (checkUrl(storage, origin)) { - if (queue_running === false) { - queue_running = true; - queue_req.enqueue(origin); - while (queue_listener.isEmpty() === false) { - let origin2 = queue_listener.dequeue(); - if (checkUrl(storage, origin2)) { - queue_req.enqueue(origin2); +async function processSearch(origin) { + //alert('processSearch'); + checkUrl(origin, async function (result) { + if (result) { + if (queue_running === false) { + queue_running = true; + await queue_req.enqueue(origin); + while (queue_listener.isEmpty() === false) { + let origin2 = queue_listener.dequeue(); + checkUrl(origin, async function (result2) { + if (result2) { + await queue_req.enqueue(origin2); + } + }); } + await precessQueue(); + queue_running = false; + } else { + await queue_listener.enqueue(origin); } - await precessQueue(storage); - queue_running = false; - } else { - queue_listener.enqueue(origin); } - } + }); } @@ -716,10 +727,14 @@ function Queue() { console.log(collection); }; this.enqueue = function (element) { - // works for strings not objects - if (collection.indexOf(element) === -1) { - collection.push(element); - } + checkUrl(element, function (result) { + if (result) { + // works for strings not objects + if (collection.indexOf(element) === -1) { + collection.push(element); + } + } + }); }; this.dequeue = function () { return collection.shift(); @@ -733,10 +748,13 @@ function Queue() { this.isEmpty = function () { return (collection.length === 0); }; + this.inQueue = function (element) { + return (collection.indexOf(element) !== -1); + } } -async function precessQueue(visitedSite) { +async function precessQueue() { while (queue_req.isEmpty() !== true) { let url = queue_req.front(); let securitytxt = null; diff --git a/manifest.json b/manifest.json index 70ce285..8c21454 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "DotGit", - "version": "4.7.1", + "version": "4.7.2", "description": "An extension for checking if .git is exposed in visited websites", "icons": { "16": "icons/dotgit-16.png",