vyyhti

Two launch bugs: a cached language redirect and Cloudflare's email obfuscation

Launching this site behind Cloudflare revealed two bugs local tests missed: a cached language redirect and an email address that turned into a placeholder.

This site is two static folders, /en/ and /fi/, served by Caddy behind Cloudflare. It worked in every local test. Two things broke only once it was live, and both are worth knowing about if you put a site behind a CDN.

Bug 1: the English page you could not reach

The first version served English at / and Finnish at /fi/. To be friendly to Finnish visitors, Caddy redirected / to /fi/ when the browser's first language was Finnish. To keep the language switch working, the redirect was skipped when the request came from the site itself, judged by the Referer header.

From a Finnish browser, clicking EN led straight back to the Finnish page. Two things were wrong at once.

The redirect was cached. HTML responses got Cache-Control: public, max-age=300, and the rule also matched the redirect. So the browser stored "/ means /fi/" for five minutes and never asked the server again. Every click on EN went to /, hit the cached redirect, and landed on /fi/. In a quick test with a fresh browser profile the bug did not appear, because nothing was cached yet.

The fix depended on Referer. Even without caching, privacy-focused browsers trim or drop the Referer header, so "came from the site itself" could not be detected reliably.

The fix was to stop routing the language switch through the redirect at all:

  • English moved to its own folder, /en/. The switch and every internal link point straight at /en/... or /fi/..., and those addresses never redirect.
  • / does only one thing: pick a language for first-time visitors. It is never cached, and it tells caches that the answer depends on the language header.
route / {
	header Cache-Control "no-store"
	header Vary "Accept-Language"
	@finnish header Accept-Language fi*
	redir @finnish /fi/ 302
	redir * /en/ 302
}

After the change I tested it the way it had failed: Finnish, US English and British English browsers each clicking EN, FI, EN, FI, with and without a Referer header. Every click landed on the chosen language.

Bug 2: "[email protected]"

When I added an email address to the contact list, the live page showed [email protected] instead of the address, and the link pointed at a Cloudflare URL.

Cloudflare has a feature called Email Address Obfuscation, which was turned on for the domain. It rewrites every email address in HTML it serves, and adds a small script that decodes the addresses back in the visitor's browser. The idea is that scrapers reading the raw HTML do not see the address.

This site sends a strict Content Security Policy. At the time it was default-src 'none' with no scripts allowed at all, and today it still allows no scripts except the site's own. So the browser blocked Cloudflare's decoder script, and the placeholder stayed on the page. My local copy of the page was fine. Only the version passing through Cloudflare was broken, which is why it looked fine until launch.

The options were to turn the feature off for the whole domain, to allow Cloudflare's script in the CSP, or to exclude just this part of the page. Cloudflare honors two HTML comments for exactly this:

<!--email_off--><li>…<a href="mailto:…">…</a></li><!--/email_off-->

The build now wraps every email row in those markers. The CSP stayed strict and nothing else on the domain changed.

What I took from it

  • Test through the CDN, not just the origin. Both bugs only existed in the copy of the site that went through Cloudflare or a browser cache.
  • Redirects get cached too. A redirect that depends on a request header needs Vary for that header, or no-store. Better still, keep the important links from going through it.
  • A strict CSP is a good alarm. It is the reason the obfuscation broke visibly instead of quietly running third-party script on the page.

Contact

Questions about one of these projects, or something else? Message me on Discord or send an email.