From 36ec141278318814e2eea54459488570abbc149e Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 11:06:08 -0700 Subject: [PATCH 1/5] Name a Cache Lifetime on Every Response Ahead of an Edge Proxy A proxy that caches by file extension sits in front of neither site today, and nothing in the bundle says how long a copy may live, so a browser guesses from Last-Modified and an edge would apply its own defaults. Every blog response now carries a Cache-Control: pages and feeds revalidate on every use, the fingerprinted assets are immutable, and media is bounded to an hour so a replaced image propagates without a purge. Both error pages answer no-cache whatever path they stand in for, and the family pages state the same. The log review keeps the last element of ClientHost, since a proxied request carries the forwarded chain there and a client may prepend any value. The operations doc names the edge as a tier above Traefik and what it hides. Verified on the local staging mirror: the live check passes, and each class serves the header the deploy README's table states. --- OPERATIONS.md | 4 +++- checks/log-review.jq | 2 ++ deploy/Caddyfile | 13 +++++++++++++ deploy/README.md | 18 ++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/OPERATIONS.md b/OPERATIONS.md index d911a64..183a7e8 100644 --- a/OPERATIONS.md +++ b/OPERATIONS.md @@ -290,6 +290,8 @@ A request crosses the proxy before it reaches the site, so no single log answers **The one routerless https `404` that is not a routing fault is the edge restarting.** It arrives on a hostname the proxy does serve, in a minute that also carries `502`s. The host side restarts the edge nightly and when it pushes a change during the day, and its documentation holds that schedule. The routes return within a minute. Such a window is an intentional update blip, so leave it alone. Investigate only a window that does not look like one, such as one that outlasts a restart or recurs with no `502` beside it. +**A hostname Cloudflare proxies adds a tier above Traefik, and that tier keeps no record you can read.** The free plan shows aggregates and a sample, never a line per request. A request its rules block or its cache answers therefore reaches no tier below. The edge never caches HTML, XML, JSON, or text by default, so every real-content `404` still reaches Traefik. A file type it does cache is answered from the edge for as long as the bundle's `Cache-Control` allows, which [`deploy/README.md`](./deploy/README.md#cache-lifetimes) sets. A count for `/media/` is then a floor, and a first sighting is still logged, which is all the inward pass needs. `ClientHost` on a proxied request is the forwarded chain rather than one address. A client may send a chain of its own, and the edge appends the address it saw. [`checks/log-review.jq`](./checks/log-review.jq) keeps the last element for that reason, and the `403` cross-check below does the same. + Two properties of the Caddy side are worth knowing before parsing it. Its access log is `format console`, so each line is a timestamp, a level, and a logger name followed by a JSON object rather than being JSON itself, and a parser that assumes one object per line reads nothing. And `trusted_proxies` is what makes `client_ip` the reader rather than the proxy, which is the same setting "Serving" describes as a security boundary. Without it every request in the log appears to come from one internal address, and the inward pass cannot distinguish a reader from a health check. ### Reading a 404 list without being fooled by it @@ -362,7 +364,7 @@ set -euo pipefail since="$(( ($(date -u +%s) - $(date -u -d "$start" +%s)) / 3600 + 1 ))h" jq -r 'select(.DownstreamStatus == 403) | select(.RequestHost == "blog.insanegenius.com" or .RequestHost == "viljoen.family") - | .ClientHost' window.jsonl | sort -u > blocked.txt + | .ClientHost | split(",") | last | ltrimstr(" ")' window.jsonl | sort -u > blocked.txt ssh "$VPS_SSH_HOST" "docker exec crowdsec cscli alerts list --since $since -l 0 -o raw" | cut -d, -f3 | sort -u > alerted.txt ssh "$VPS_SSH_HOST" 'docker exec crowdsec cscli decisions list -a -l 0 -o raw' | diff --git a/checks/log-review.jq b/checks/log-review.jq index e64ce8f..ca41971 100644 --- a/checks/log-review.jq +++ b/checks/log-review.jq @@ -19,3 +19,5 @@ select(.["request_X-Blog-Check"] == null) | select(.RequestHost == $blog or .RequestHost == $family) | select(.DownstreamStatus == 404) | select(scanner | not) +# Behind a proxy ClientHost is the forwarded chain, and its last element is the address the edge saw. +| .ClientHost |= (if . == null then . else (split(",") | last // "" | ltrimstr(" ")) end) diff --git a/deploy/Caddyfile b/deploy/Caddyfile index 3734410..8dfcae8 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -130,6 +130,14 @@ redir @mapped {mapped} 301 redir @mapped_slash {mapped_slash} 301 + # Explicit lifetimes replace whatever heuristic a browser or an edge cache would apply, so a deploy shows at once. + # An hour bounds how long a replaced image is still served from any copy. + header Cache-Control "no-cache" + @fingerprinted path /assets/* + header @fingerprinted Cache-Control "public, max-age=31536000, immutable" + @media path /media/* /*.png /*.ico + header @media Cache-Control "public, max-age=3600" + # The proxy forwards Accept-Encoding unchanged and adds no compression of its own. # Serving the precompressed siblings here is what reaches the client. file_server { @@ -138,6 +146,8 @@ } handle_errors { + # A missing file in a cached class would otherwise keep that class's lifetime. + header Cache-Control "no-cache" rewrite * /404.html file_server } @@ -168,6 +178,8 @@ http://viljoen.family:8080, http://viljoen.vps.insanegenius.net:8080 {$FAMILY_SI header @svg Cache-Control "public, max-age=604800" @code path *.css *.js header @code Cache-Control "no-cache" + @page not path *.svg *.css *.js + header @page Cache-Control "no-cache" # The root follows the browser's first language, and /en/ and /af/ never redirect, so the language switch always holds. @af_first { @@ -186,6 +198,7 @@ http://viljoen.family:8080, http://viljoen.vps.insanegenius.net:8080 {$FAMILY_SI # A single-page site has nowhere better to send a stray path than the page itself. handle_errors { + header Cache-Control "no-cache" @af_page path /af/* handle @af_page { rewrite * /af/index.html diff --git a/deploy/README.md b/deploy/README.md index d0c2e35..82ee834 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -271,6 +271,24 @@ variable would hold both at the stricter value. Set both to `noindex, nofollow` container, since neither falls back to the other. No check reads `X-Robots-Tag`, so a missing value shows only in the served header. +## Cache lifetimes + +Every blog response names its own lifetime, so a browser and an edge cache behave the same with or +without a caching proxy in front. Without one a browser guesses from `Last-Modified`, and an edge +cache applies a default by file extension. Neither guess is bounded by anything this repository +controls. + +| Class | `Cache-Control` | Why | +| --- | --- | --- | +| Pages, feeds, the sitemap, `index.json`, `robots.txt`, and every other path | `no-cache` | A copy may be kept but is revalidated on every use, so a deploy shows at once | +| `/assets/`, the fingerprinted stylesheet and script | `public, max-age=31536000, immutable` | The name changes with the content, so a copy is never stale | +| `/media/` and the root icons | `public, max-age=3600` | An image rarely changes, and an hour bounds how long a replaced one is still served from any copy | + +A `404` answers with `no-cache` whatever its path, since a missing file in a cached class would +otherwise keep that class's lifetime. The redirects name no lifetime, so a browser and an edge keep +their defaults for a `301`. The family site keeps its own, shorter list in its block, and its error +page answers `no-cache` the same way. + ## Trusting the proxy A proxy fronts Caddy in every environment, so the peer address is always the proxy and the real From eb3d03234b5af286d6e7950714a6cf3b5f36195d Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 11:13:21 -0700 Subject: [PATCH 2/5] Scope the Lifetime Claims and Name Cloudflare Where the Edge Is Meant The first strict review pass found the deploy README claiming a lifetime on every blog response while the redirects carry none, the operations doc and the jq comment using the edge for Cloudflare where that section means Traefik, the forwarded-chain claim missing the trust condition it depends on, and null guards on a field Traefik always writes. --- OPERATIONS.md | 2 +- checks/log-review.jq | 4 ++-- deploy/README.md | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/OPERATIONS.md b/OPERATIONS.md index 183a7e8..28b8b9a 100644 --- a/OPERATIONS.md +++ b/OPERATIONS.md @@ -290,7 +290,7 @@ A request crosses the proxy before it reaches the site, so no single log answers **The one routerless https `404` that is not a routing fault is the edge restarting.** It arrives on a hostname the proxy does serve, in a minute that also carries `502`s. The host side restarts the edge nightly and when it pushes a change during the day, and its documentation holds that schedule. The routes return within a minute. Such a window is an intentional update blip, so leave it alone. Investigate only a window that does not look like one, such as one that outlasts a restart or recurs with no `502` beside it. -**A hostname Cloudflare proxies adds a tier above Traefik, and that tier keeps no record you can read.** The free plan shows aggregates and a sample, never a line per request. A request its rules block or its cache answers therefore reaches no tier below. The edge never caches HTML, XML, JSON, or text by default, so every real-content `404` still reaches Traefik. A file type it does cache is answered from the edge for as long as the bundle's `Cache-Control` allows, which [`deploy/README.md`](./deploy/README.md#cache-lifetimes) sets. A count for `/media/` is then a floor, and a first sighting is still logged, which is all the inward pass needs. `ClientHost` on a proxied request is the forwarded chain rather than one address. A client may send a chain of its own, and the edge appends the address it saw. [`checks/log-review.jq`](./checks/log-review.jq) keeps the last element for that reason, and the `403` cross-check below does the same. +**A hostname Cloudflare proxies adds a tier above Traefik, and that tier keeps no record you can read.** The free plan shows aggregates and a sample, never a line per request. A request its rules block or its cache answers therefore reaches no tier below. Cloudflare never caches HTML, XML, JSON, or text by default, so every real-content `404` still reaches Traefik. A file type it does cache is answered from Cloudflare for as long as the bundle's `Cache-Control` allows, which [`deploy/README.md`](./deploy/README.md#cache-lifetimes) sets. A count for `/media/` is then a floor, and a first sighting is still logged, which is all the inward pass needs. `ClientHost` on a proxied request is the forwarded chain rather than one address, where Traefik trusts Cloudflare's ranges. Without that trust Traefik strips the header, and the field is Cloudflare's own address, which a pass would read as a reader. That trust is the host side's setting. A client may send a chain of its own, and Cloudflare appends the address it saw. [`checks/log-review.jq`](./checks/log-review.jq) keeps the last element for that reason, and the `403` cross-check below does the same. Two properties of the Caddy side are worth knowing before parsing it. Its access log is `format console`, so each line is a timestamp, a level, and a logger name followed by a JSON object rather than being JSON itself, and a parser that assumes one object per line reads nothing. And `trusted_proxies` is what makes `client_ip` the reader rather than the proxy, which is the same setting "Serving" describes as a security boundary. Without it every request in the log appears to come from one internal address, and the inward pass cannot distinguish a reader from a health check. diff --git a/checks/log-review.jq b/checks/log-review.jq index ca41971..68e1afd 100644 --- a/checks/log-review.jq +++ b/checks/log-review.jq @@ -19,5 +19,5 @@ select(.["request_X-Blog-Check"] == null) | select(.RequestHost == $blog or .RequestHost == $family) | select(.DownstreamStatus == 404) | select(scanner | not) -# Behind a proxy ClientHost is the forwarded chain, and its last element is the address the edge saw. -| .ClientHost |= (if . == null then . else (split(",") | last // "" | ltrimstr(" ")) end) +# Behind a proxy ClientHost is the forwarded chain, and its last element is the address Cloudflare saw. +| .ClientHost |= (split(",") | last | ltrimstr(" ")) diff --git a/deploy/README.md b/deploy/README.md index 82ee834..035dcec 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -273,8 +273,8 @@ No check reads `X-Robots-Tag`, so a missing value shows only in the served heade ## Cache lifetimes -Every blog response names its own lifetime, so a browser and an edge cache behave the same with or -without a caching proxy in front. Without one a browser guesses from `Last-Modified`, and an edge +Every file the blog serves, and its error page, names its own lifetime, so a browser and an edge +cache behave the same with or without a caching proxy in front. Without one a browser guesses from `Last-Modified`, and an edge cache applies a default by file extension. Neither guess is bounded by anything this repository controls. @@ -285,9 +285,10 @@ controls. | `/media/` and the root icons | `public, max-age=3600` | An image rarely changes, and an hour bounds how long a replaced one is still served from any copy | A `404` answers with `no-cache` whatever its path, since a missing file in a cached class would -otherwise keep that class's lifetime. The redirects name no lifetime, so a browser and an edge keep -their defaults for a `301`. The family site keeps its own, shorter list in its block, and its error -page answers `no-cache` the same way. +otherwise keep that class's lifetime. The blog's redirects name no lifetime, since they answer +before the headers are set, so a browser and an edge keep their defaults for a `301`. The family +site keeps its own, shorter list in its block, and its error page answers `no-cache` the same way. +Its language redirects answer `no-cache` too, because the block's default reaches them. ## Trusting the proxy From 1e1d6c4736212bf4c07958a5d69f008850c1548c Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 11:15:39 -0700 Subject: [PATCH 3/5] Shorten Two Cache Lifetime Sentences and Name the Family Matcher The second strict review pass found two sentences over the length rule and a claim that the family block has a default header where the catch-all matcher is what reaches its redirects. --- deploy/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/deploy/README.md b/deploy/README.md index 035dcec..1db6d10 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -273,10 +273,10 @@ No check reads `X-Robots-Tag`, so a missing value shows only in the served heade ## Cache lifetimes -Every file the blog serves, and its error page, names its own lifetime, so a browser and an edge -cache behave the same with or without a caching proxy in front. Without one a browser guesses from `Last-Modified`, and an edge -cache applies a default by file extension. Neither guess is bounded by anything this repository -controls. +Every file the blog serves, and its error page, names its own lifetime. A browser and an edge cache +then behave the same with or without a caching proxy in front. Without a lifetime a browser guesses +from `Last-Modified`, and an edge cache applies a default by file extension. Neither guess is +bounded by anything this repository controls. | Class | `Cache-Control` | Why | | --- | --- | --- | @@ -286,9 +286,9 @@ controls. A `404` answers with `no-cache` whatever its path, since a missing file in a cached class would otherwise keep that class's lifetime. The blog's redirects name no lifetime, since they answer -before the headers are set, so a browser and an edge keep their defaults for a `301`. The family -site keeps its own, shorter list in its block, and its error page answers `no-cache` the same way. -Its language redirects answer `no-cache` too, because the block's default reaches them. +before the headers are set. A browser and an edge keep their defaults for a `301`. The family site +keeps its own, shorter list in its block, and its error page answers `no-cache` the same way. Its +language redirects answer `no-cache` too, because the `@page` matcher reaches them. ## Trusting the proxy From d63d9bb848abe621f17a99afb5f379108fb250f9 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 11:25:02 -0700 Subject: [PATCH 4/5] Run the Baseline Cache Header Ahead of the Redirects Copilot found that the redirect handlers end the route before the baseline no-cache header ran, so a 301 carried no lifetime and a changed map target could outlive a deploy in a cache. The baseline now runs first and the file classes override it. Verified on the local staging mirror: the live check passes, a legacy media redirect and a feed redirect answer no-cache, and the media and error classes keep their headers. --- deploy/Caddyfile | 6 ++++-- deploy/README.md | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/deploy/Caddyfile b/deploy/Caddyfile index 8dfcae8..8f3f11a 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -73,6 +73,10 @@ } route { + # Explicit lifetimes replace whatever heuristic a browser or an edge cache would apply, so a deploy shows at once. + # The baseline runs first so a redirect carries it too, and the file classes below override it. + header Cache-Control "no-cache" + redir @post_id {by_id} 301 # WordPress served every feed under a type suffix too, so dropping it hands the address to the bare feed's rule. @@ -130,9 +134,7 @@ redir @mapped {mapped} 301 redir @mapped_slash {mapped_slash} 301 - # Explicit lifetimes replace whatever heuristic a browser or an edge cache would apply, so a deploy shows at once. # An hour bounds how long a replaced image is still served from any copy. - header Cache-Control "no-cache" @fingerprinted path /assets/* header @fingerprinted Cache-Control "public, max-age=31536000, immutable" @media path /media/* /*.png /*.ico diff --git a/deploy/README.md b/deploy/README.md index 1db6d10..e32d719 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -285,10 +285,11 @@ bounded by anything this repository controls. | `/media/` and the root icons | `public, max-age=3600` | An image rarely changes, and an hour bounds how long a replaced one is still served from any copy | A `404` answers with `no-cache` whatever its path, since a missing file in a cached class would -otherwise keep that class's lifetime. The blog's redirects name no lifetime, since they answer -before the headers are set. A browser and an edge keep their defaults for a `301`. The family site -keeps its own, shorter list in its block, and its error page answers `no-cache` the same way. Its -language redirects answer `no-cache` too, because the `@page` matcher reaches them. +otherwise keep that class's lifetime. The blog's redirects answer `no-cache` too, since the +baseline header runs before them. A map entry a release changes is then followed at the next +request. The family site keeps its own, shorter list in its block, and its error page answers +`no-cache` the same way. Its language redirects answer `no-cache` as well, because the `@page` +matcher reaches them. ## Trusting the proxy From c671bc6e4f025738223d64d1acc8ae82417e445f Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 11:26:20 -0700 Subject: [PATCH 5/5] Place the Media Lifetime Comment Above the Rule It Explains --- deploy/Caddyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/Caddyfile b/deploy/Caddyfile index 8f3f11a..c02835b 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -134,9 +134,9 @@ redir @mapped {mapped} 301 redir @mapped_slash {mapped_slash} 301 - # An hour bounds how long a replaced image is still served from any copy. @fingerprinted path /assets/* header @fingerprinted Cache-Control "public, max-age=31536000, immutable" + # An hour bounds how long a replaced image is still served from any copy. @media path /media/* /*.png /*.ico header @media Cache-Control "public, max-age=3600"