summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-07-15 11:41:18 -0500
committerGitHub <[email protected]>2026-07-15 11:41:18 -0500
commit184ce2c6dcdd047d6888fd243b9189c797f58d38 (patch)
tree9ff7cf8d36007a319393c533abf92c3f23b3da5e /README.md
parent8e8c03891a17798067a8da0a034725bf44ece8d0 (diff)
downloadskunky-art-184ce2c6dcdd047d6888fd243b9189c797f58d38.tar.gz
skunky-art-184ce2c6dcdd047d6888fd243b9189c797f58d38.tar.bz2
skunky-art-184ce2c6dcdd047d6888fd243b9189c797f58d38.zip
fix: reject forged subdomains in the media proxy (#9)
* fix: make memcache concurrency-safe and stamp the version at link time memcache was a crash waiting for traffic. Readers touched tempFS without holding mx, while a per-entry goroutine deleted from it under the lock: a concurrent map read and map write, which the runtime treats as a fatal error that recover cannot catch. The option ships in config.example.json and was the one cache key SETUP.md never documented, so it read like a free win to enable. Put every map and field access behind the mutex, and age the whole map from one janitor instead of a goroutine per cached file, each of which looped forever holding its entry alive. mx is now a plain Mutex: every operation here mutates something, and the old code took an RLock to write. Document the option, and cover it with tests that run the readers, writers and janitor concurrently. Split the disk/origin fetch out of DownloadAndSendMedia while there, so the error path returns instead of falling through to write an empty body after the error page. Release.Version was hardcoded to 1.3.2, so images tagged v1.3.6 reported 1.3.2 from --help and /api/instance, and --help linked to the wrong release. Take it from a main.version string the release workflow links in from the git tag. * fix: reject forged subdomains in the media proxy DownloadAndSendMedia built its upstream URL by concatenation, pasting the subdomain segment of the request path straight into the host position. That segment reaches the handler already percent-decoded, so it can carry "@", "#", "?" and "/" — the characters that end a host. A request for /media/file/[email protected]:8080%2F/f/x.jpg built a URL whose host parsed as 127.0.0.1:8080, with images-wixmp-x demoted to userinfo, letting any caller aim the instance's fetcher at any address it could reach, including services behind the firewall. Validate the label against ^[a-zA-Z0-9-]+$ and refuse anything else with a 400. Rejecting rather than escaping is what closes this: the label is the host, and url.URL passes a host through verbatim, so building the URL structurally is not sufficient on its own. DeviantArt's own media URLs use a hex-and-dash label, and ParseMedia already splits on the first dot, so a legitimate label cannot contain one. Build the URL from url.URL fields as well, which escapes the path, and encode the token argument, which reached the request unescaped. Reported by CodeQL as go/request-forgery (CWE-918).
Diffstat (limited to 'README.md')
-rwxr-xr-xREADME.md3
1 files changed, 3 insertions, 0 deletions
diff --git a/README.md b/README.md
index 9dd9d17..4126803 100755
--- a/README.md
+++ b/README.md
@@ -20,6 +20,9 @@ can also add the `-ldflags "-w -s"` argument (GCCGO has a different name for it
`go build -tags embed -ldflags "-w -s"`
+Such a build reports its version as `dev`. To stamp one in, as the release
+workflow does from the git tag, add `-X main.version=<version>` to the ldflags.
+
## Docker
Prebuilt multi-arch images (`linux/amd64`, `linux/arm64`) are published to GHCR
on every release tag: