diff options
| author | Christian Cleberg <[email protected]> | 2026-07-15 11:41:18 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-07-15 11:41:18 -0500 |
| commit | 184ce2c6dcdd047d6888fd243b9189c797f58d38 (patch) | |
| tree | 9ff7cf8d36007a319393c533abf92c3f23b3da5e /compose.example.yaml | |
| parent | 8e8c03891a17798067a8da0a034725bf44ece8d0 (diff) | |
| download | skunky-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 'compose.example.yaml')
0 files changed, 0 insertions, 0 deletions
