Obfuscating Contact Data on a Static Site
Base64 in a data attribute and reversed text flipped back by CSS keep the imprint's email address away from harvesters and from copy and paste.
Reviewed by adrian
on
German law (§ 5 DDG, which replaced § 5 TMG in May 2024) requires an imprint with a real name, a postal address and a working email address.1 That is a legal duty to publish exactly what spam harvesters look for. Here are the two layers I use to protect that data on a static site without making the page useless.
The setup
- Site: a static Astro build, no server-side rendering, no API that could obfuscate on demand.
- Legal minimum: the imprint shows name, address and email.
- Threat model: automated harvesters (static scrapers, regex crawlers, bots that run JavaScript). Not a determined human.
The problem
The HTML goes out as it is, and every address in the source is one regex away. <a href="mailto:[email protected]"> is the easiest catch of all: no JavaScript, no interaction.
Layer 1: Base64 and a script
The real text leaves the source. The element stays empty, and the content travels as Base64 in a data-obf attribute:
<span data-obf="cmVudGxBIG5haXJkQQ=="></span>
A small script decodes it in the browser:
document.querySelectorAll('[data-obf]').forEach((el) => {
el.textContent = atob(el.dataset.obf);
});
For links, data-obf-href carries the whole mailto: URL, so not even the mailto: prefix is in the source:
<a data-obf-href="bWFpbHRvOmhleUBleGFtcGxlLmNvbQ=="></a>
Static scrapers now see only Base64. Copy and paste still hands out the real address, because after the script runs it is in the DOM.
Layer 2: reversed text, flipped back by CSS
The text is stored backwards and turned round again by CSS:
.r {
direction: rtl;
unicode-bidi: bidi-override;
}
With unicode-bidi: bidi-override the browser draws the characters strictly from right to left. The DOM holds rentlA nairdA, the screen shows Adrian Altner, and whoever copies it gets rentlA nairdA.
Both together
data-obf holds the reversed string in Base64, the script writes it into the DOM, CSS shows it the right way round:
<span class="r" data-obf="cmVudGxBIG5haXJkQQ=="></span>
- Static HTML: an empty element with an opaque attribute.
- After the script:
rentlA nairdAin the DOM. - After CSS:
Adrian Altneron the screen. - Copied:
rentlA nairdAin the clipboard.
Generating the reversed strings
Email addresses get placeholders for @ and ., and those run into bidi mirroring. Brackets such as {, }, ( and ) are mirror pairs: in right-to-left text the browser swaps them. To show {at}, the stored string has to contain {ta}:
- Stored
{ta}, characters reversed}at{, mirrored{at}. Correct. - Stored
}ta{, characters reversed{at}, mirrored}at{. Wrong.
{dot} works the same way with {tod}. To show hey{at}adrian-altner{dot}com, the stored string is:
moc{tod}rentla-nairda{ta}yeh
A small Node script builds the values for every field:
const obfuscate = (s) =>
s.split('').reverse().join('').replace(/@/g, '{ta}').replace(/\./g, '{tod}');
The result is Base64-encoded and goes into data-obf.
What it protects and what it doesn't
| Threat | Protected |
|---|---|
| Static HTML scrapers (most spam bots) | yes |
| Regex email harvesters | yes |
| Copy and paste by visitors | yes (reversed text in the clipboard) |
| Headless browsers running JavaScript | partly: reversed text, no plain address |
| Someone reading the decoded DOM | no |
| A human reading the page | no |
The last two cannot be avoided: what a human can read, a patient human can get. The aim is to stop the automated tools that send most of the spam.
Takeaways
- No
mailto:links in the HTML. They are the first thing harvesters look for. - Two cheap layers beat one clever one: Base64 stops static scrapers, reversed text stops copy and paste and many scripted scrapers.
- Bidi mirroring is real. Store bracket placeholders mirrored and test in a real browser, not only with a reverse function.
Based on
-
Obfuscating Contact Data on a Static Site
(
raw/2026/2026-03-23/obfuscating-contact-data-on-a-static-site.md) [post] - § 5 DDG, Allgemeine Informationspflichten [ddg]
Topic
- Static Website A website made of finished HTML files that are built once and then served unchanged. No server code, no database.
- Web Development How this site and others are made and found: static pages, search engines, the IndieWeb and maps in the browser.
Mentioned in
- Security Headers in Caddy A strict Content Security Policy, HSTS and no-referrer in a Caddy site block, checked with Webbkoll, securityheaders.com and the Mozilla Observatory.