summaryrefslogtreecommitdiff
path: root/app/router.go
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-07-15 03:17:09 -0500
committerChristian Cleberg <[email protected]>2026-07-15 03:17:09 -0500
commit83d9cd0b7a3e0ec6beb5c889102211567a6db03f (patch)
tree59926c27df295ba506d6f08a901274dd6d7c300c /app/router.go
parent8d08f343c930f556c6ab016be9d00b23f1e516e3 (diff)
downloadskunky-art-83d9cd0b7a3e0ec6beb5c889102211567a6db03f.tar.gz
skunky-art-83d9cd0b7a3e0ec6beb5c889102211567a6db03f.tar.bz2
skunky-art-83d9cd0b7a3e0ec6beb5c889102211567a6db03f.zip
fix: serve media again by unsetting download-proxy and scoping Host per request
Two independent faults made every image fail while pages still rendered. config.example.json shipped download-proxy=http://127.0.0.1:8080. Only media fetches go through that proxy — pages reach DeviantArt via devianter on the default transport — so when nothing listens there, images 502 and the rest of the page looks fine. In a scratch container 127.0.0.1 is the container itself, so the default could never work under Docker. Unset it and document that it must stay empty unless an operator really runs a proxy. Host was a package global reassigned by every request, so a concurrent request could overwrite it mid-render and emit URLs on another origin's host and port. The instance's own default-src 'self' CSP then blocked those images. Thread the request's host through skunkyart instead, and take it as an explicit argument in URLBuilder, ParseMedia, ParseDescription, BuildUserPlate and ConvertDeviantArtURLToSkunkyArt. Feeds keep their absolute URLs. Also start RefreshInstances after ExecuteConfig rather than before it: the goroutine read CFG while json.Unmarshal was writing it (a race the detector flags), and its fetch escaped both the throttle and the configured User-Agent. Verified: 300 concurrent requests with distinct Host headers now round-trip their own host (was 1 leak per 300), go test -race is clean, and cache+proxy both enabled serves 200 image/jpeg cold and from cache.
Diffstat (limited to 'app/router.go')
-rwxr-xr-xapp/router.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/app/router.go b/app/router.go
index e29005d..4b68282 100755
--- a/app/router.go
+++ b/app/router.go
@@ -10,10 +10,6 @@ import (
"time"
)
-// Host is the scheme and host that generated links are built from. It is set per
-// request from the Host header and X-Forwarded-Proto.
-var Host string
-
// Router registers the single catch-all handler that dispatches every path, then
// serves until the process exits. It does not return on success.
func Router() {
@@ -68,12 +64,18 @@ func Router() {
// the function that drives everything
handle := func(w http.ResponseWriter, r *http.Request) {
path := parsepath(r.URL.Path)
- Host = "http://" + r.Host
+
+ // Per-request, not a package global: requests arrive concurrently on
+ // different hosts and ports (bots hitting a proxy's alternate ports, for
+ // one), and a shared global lets one request's host leak into another's
+ // rendered URLs. Those URLs then point at a different origin, which this
+ // handler's own default-src 'self' CSP blocks.
+ host := "http://" + r.Host
if h := r.Header["X-Forwarded-Proto"]; len(h) != 0 && h[0] == "https" {
- Host = "https://" + r.Host
+ host = "https://" + r.Host
}
- var skunky = skunkyart{Version: Release.Version}
+ var skunky = skunkyart{Version: Release.Version, Host: host}
skunky._pth = r.URL.Path
skunky.Args = r.URL.Query()