From 4a9b1faf3af8ee9746c81e26a4aac22c0f04a1a5 Mon Sep 17 00:00:00 2001 From: davtur19 Date: Fri, 1 Sep 2023 00:21:40 +0200 Subject: [PATCH] Trying to fix the race condition... --- dotgit.js | 118 +++++++++++++++++++++++++++----------------------- manifest.json | 2 +- 2 files changed, 65 insertions(+), 55 deletions(-) diff --git a/dotgit.js b/dotgit.js index a97d20d..1bde4f4 100644 --- a/dotgit.js +++ b/dotgit.js @@ -667,20 +667,18 @@ chrome.storage.local.set({ function processListener(details) { + console.log('processListener'); 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); - } + chrome.storage.local.get(["checked", "withExposedGit"], result => processSearch(result, origin)); } function checkUrl(storage, origin) { + console.log('checkUrl'); let hostname = new URL(origin)["hostname"]; if (origin.startsWith("chrome-extension")) { @@ -691,17 +689,20 @@ function checkUrl(storage, origin) { async function processSearch(storage, origin) { + console.log('processSearch'); if (checkUrl(storage, origin)) { if (queue_running === false) { queue_running = true; + console.log('queue_req.enqueue 1 ' + origin); queue_req.enqueue(origin); while (queue_listener.isEmpty() === false) { let origin2 = queue_listener.dequeue(); if (checkUrl(storage, origin2)) { + console.log('queue_req.enqueue 2 ' + origin2) queue_req.enqueue(origin2); } } - await precessQueue(storage); + await processQueue(); queue_running = false; } else { queue_listener.enqueue(origin); @@ -736,66 +737,75 @@ function Queue() { } -async function precessQueue(visitedSite) { +async function processQueue() { + console.log('processQueue'); + console.log('isEmpty ' + queue_req.isEmpty()); while (queue_req.isEmpty() !== true) { - let url = queue_req.front(); - let securitytxt = null; - let findings = []; - // replace ws and wss with http and https - url = url.replace(WS_SEARCH, WS_REPLACE); - - if (check_git) { - if (await checkGit(url) !== false) { - let open = false; - if (check_opensource) { - open = await isOpenSource(url); - } - if (check_securitytxt) { - securitytxt = await checkSecuritytxt(url); - } + let origin = queue_req.dequeue(); + console.log('origin ' + origin); + await doQueue(origin); + } +} - findings.push({ - type: "git", - url: url, - open: open, - securitytxt: securitytxt - }); +async function doQueue(origin) { + console.log('doQueue'); + let url = origin; + let securitytxt = null; + let findings = []; + // replace ws and wss with http and https + url = url.replace(WS_SEARCH, WS_REPLACE); + + if (check_git) { + if (await checkGit(url) !== false) { + let open = false; + if (check_opensource) { + open = await isOpenSource(url); + } + if (check_securitytxt) { + securitytxt = await checkSecuritytxt(url); } + + findings.push({ + type: "git", + url: url, + open: open, + securitytxt: securitytxt + }); } - if (check_svn) { - if (await checkSvn(url) !== false) { - if (check_securitytxt && securitytxt === null) { - securitytxt = await checkSecuritytxt(url); - } - findings.push({type: "svn", url: url, securitytxt: securitytxt}); + } + if (check_svn) { + if (await checkSvn(url) !== false) { + if (check_securitytxt && securitytxt === null) { + securitytxt = await checkSecuritytxt(url); } + findings.push({type: "svn", url: url, securitytxt: securitytxt}); } - if (check_hg) { - if (await checkHg(url) !== false) { - if (check_securitytxt && securitytxt === null) { - securitytxt = await checkSecuritytxt(url); - } - findings.push({type: "hg", url: url, securitytxt: securitytxt}); + } + if (check_hg) { + if (await checkHg(url) !== false) { + if (check_securitytxt && securitytxt === null) { + securitytxt = await checkSecuritytxt(url); } + findings.push({type: "hg", url: url, securitytxt: securitytxt}); } - if (check_env) { - if (await checkEnv(url) !== false) { - if (check_securitytxt && securitytxt === null) { - securitytxt = await checkSecuritytxt(url); - } - findings.push({type: "env", url: url, securitytxt: securitytxt}); + } + if (check_env) { + if (await checkEnv(url) !== false) { + if (check_securitytxt && securitytxt === null) { + securitytxt = await checkSecuritytxt(url); } + findings.push({type: "env", url: url, securitytxt: securitytxt}); } + } - chrome.storage.local.get(["withExposedGit", "checked"], function (result) { - findings.forEach(function (obj) { - result.withExposedGit.push(obj); - }); - result.checked.push(url); - chrome.storage.local.set(result); + return chrome.storage.local.get(["withExposedGit", "checked"], await function (result) { + console.log('storage' + JSON.stringify(result)); + findings.forEach(function (obj) { + result.withExposedGit.push(obj); }); - queue_req.dequeue(); - } + result.checked.push(url); + return chrome.storage.local.set(result); + }); } diff --git a/manifest.json b/manifest.json index 70ce285..8432c74 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "DotGit", - "version": "4.7.1", + "version": "4.7.3", "description": "An extension for checking if .git is exposed in visited websites", "icons": { "16": "icons/dotgit-16.png",