From 5c24d4a60523d3cb54144494443cb81943004f20 Mon Sep 17 00:00:00 2001 From: sneak Date: Wed, 14 Oct 2026 17:08:25 +0000 Subject: [PATCH] script/gitea-requests, and the gitea refusals it confirms named in SPEC.md (closes #30) script/gitea-requests runs gitea 1.27.3 behind the image at its defaults, sends through it the requests that reading gitea's source found the Core Rule Set refuses, with a short sample of ordinary use, and prints each request with the rule ids that matched it. make gitea-requests runs it; make check does not. Every case still holds, and each fix would let through what SPEC.md says stays refused, so the notes specific to gitea now name them with how each refusal plays out: file names in query parameters that read as Java, script, PowerShell or SQL, such paths, and an image push that reuses a layer of an image named like a command. Model: opus-5-5 --- Makefile | 8 +- README.md | 13 ++ SPEC.md | 44 +++++- script/gitea-requests | 329 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 388 insertions(+), 6 deletions(-) create mode 100755 script/gitea-requests diff --git a/Makefile b/Makefile index 6f3d484..2439e93 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,12 @@ .PHONY: bootstrap setup test lint fmt fmt-check tidy check docker hooks build \ - run example-app + run example-app gitea-requests # Makefile targets are thin shims; the implementations live in script/ # per the scripts-to-rule-them-all pattern (see the Entrypoints section # of README.md). tidy writes go.mod and go.sum as `go mod tidy` does, # which test checks. build and run are for working on the code by hand; -# example-app checks the image with an app built on it. +# example-app checks the image with an app built on it; gitea-requests +# reports the gitea requests the Core Rule Set refuses at the defaults. bootstrap: @script/bootstrap @@ -45,3 +46,6 @@ run: example-app: @script/example-app + +gitea-requests: + @script/gitea-requests diff --git a/README.md b/README.md index 3d706dc..731aabe 100644 --- a/README.md +++ b/README.md @@ -2374,6 +2374,19 @@ so that they run in minimal containers. the same volume still refuses the banned client; then removes the containers, the volume and both images. It needs network access, for nixpkgs' binary cache, and `script/check` does not run it; `make example-app` does. +- `script/gitea-requests`: builds the image and runs gitea 1.27.3 behind it, + with every setting of `smallwebwaf` at its default but `SWWAF_UPSTREAM_URL`, + which names gitea's container. It sends through it the gitea requests that the + notes specific to gitea in [`SPEC.md`](SPEC.md) name for a file name in a + query parameter, for a path and for a container image push, and a short sample + of gitea's ordinary use: signing in, pages of files and commits, a diff, the + API, a push, clone and fetch over HTTP, and two container image pushes. It + prints a line for each request `smallwebwaf` logged, with what it did with it + and the ids of the Core Rule Set's rules that matched it, then removes the + containers, the network and the images it made, but gitea's own image. It + needs network access, and a docker daemon that pushes to a registry on + `localhost` over plain HTTP, as docker does by default; `script/check` does + not run it, and `make gitea-requests` does. ## TODO diff --git a/SPEC.md b/SPEC.md index c6e8fb3..979d69d 100644 --- a/SPEC.md +++ b/SPEC.md @@ -1477,8 +1477,42 @@ holds any token file. Saving such a rule stores it, but the branch settings page gitea then returns to gets the 403 answer of `smallwebwaf`, so the save looks as if it failed. + - A file name in a query parameter, those the fourth change leaves out + of 930120, 932160 and 932260 included, in which the Core Rule Set's + rules for Java, script, PowerShell and SQL find what they look for: + `runtime` in OpenJDK's + `src/java.base/share/classes/java/lang/Runtime.java` (944110), a Java + class, as in `java.lang.String.md` (944130), `document.write.js` + (941180), `process.env.d.ts` (934100), `__proto__` (934130), the + PowerShell command `Install-Script`, as in `install-script.sh` + (932120), or a database's name, as in PostgreSQL's + `information_schema.sql` (942140). For such a file, the API's list of + its commits (`path`) is refused, and so are the API's call for the + contents of files that names it in its query (`body`), the commit + graph of that file alone (`file`), and the hidden lines of its diff + (`path`), which stay hidden. A visitor whom gitea sends to sign in on + the way to a page of such a file that needs signing in, such as its + edit page, gets the 403 answer of `smallwebwaf` in place of the + sign-in page (`redirect_to`), and can still sign in by opening the + sign-in page itself. - A path: a file name ending in `~`, or an `.xhtml` file whose path holds a space. + - A path that holds what the Core Rule Set takes for a Java class + (944130), as `java.lang.String.md` and + `META-INF/services/org.apache.commons.logging.LogFactory` do, or for + Node.js code (934100), as `process.env.d.ts` does, or that has a + directory named `...` (930100, 930110), such as `.../notes.txt`. The + page of such a file, its raw file, its history, its blame and its edit + page are refused; the directory that holds it lists it, and a clone + carries it. + - A container image push that reuses a layer of an image docker has + pushed to that gitea before, when that image's name, after its owner, + starts with an entry on the list of commands (932260), such as + `owner/python3-app` or `owner/docker-base`. docker asks gitea to take + the layer from that image, naming it in the query parameter `from`, + which 932260 checks. The push fails with the 403 answer of + `smallwebwaf`, and so does each new try, since docker asks in the same + way. - Artifact uploads from `actions/upload-artifact@v3` send the header `Content-Range`, which the Core Rule Set refuses (920450). The action sends two files at a time, does not retry a 403 and sends no further file @@ -1566,10 +1600,12 @@ holds any token file. - Core Rule Set false positives against real apps (a search for code, and any body once `SWWAF_WAF_BODY_LIMIT` is set): a match refuses only that request and bans no one by itself; the request log names the rule, and exclusions by - rule id and path fix it. Further gitea requests the Core Rule Set may refuse - at the defaults, found by reading gitea's source rather than a running gitea, - are collected in https://git.eeqj.de/sneak/smallwebwaf/issues/30 and checked - when milestone 1 runs in front of a real gitea. + rule id and path fix it. `script/gitea-requests` runs gitea behind the image + at the defaults, sends through it the requests the notes specific to gitea + name for a file name in a query parameter, for a path and for a container + image push, and a short sample of gitea's ordinary use, and reports each + request the Core Rule Set refuses, so that those notes can be checked again + when gitea or the Core Rule Set changes version. - Attacks carried in request bodies: not refused by default, since on a code forge bodies are full of code the Core Rule Set takes for attacks. Most of what shows in URLs and headers is still refused, the client that sends an diff --git a/script/gitea-requests b/script/gitea-requests new file mode 100755 index 0000000..cbf9226 --- /dev/null +++ b/script/gitea-requests @@ -0,0 +1,329 @@ +#!/bin/sh +# script/gitea-requests: build the image and run gitea 1.27.3 behind it, +# with every setting of smallwebwaf at its default but SWWAF_UPSTREAM_URL, +# which names gitea's container. Then send through it the gitea requests +# that reading gitea's source found the Core Rule Set refuses, and a short +# sample of gitea's ordinary use: signing in, pages of files and commits, +# a diff, the API, a push, clone and fetch over HTTP, and two container +# image pushes. Last, print each request smallwebwaf logged, with what it +# did with it and the ids of the Core Rule Set's rules that matched it. +# Every request comes from one client, docker's gateway, so more than +# SWWAF_ERROR_BURST_THRESHOLD, 30, refusals in a minute would ban it, and +# the requests after would show as banned. The containers, the network, the images and the files the script makes +# are removed however it ends; gitea's own image stays, as the base images +# of a build do. It needs network access, and a docker daemon that pushes +# to a registry on localhost over plain HTTP, as docker does by default. +# script/check does not run this. +set -eu + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)" +ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)" + +# gitea 1.27.3, 2026-08-29 +GITEA_IMAGE="gitea/gitea@sha256:87a67ee09d3ae0d1df5fda5dcda3e2a1f9236a45b0a59025d6e00e46adc43bef" + +# Named after this run, so that runs in other clones on the same host +# never touch each other's. +NAME="$("$SCRIPT_DIR/projectname")-gitea-$$" +IMAGE="$NAME-image" +NETWORK="$NAME" +SMALLWEBWAF="$NAME-smallwebwaf" +GITEA="$NAME-gitea" + +# gitea's one user, who owns the repository and the container images. +PASSWORD="owner-password" + +BROWSER="Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0" + +# The files the script makes, and smallwebwaf's address once it runs, +# localhost and the port docker publishes it on: a host name, since the +# Core Rule Set takes a Host that is an IP address for a warning (920350). +WORK="" +address="" + +cleanup() { + docker rm --force --volumes "$SMALLWEBWAF" "$GITEA" >/dev/null 2>&1 || true + docker network rm "$NETWORK" >/dev/null 2>&1 || true + docker rmi --force "$IMAGE" >/dev/null 2>&1 || true + if [ -n "$address" ]; then + docker rmi --force "$address/owner/python3-app:1" "$address/owner/app:1" \ + >/dev/null 2>&1 || true + fi + rm -rf "$WORK" +} + +fail() { + echo "gitea-requests: $*" >&2 + report + exit 1 +} + +# wait_for ...: run the command every second until +# it succeeds, for at most a minute. +wait_for() { + failure="$1" + shift + tries=0 + until "$@"; do + tries=$((tries + 1)) + [ "$tries" -lt 60 ] || fail "$failure" + sleep 1 + done +} + +healthy() { + status="$(docker inspect --format '{{.State.Health.Status}}' "$SMALLWEBWAF")" + [ "$status" = healthy ] +} + +# logged ...: a line of smallwebwaf's output holds every text, in +# any order. +logged() { + lines="$(docker logs "$SMALLWEBWAF" 2>&1)" + for text in "$@"; do + lines="$(printf '%s\n' "$lines" | grep -F "$text")" || return 1 + done +} + +# send