diff options
| -rw-r--r-- | GNUmakefile | 1 | ||||
| -rw-r--r-- | content/varnish-pow-bot-blocker.js | 45 |
2 files changed, 46 insertions, 0 deletions
diff --git a/GNUmakefile b/GNUmakefile index c0198e9..071c7a1 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -38,6 +38,7 @@ CONTENT_SCRIPTS = $(addprefix content/, \ the-chosen-videos.js \ vatican-news-main-page.js \ vatican-news-site.js \ + varnish-pow-bot-blocker.js \ ) manifest.json: manifest.json.in get-code-block.awk $(CONTENT_SCRIPTS) diff --git a/content/varnish-pow-bot-blocker.js b/content/varnish-pow-bot-blocker.js new file mode 100644 index 0000000..a4c129f --- /dev/null +++ b/content/varnish-pow-bot-blocker.js @@ -0,0 +1,45 @@ +/** + * SPDX-License-Identifier: CC0-1.0 + * + * Copyright (C) 2026 Woj. Kosior <koszko@koszko.org> + */ + +/* + #+begin_src manifest-jq + .matches = ["<all_urls>"] + #+end_src +*/ + +if (false) { /* #+begin_src background-js */ + blockJsOnCookie(/^pow_challenge=[0-9]{12}[.]/); +} /* #+end_src */ + +/* + * Solve "Varnish PoW" challenges. These are used in some places under + * *.debian.org and are derived from haphash PoW challenges. We utilize + * `pow-solver.js' for computing the hashes and + * `appended-number-counting-schemes.js' for the counting scheme. + */ + +(() => { + +const target = new URLSearchParams(window.location.search).get('original'); +const match = /(?:^|;)\s*pow_challenge=(\S*)/.exec(document.cookie); +if (target && match && !window.location.href.startsWith("file://")) { + document.documentElement.innerHTML = `\ +<p style="margin: 1em auto; max-width: 600px; text-align: center;"> + Simple extension is trying to solve a Varnish PoW challenge on this page⦠+</p> +`; + + const challenge = match[1]; + /* A fixed length of 8 zero bits is required by this challenge. */ + genericSolvePow(challenge + ';', 8, appendedNumberCountingSchemes) + .then(({suffixArray}) => { + const nonce = new TextDecoder().decode(suffixArray); + document.cookie = `pow_nonce=${nonce}; Path=/`; + window.location.href = target; + }); +} + +})(); |
