Skip to content

Commit

Permalink
fix for ds_store and "refactor"
Browse files Browse the repository at this point in the history
  • Loading branch information
davtur19 committed Aug 18, 2024
1 parent 0cfe7f5 commit 785b40b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 59 deletions.
87 changes: 44 additions & 43 deletions dotgit.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,33 +214,6 @@ async function checkGit(url) {
return false;
}

async function checkDSStore(url) {
const to_check = url + DS_STORE;

try {
const response = await fetchWithTimeout(to_check, {
redirect: "manual",
timeout: 10000
});

if (response.status === 200) {
let text = await response.text();
console.log(response.text());
if (text !== false && text.startsWith(DS_STORE_HEADER[0]) === true) {

setBadge();
notification("Found an exposed .DS_Store", to_check);
return true;
}
}
} catch (error) {
// Timeouts if the request takes longer than X seconds
//console.log(error.name);
}

return false;
}

async function checkSvn(url) {
const to_check = url + SVN_DB_PATH;

Expand Down Expand Up @@ -325,6 +298,33 @@ async function checkEnv(url) {
return false;
}

async function checkDSStore(url) {
const to_check = url + DS_STORE;

try {
const response = await fetchWithTimeout(to_check, {
redirect: "manual",
timeout: 10000
});

if (response.status === 200) {
let text = await response.text();
console.log(response.text());
if (text !== false && text.startsWith(DS_STORE_HEADER[0]) === true) {

setBadge();
notification("Found an exposed .DS_Store", to_check);
return true;
}
}
} catch (error) {
// Timeouts if the request takes longer than X seconds
//console.log(error.name);
}

return false;
}


function startDownload(baseUrl, downloadFinished) {
const downloadedFiles = [];
Expand Down Expand Up @@ -371,7 +371,10 @@ function startDownload(baseUrl, downloadFinished) {

zip.generateAsync({type: "base64"}).then(function (zipData) {
// download zip
chrome.downloads.download({url: `data:application/octet-stream;base64,${zipData}`, filename: `${filename}.zip`});
chrome.downloads.download({
url: `data:application/octet-stream;base64,${zipData}`,
filename: `${filename}.zip`
});
downloadFinished(fileExist, downloadStats);
});
}
Expand Down Expand Up @@ -407,7 +410,7 @@ function startDownload(baseUrl, downloadFinished) {

fetch(baseUrl + GIT_PATH + path, {
redirect: "manual",
headers: { "Accept": "text/html" },
headers: {"Accept": "text/html"},
}).then(function (response) {
downloadStats[response.status] = (typeof downloadStats[response.status] === "undefined") ? 1 : downloadStats[response.status] + 1;
// ignore status code?
Expand Down Expand Up @@ -590,14 +593,14 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
} else if (request.type === "svn") {
check_svn = request.value;
sendResponse({status: true});
} else if (request.type === "ds_store") {
check_ds_store = request.value;
} else if (request.type === "hg") {
} else if (request.type === "hg") {
check_hg = request.value;
sendResponse({status: true});
} else if (request.type === "env") {
check_env = request.value;
sendResponse({status: true});
} else if (request.type === "ds_store") {
check_ds_store = request.value;
} else if (request.type === "notification_new_git") {
notification_new_git = request.value;
sendResponse({status: true});
Expand Down Expand Up @@ -774,17 +777,6 @@ async function precessQueue(visitedSite) {
chrome.storage.local.set(visitedSite);
}
}

if (check_ds_store) {
if (await checkDSStore(url) !== false ) {
if (check_securitytxt && securitytxt === null ) {
securitytxt = await checkSecuritytxt(url);
}
visitedSite.withExposedGit.push({type: "ds_store", url: url, securitytxt: securitytxt});
chrome.storage.local.set(visitedSite);
}
}

if (check_hg) {
if (await checkHg(url) !== false) {
if (check_securitytxt && securitytxt === null) {
Expand All @@ -803,6 +795,15 @@ async function precessQueue(visitedSite) {
chrome.storage.local.set(visitedSite);
}
}
if (check_ds_store) {
if (await checkDSStore(url) !== false) {
if (check_securitytxt && securitytxt === null) {
securitytxt = await checkSecuritytxt(url);
}
visitedSite.withExposedGit.push({type: "ds_store", url: url, securitytxt: securitytxt});
chrome.storage.local.set(visitedSite);
}
}
visitedSite.checked.push(url);
chrome.storage.local.set(visitedSite);
queue_req.dequeue();
Expand Down
16 changes: 8 additions & 8 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
<input type="radio" id="svnOff" name="svn" value="off" checked/>
<label for="svnOff">Off</label>
</div>
<div class="browser-style title-option">
.DS_Store
<input type="radio" id="DS_StoreON" name="ds_store" value="on"/>
<label for="DS_StoreON">On</label>

<input type="radio" id="DS_StoreOFF" name="ds_store" value="off" checked/>
<label for="DS_StoreOFF">Off</label>
</div>
<div class="browser-style title-option">
.hg
<input type="radio" id="hgOn" name="hg" value="on"/>
Expand All @@ -51,6 +43,14 @@
<input type="radio" id="envOff" name="env" value="off" checked/>
<label for="envOff">Off</label>
</div>
<div class="browser-style title-option">
.DS_Store
<input type="radio" id="ds_storeON" name="ds_store" value="on"/>
<label for="ds_storeON">On</label>

<input type="radio" id="ds_storeOFF" name="ds_store" value="off" checked/>
<label for="ds_storeOFF">Off</label>
</div>
</section>
<section class="option">
<div class="browser-style title-option">
Expand Down
10 changes: 10 additions & 0 deletions options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function set_gui(options) {
document.getElementById("hgOff").checked = !options.functions.hg;
document.getElementById("envOn").checked = options.functions.env;
document.getElementById("envOff").checked = !options.functions.env;
document.getElementById("ds_storeOn").checked = options.functions.ds_store;
document.getElementById("ds_storeOff").checked = !options.functions.ds_store;
document.getElementById("max_sites").value = options.max_sites;
document.getElementById("max_connections").value = options.download.max_connections;
document.getElementById("failed_in_a_row").value = options.download.failed_in_a_row;
Expand Down Expand Up @@ -66,6 +68,14 @@ document.addEventListener("DOMContentLoaded", function () {
value: result.options.functions.env
}, function (response) {
});
} else if (e.target.name === "ds_store") {
result.options.functions.ds_store = (e.target.value === "on");
chrome.storage.local.set(result);
chrome.runtime.sendMessage({
type: e.target.name,
value: result.options.functions.ds_store
}, function (response) {
});
} else if (e.target.id === "color") {
result.options.color = e.target.value;
chrome.storage.local.set(result);
Expand Down
16 changes: 8 additions & 8 deletions popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@ function addElements(element, array, callback, downloading, max_sites) {
}
link.setAttribute("href", HREF_PREFIX + callback(array[i].url) + "/.svn/");
}
if (callback(array[i].type) === "ds_store") {
if (callback(array[i].securitytxt) !== "false" && callback(array[i].securitytxt) !== "undefined") {
listItem.appendChild(spanSecuritytxtStatus);
}
link.setAttribute("href", HREF_PREFIX + callback(array[i].url) + "/.DS_Store");
}
if (callback(array[i].type) === "hg") {
if (callback(array[i].securitytxt) !== "false" && callback(array[i].securitytxt) !== "undefined") {
listItem.appendChild(spanSecuritytxtStatus);
Expand All @@ -153,6 +147,12 @@ function addElements(element, array, callback, downloading, max_sites) {
}
link.setAttribute("href", HREF_PREFIX + callback(array[i].url) + "/.env");
}
if (callback(array[i].type) === "ds_store") {
if (callback(array[i].securitytxt) !== "false" && callback(array[i].securitytxt) !== "undefined") {
listItem.appendChild(spanSecuritytxtStatus);
}
link.setAttribute("href", HREF_PREFIX + callback(array[i].url) + "/.DS_Store");
}
link.innerText = callback(array[i].url);

spanLink.appendChild(link);
Expand Down Expand Up @@ -235,10 +235,10 @@ document.addEventListener("click", (event) => {
}
});

document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("DOMContentLoaded", function () {
chrome.storage.local.get(["withExposedGit", "downloading", "options"], function (visitedSite) {
if (typeof visitedSite.withExposedGit !== "undefined" && visitedSite.withExposedGit.length !== 0) {
let hostElementFoundTitle= document.getElementById("hostsFoundTitle");
let hostElementFoundTitle = document.getElementById("hostsFoundTitle");
let max_sites = visitedSite.options.max_sites
hostElementFoundTitle.textContent = "Total found: " + visitedSite.withExposedGit.length + " Max shown: " + max_sites;

Expand Down

0 comments on commit 785b40b

Please sign in to comment.