Skip to content

Commit

Permalink
Trying to fix the race condition...
Browse files Browse the repository at this point in the history
  • Loading branch information
davtur19 committed Aug 31, 2023
1 parent b6d5c67 commit 4a9b1fa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 55 deletions.
118 changes: 64 additions & 54 deletions dotgit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
});
}


Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 4a9b1fa

Please sign in to comment.