diff --git a/src/js/auto.js b/src/js/auto.js index e15a8eb..48bbed7 100644 --- a/src/js/auto.js +++ b/src/js/auto.js @@ -40,6 +40,15 @@ if (!window._basedflareAuto) { }); }; + clearCookiesForDomains = (domain) => { + const parts = domain.split('.'); + for (let i = 0; i < parts.length - 1; i++) { + const subdomain = parts.slice(i).join('.'); + document.cookie = `_basedflare_pow=; Max-Age=-9999999; Path=/; Domain=.${subdomain}`; + document.cookie = `_basedflare_captcha=; Max-Age=-9999999; Path=/; Domain=.${subdomain}`; + } + }; + messageHandler = (e, json) => { console.log('messageHandler') if (e.data.length === 1) { return; } @@ -57,10 +66,13 @@ if (!window._basedflareAuto) { }), redirect: "manual", }).then((res) => { - if (res.status >= 400) { - this.fails++; - console.error("basedflare post status >= 400", res); + if (res.status >= 400 && res.status < 500) { + clearCookiesForDomain(location.hostname); + console.error("Server rejected your submission."); + } else if (res.status >= 500) { + console.error("Server encountered an error."); } + this.fails++; }).catch((e) => { console.error(e); }).finally(() => { diff --git a/src/js/challenge.js b/src/js/challenge.js index 1c1492e..21720a2 100644 --- a/src/js/challenge.js +++ b/src/js/challenge.js @@ -76,6 +76,15 @@ const wasmSupported = (() => { // } // }; +function clearCookiesForDomains(domain) { + const parts = domain.split('.'); + for (let i = 0; i < parts.length - 1; i++) { + const subdomain = parts.slice(i).join('.'); + document.cookie = `_basedflare_pow=; Max-Age=-9999999; Path=/; Domain=.${subdomain}`; + document.cookie = `_basedflare_captcha=; Max-Age=-9999999; Path=/; Domain=.${subdomain}`; + } +} + function postResponse(powResponse, captchaResponse) { const body = { "pow_response": powResponse, @@ -94,6 +103,7 @@ function postResponse(powResponse, captchaResponse) { }).then((res) => { const s = res.status; if (s >= 400 && s < 500) { + clearCookiesForDomain(location.hostname); return insertError(__("Server rejected your submission.")); } else if (s >= 500) { return insertError(__("Server encountered an error."));