From 24f8ba729b180fb420995b8c6b592f23b3e5a552 Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Fri, 25 Apr 2025 14:39:38 -0400 Subject: feat: add support for a base prefix (#294) * fix: rename variable for preventing collision in ED25519 private key handling Signed-off-by: Jason Cameron * fix: remove unused import and debug print in xess.go Signed-off-by: Jason Cameron * feat: introduce base path configuration for Anubis endpoints Closes: #231 Signed-off-by: Jason Cameron * hack(internal/test): skip these tests for now Signed-off-by: Xe Iaso * fix(yeet): unbreak package builds Signed-off-by: Xe Iaso --------- Signed-off-by: Jason Cameron Signed-off-by: Xe Iaso Co-authored-by: Xe Iaso --- web/index.templ | 84 +++++++++++++++++++++++++++++++++------------------- web/index_templ.go | 87 +++++++++++++++++++++++++++++------------------------- web/js/main.mjs | 19 ++++++------ 3 files changed, 110 insertions(+), 80 deletions(-) (limited to 'web') diff --git a/web/index.templ b/web/index.templ index 4fdb4fc..872c8b1 100644 --- a/web/index.templ +++ b/web/index.templ @@ -10,16 +10,56 @@ templ base(title string, body templ.Component, challenge any, ogTags map[string] { title } - + for key, value := range ogTags { } + @templ.JSONScript("anubis_version", anubis.Version) if challenge != nil { @templ.JSONScript("anubis_challenge", challenge) } + @templ.JSONScript("anubis_base_prefix", anubis.BasePrefix)
@@ -44,20 +84,10 @@ templ base(title string, body templ.Component, challenge any, ogTags map[string] templ index() {
- Loading...

- +
Why am I seeing this?

You are seeing this because the administrator of this website has set up Anubis to protect the server against the scourge of AI companies aggressively scraping websites. This can and does cause downtime for the websites, which makes their resources inaccessible for everyone.

Anubis is a compromise. Anubis uses a Proof-of-Work scheme in the vein of Hashcash, a proposed proof-of-work scheme for reducing email spam. The idea is that at individual scales the additional load is ignorable, but at mass scraper levels it adds up and makes scraping much more expensive.

Ultimately, this is a hack whose real purpose is to give a \"good enough\" placeholder solution so that more time can be spent on fingerprinting and identifying headless browsers (EG: via how they do font rendering) so that the challenge proof of work page doesn't need to be presented to users that are much more likely to be legitimate.

Please note that Anubis requires the use of modern JavaScript features that plugins like JShelter will disable. Please disable JShelter or other such plugins for this domain.

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "\">
Why am I seeing this?

You are seeing this because the administrator of this website has set up Anubis to protect the server against the scourge of AI companies aggressively scraping websites. This can and does cause downtime for the websites, which makes their resources inaccessible for everyone.

Anubis is a compromise. Anubis uses a Proof-of-Work scheme in the vein of Hashcash, a proposed proof-of-work scheme for reducing email spam. The idea is that at individual scales the additional load is ignorable, but at mass scraper levels it adds up and makes scraping much more expensive.

Ultimately, this is a hack whose real purpose is to give a \"good enough\" placeholder solution so that more time can be spent on fingerprinting and identifying headless browsers (EG: via how they do font rendering) so that the challenge proof of work page doesn't need to be presented to users that are much more likely to be legitimate.

Please note that Anubis requires the use of modern JavaScript features that plugins like JShelter will disable. Please disable JShelter or other such plugins for this domain.

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -226,38 +232,38 @@ func errorPage(message string, mail string) templ.Component { templ_7745c5c3_Var11 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "
\"Sad\"Sad

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\">

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var13 string templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(message) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `index.templ`, Line: 114, Col: 14} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `index.templ`, Line: 141, Col: 14} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, ".

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, ".

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if mail != "" { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "

Go home or if you believe you should not be blocked, please contact the webmaster at Go home or if you believe you should not be blocked, please contact the webmaster at ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var15 string templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(mail) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `index.templ`, Line: 120, Col: 11} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `index.templ`, Line: 147, Col: 11} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "

Go home

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "

Go home

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -318,7 +324,7 @@ func StaticHappy() templ.Component { templ_7745c5c3_Var16 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "

This is just a check endpoint for your reverse proxy to use.

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "\">

This is just a check endpoint for your reverse proxy to use.

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -361,34 +367,33 @@ func bench() templ.Component { templ_7745c5c3_Var18 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "
TimeIters
Time AIters ATime BIters B
TimeIters
Time AIters ATime BIters B

Loading...

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\">
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/web/js/main.mjs b/web/js/main.mjs index 9bb6031..c50ed2b 100644 --- a/web/js/main.mjs +++ b/web/js/main.mjs @@ -14,8 +14,8 @@ const u = (url = "", params = {}) => { return result.toString(); }; -const imageURL = (mood, cacheBuster) => - u(`/.within.website/x/cmd/anubis/static/img/${mood}.webp`, { cacheBuster }); +const imageURL = (mood, cacheBuster, basePrefix) => + u(`${basePrefix}/.within.website/x/cmd/anubis/static/img/${mood}.webp`, { cacheBuster }); const dependencies = [ { @@ -81,6 +81,7 @@ function showContinueBar(hash, nonce, t0, t1) { const title = document.getElementById('title'); const progress = document.getElementById('progress'); const anubisVersion = JSON.parse(document.getElementById('anubis_version').textContent); + const basePrefix = JSON.parse(document.getElementById('anubis_base_prefix').textContent); const details = document.querySelector('details'); let userReadDetails = false; @@ -103,7 +104,7 @@ function showContinueBar(hash, nonce, t0, t1) { ohNoes({ titleMsg: "Your context is not secure!", statusMsg: `Try connecting over HTTPS or let the admin know to set up HTTPS. For more information, see MDN.`, - imageSrc: imageURL("reject", anubisVersion), + imageSrc: imageURL("reject", anubisVersion, basePrefix), }); return; } @@ -128,7 +129,7 @@ function showContinueBar(hash, nonce, t0, t1) { ohNoes({ titleMsg: `Missing feature ${name}`, statusMsg: msg, - imageSrc: imageURL("reject", anubisVersion), + imageSrc: imageURL("reject", anubisVersion, basePrefix), }); } } @@ -140,7 +141,7 @@ function showContinueBar(hash, nonce, t0, t1) { ohNoes({ titleMsg: "Challenge error!", statusMsg: `Failed to resolve check algorithm. You may want to reload the page.`, - imageSrc: imageURL("reject", anubisVersion), + imageSrc: imageURL("reject", anubisVersion, basePrefix), }); return; } @@ -198,7 +199,7 @@ function showContinueBar(hash, nonce, t0, t1) { title.innerHTML = "Success!"; status.innerHTML = `Done! Took ${t1 - t0}ms, ${nonce} iterations`; - image.src = imageURL("happy", anubisVersion); + image.src = imageURL("happy", anubisVersion, basePrefix); progress.style.display = "none"; if (userReadDetails) { @@ -223,7 +224,7 @@ function showContinueBar(hash, nonce, t0, t1) { function onDetailsExpand() { const redir = window.location.href; window.location.replace( - u("/.within.website/x/cmd/anubis/api/pass-challenge", { + u(`${basePrefix}/.within.website/x/cmd/anubis/api/pass-challenge`, { response: hash, nonce, redir, @@ -239,7 +240,7 @@ function showContinueBar(hash, nonce, t0, t1) { setTimeout(() => { const redir = window.location.href; window.location.replace( - u("/.within.website/x/cmd/anubis/api/pass-challenge", { + u(`${basePrefix}/.within.website/x/cmd/anubis/api/pass-challenge`, { response: hash, nonce, redir, @@ -253,7 +254,7 @@ function showContinueBar(hash, nonce, t0, t1) { ohNoes({ titleMsg: "Calculation error!", statusMsg: `Failed to calculate challenge: ${err.message}`, - imageSrc: imageURL("reject", anubisVersion), + imageSrc: imageURL("reject", anubisVersion, basePrefix), }); } })(); \ No newline at end of file -- cgit v1.2.3