summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorSharlatan Hellseher <sharlatanus@gmail.com>2025-09-09 22:18:05 +0100
committerSharlatan Hellseher <sharlatanus@gmail.com>2026-09-01 23:35:37 +0100
commit294d3c1155b3a1c78251c0a4fbf42efde01573cf (patch)
tree03871f1e6a0af2d2dca81f002afd4b39d3755f7a /gnu
parent59df9802c61d29d0ebe83f2b7b3d9c80f8ece58f (diff)
gnu: Add anubis-ai-firewall.
* gnu/packages/web.scm (anubis-ai-firewall): New variable. * gnu/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch: New file. * gnu/local.mk (dist_patch_DATA): Register patches. Relates-to: guix/guix!2572
Diffstat (limited to 'gnu')
-rw-r--r--gnu/local.mk1
-rw-r--r--gnu/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch60
-rw-r--r--gnu/packages/web.scm110
3 files changed, 171 insertions, 0 deletions
diff --git a/gnu/local.mk b/gnu/local.mk
index 175028eba06..2728cbc2e87 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1014,6 +1014,7 @@ dist_patch_DATA = \
1014 %D%/packages/patches/amd-smi-newer-libdrm.patch \ 1014 %D%/packages/patches/amd-smi-newer-libdrm.patch \
1015 %D%/packages/patches/amd-smi-python.patch \ 1015 %D%/packages/patches/amd-smi-python.patch \
1016 %D%/packages/patches/angband-remove-nonfree-tile-options.patch \ 1016 %D%/packages/patches/angband-remove-nonfree-tile-options.patch \
1017 %D%/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch \
1017 %D%/packages/patches/ibus-anthy-fix-tests.patch \ 1018 %D%/packages/patches/ibus-anthy-fix-tests.patch \
1018 %D%/packages/patches/ibus-table-paths.patch \ 1019 %D%/packages/patches/ibus-table-paths.patch \
1019 %D%/packages/patches/antiword-CVE-2014-8123.patch \ 1020 %D%/packages/patches/antiword-CVE-2014-8123.patch \
diff --git a/gnu/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch b/gnu/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch
new file mode 100644
index 00000000000..c6bbae2f75f
--- /dev/null
+++ b/gnu/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch
@@ -0,0 +1,60 @@
1From c29172faf8b57450317f6d29ac9ff4c5dfe69d77 Mon Sep 17 00:00:00 2001
2From: Sharlatan Hellseher <sharlatanus@gmail.com>
3Date: Tue, 18 Aug 2026 19:26:53 +0100
4Subject: [PATCH] chore: Use the browser-native Web Crypto API.
5
6Use the browser-native Web Crypto API instead of @aws-crypto/sha256-js.
7
8* lib/challenge/preact/js/app.jsx (useEffect): Switch to browser native hasher.
9* web/js/worker/sha256-purejs.mjs (calculateSHA256): Likewise.
10---
11 lib/challenge/preact/js/app.jsx | 7 +++----
12 web/js/worker/sha256-purejs.mjs | 10 ++++------
13 2 files changed, 7 insertions(+), 10 deletions(-)
14
15diff --git a/lib/challenge/preact/js/app.jsx b/lib/challenge/preact/js/app.jsx
16index f1321b8..96352b0 100644
17--- a/lib/challenge/preact/js/app.jsx
18+++ b/lib/challenge/preact/js/app.jsx
19@@ -1,7 +1,6 @@
20 import { render, h, Fragment } from 'preact';
21 import { useState, useEffect } from 'preact/hooks';
22 import { g, j, u, x } from "./xeact.js";
23-import { Sha256 } from '@aws-crypto/sha256-js';
24
25 /** @jsx h */
26 /** @jsxFrag Fragment */
27@@ -24,9 +23,9 @@ const App = () => {
28
29 useEffect(() => {
30 setImageURL(state.pensive_url);
31- const hash = new Sha256('');
32- hash.update(state.challenge);
33- setChallenge(toHexString(hash.digestSync()));
34+ crypto.subtle
35+ .digest("SHA-256", new TextEncoder().encode(state.challenge))
36+ .then((buf) => setChallenge(toHexString(new Uint8Array(buf))));
37 }, [state]);
38
39 useEffect(() => {
40diff --git a/web/js/worker/sha256-purejs.mjs b/web/js/worker/sha256-purejs.mjs
41index 3211b44..08072c6 100644
42--- a/web/js/worker/sha256-purejs.mjs
43+++ b/web/js/worker/sha256-purejs.mjs
44@@ -1,9 +1,7 @@
45-import { Sha256 } from '@aws-crypto/sha256-js';
46-
47-const calculateSHA256 = (text) => {
48- const hash = new Sha256();
49- hash.update(text);
50- return hash.digest();
51+const calculateSHA256 = async (text) => {
52+ return new Uint8Array(
53+ await crypto.subtle.digest("SHA-256",
54+ new TextEncoder().encode(text)));
55 };
56
57 function toHexString(arr) {
58--
592.54.0
60
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index 369c40606b7..0c2c5b335f9 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -142,6 +142,7 @@
142 #:use-module (gnu packages golang-build) 142 #:use-module (gnu packages golang-build)
143 #:use-module (gnu packages golang-check) 143 #:use-module (gnu packages golang-check)
144 #:use-module (gnu packages golang-compression) 144 #:use-module (gnu packages golang-compression)
145 #:use-module (gnu packages golang-crypto)
145 #:use-module (gnu packages golang-web) 146 #:use-module (gnu packages golang-web)
146 #:use-module (gnu packages golang-xyz) 147 #:use-module (gnu packages golang-xyz)
147 #:use-module (gnu packages gperf) 148 #:use-module (gnu packages gperf)
@@ -177,6 +178,7 @@
177 #:use-module (gnu packages nettle) 178 #:use-module (gnu packages nettle)
178 #:use-module (gnu packages networking) 179 #:use-module (gnu packages networking)
179 #:use-module (gnu packages node) 180 #:use-module (gnu packages node)
181 #:use-module (gnu packages node-xyz)
180 #:use-module (gnu packages nss) 182 #:use-module (gnu packages nss)
181 #:use-module (gnu packages nss) 183 #:use-module (gnu packages nss)
182 #:use-module (gnu packages openldap) 184 #:use-module (gnu packages openldap)
@@ -248,6 +250,114 @@
248 #:use-module (ice-9 match) 250 #:use-module (ice-9 match)
249 #:use-module ((srfi srfi-1) #:select (delete-duplicates))) 251 #:use-module ((srfi srfi-1) #:select (delete-duplicates)))
250 252
253(define-public anubis-ai-firewall
254 (package
255 ;; Name clashes with "anubis" in (gnu packages mail).
256 (name "anubis-ai-firewall")
257 (version "1.22.0")
258 (source
259 (origin
260 (method git-fetch)
261 (uri (git-reference
262 (url "https://github.com/TecharoHQ/anubis")
263 (commit (string-append "v" version))))
264 (file-name (git-file-name name version))
265 (patches
266 (search-patches "anubis-use-the-browser-native-web-crypto-api.patch"))
267 (sha256
268 (base32 "1vaj78727ndzsxydhdgwr9w0p9ykg73nkrbbiijh5l7lvabh3ric"))))
269 (build-system go-build-system)
270 (arguments
271 (list
272 ;; TODO: Enable some of them
273 #:tests? #f
274 ;; TODO: some JS work is required as app.js could not be found
275 #:install-source? #f
276 #:embed-files #~(list ".version"
277 ".*\\.tmpl"
278 ".*\\.js"
279 ".*\\.jsx"
280 ".*\\.mjs"
281 ".*\\.sh"
282 ".*\\.css"
283 "nodes"
284 "text"
285 "children")
286 #:import-path "github.com/TecharoHQ/anubis/cmd/anubis"
287 #:unpack-path "github.com/TecharoHQ/anubis"
288 #:phases
289 #~(modify-phases %standard-phases
290 (add-after 'unpack 'patch-usr-bin-env-shebangs
291 (lambda* (#:key unpack-path #:allow-other-keys)
292 (with-directory-excursion (string-append "src/" unpack-path)
293 (substitute* (find-files "." "\\.sh$")
294 (("#!/usr/bin/env bash")
295 (string-append "#!" (which "bash")))))))
296 (add-after 'patch-usr-bin-env-shebangs 'generate-code
297 (lambda* (#:key unpack-path #:allow-other-keys)
298 (with-directory-excursion (string-append "src/" unpack-path)
299 (for-each make-file-writable
300 (find-files "." "(_templ\\.go|_string\\.go)$"))
301 (invoke "templ" "generate")
302 (with-directory-excursion "internal/dnsbl"
303 (invoke "stringer" "-type=DroneBLResponse")))))
304 (add-after 'generate-code 'make-assets
305 (lambda* (#:key inputs unpack-path #:allow-other-keys)
306 (with-directory-excursion (string-append "src/" unpack-path)
307 (substitute* "xess/xess.go"
308 (("if anubis.Version != \"devel\" \\{")
309 "if false {"))
310 ;; Let esbuild resolve 'preact' and 'preact/hooks'.
311 (setenv "NODE_PATH"
312 (string-append (assoc-ref inputs "node-preact")
313 "/lib/node_modules"))
314 (invoke "./web/build.sh")
315 (invoke "./lib/challenge/preact/build.sh")))))))
316 (native-inputs
317 (list brotli
318 esbuild
319 go-github-com-a-h-templ
320 go-github-com-cespare-xxhash-v2
321 go-github-com-facebookgo-flagenv
322 go-github-com-gaissmai-bart
323 go-github-com-golang-jwt-jwt-v5
324 go-github-com-google-cel-go
325 go-github-com-google-uuid
326 go-github-com-grpc-ecosystem-go-grpc-middleware-providers-prometheus
327 go-github-com-grpc-ecosystem-go-grpc-middleware-v2
328 go-github-com-joho-godotenv
329 go-github-com-lum8rjack-go-ja4h
330 go-github-com-nicksnyder-go-i18n-v2
331 go-github-com-prometheus-client-golang
332 go-github-com-redis-go-redis-v9
333 go-github-com-sebest-xff
334 go-github-com-shirou-gopsutil-v4
335 go-github-com-techarohq-thoth-proto
336 go-go-etcd-io-bbolt
337 go-golang-org-x-net
338 go-golang-org-x-text
339 go-google-golang-org-grpc
340 go-gopkg-in-yaml-v3
341 go-k8s-io-apimachinery
342 go-sigs-k8s-io-yaml
343 go-tools
344 gzip
345 node-preact
346 templ
347 zstd))
348 (home-page "https://github.com/TecharoHQ/anubis")
349 (synopsis "Weighs the soul of incoming HTTP requests to stop AI crawlers")
350 (description
351 "Anubis is a Web AI Firewall Utility that weighs the soul of your
352connection using one or more challenges in order to protect upstream resources
353from scraper bots.
354
355This program is designed to help protect the small internet from the endless
356storm of requests that flood in from AI companies. Anubis is as lightweight as
357possible to ensure that everyone can afford to protect the communities closest
358to them.")
359 (license license:expat)))
360
251(define-public qhttp 361(define-public qhttp
252 (package 362 (package
253 (name "qhttp") 363 (name "qhttp")