aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorW. Kosior <koszko@koszko.org>2026-07-23 13:50:46 +0200
committerW. Kosior <koszko@koszko.org>2026-07-23 13:50:46 +0200
commitf6919c603417b0e64f1c355f207f9b38a7a6e574 (patch)
treefe15110f404d44bfec426dad32c784067dc8232e
parent718e626d6f490c1c0dd0e34f83bf47492965f379 (diff)
downloadsimple-browser-extension-magister.tar.gz
simple-browser-extension-magister.zip
Add a fix for the Varnish PoW bot blocker.HEADmagister
-rw-r--r--GNUmakefile1
-rw-r--r--content/varnish-pow-bot-blocker.js45
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;
+ });
+}
+
+})();