I run a handful of small web tools for my own homelab that nobody but me ever opens (an internal dashboard, a couple of admin panels, the kind of thing you build in an evening and then stop thinking about). One of them had been quietly broken for several days before I even noticed, because when the only user is you, nothing complains until you go looking for it.
The container was still running. The problem was underneath it: the directory on the host that got bind-mounted in as the app's source had somehow been reduced to empty folders. The actual application code, the file that did everything, was just gone.
No git, no backup, no second copy
This is where the story stops being about the crash and starts being about everything I'd normalized leading up to it. This particular tool had never been put in a git repository, because it was "just for me." It had never been added to the backup job's scope either, for the same reason. Both of those decisions felt reasonable one at a time. Stacked together, they meant there was exactly one copy of the source code in existence, and it had just vanished.
The only thing standing between me and rewriting the whole thing from memory was Docker itself. The running container's image still had every layer that had ever gone into building it, cached locally, completely independent of whatever happened to the bind mount on top. A quick look at the build history, and pulling the files back out of an older cached layer, got me a complete, if several months stale, copy of the application back.
# See every layer that built the current image, newest first
docker history --no-trunc my-internal-tool:latest
# Pull a file straight out of a specific layer without starting a container
docker create --name recover-tmp my-internal-tool:latest
docker cp recover-tmp:/app/app.py ./recovered-app.py
docker rm recover-tmp
Relief first. Then, reading back through the recovered file before putting it into service, a much less comfortable feeling.
What was actually in there
Three things, each individually a well-known mistake, sitting together in one small file I'd apparently stopped looking at closely a long time ago:
- A long-lived API token, hardcoded directly into client-side JavaScript on the admin page. Not a server-side secret, but something sent to the browser on every page load, visible to anyone who opened dev tools.
- A command-execution endpoint with no authentication check at all. It existed to let me run a couple of maintenance commands from the UI instead of SSHing in. It had no gate on it whatsoever.
- An auth check on the admin page that failed open. It looked for one specific header, the kind a reverse proxy adds once it has verified who you are, and if that header simply wasn't present on a request, the code's fallback was to treat the request as the admin user. Not deny. Assume it's me.
Each of these is bad on its own. Combined, "assume it's me when the header's missing" sitting in front of an unauthenticated command-exec endpoint is close to "anyone who can reach this port is me." The header-based check wasn't really authentication at all. It was a convenience that happened to work as long as every single request came through the one proxy I had in mind when I wrote it.
The fix, and the parts that were harder than expected
Before putting the recovered code back into service, I rotated the embedded token and redacted it from the source, flipped the auth default from allow-unless-proven-otherwise to deny-unless-proven-otherwise, and added that same explicit check to the exec endpoint. The pattern looks roughly like this (genericized, not the real code):
# Before: fails open if the header is missing
def is_admin(request):
role = request.headers.get("X-Auth-Role")
if role is None:
return True # "it's probably the proxy, probably fine"
return role == "admin"
# After: fails closed by default
def is_admin(request):
role = request.headers.get("X-Auth-Role")
if role is None:
return False # no header means no, full stop
return role == "admin"
The part that took longer than fixing the code: finding every other place that same token had ended up. There was more than one stale backup copy of this tool's source sitting around from earlier "just in case" moments, and every one of them had the same hardcoded token baked in. Rotating the token in one place and assuming you got them all is exactly the kind of assumption that started this whole mess.
The transferable part
None of this is specific to the one tool. Three lessons generalize to anything you run on your own network:
1. Deleting a secret from your source doesn't delete it from history that's already baked
A Docker image layer, a git commit, a backup tarball: once a secret is captured in any of these, it survives every later "fix" to the live source unless you specifically go back and scrub that history too. The only reliable fix for an exposed secret is rotating it, not editing the file it's currently sitting in.
2. A header-based auth shortcut is only as safe as the guarantee that the header is always present
If you can imagine any path where your reverse proxy isn't in front of a request (local testing, a misconfigured route, a future refactor, someone hitting the container's port directly), then failing open on that header isn't a convenience, it's a standing vulnerability with your name already signed to it.
3. Your most exposed service is the one you stopped thinking about
Every "just for me, nobody will ever find this" internal tool is still a listening port on your network. It deserves the same baseline as anything customer-facing: auth that fails closed, no secrets rendered into client-side code, and a real place where it's tracked and backed up, because "I'll remember" is not a recovery plan, and it's definitely not a security review.
A short list to run against your own setup tonight
- List every container or exposed port you can't immediately explain the auth model for.
- Grep your own repos and images specifically for token-shaped strings in anything that ships to the browser. Server-side secrets are one problem, but client-rendered ones are handed to every visitor.
- For anything that gates on a header or cookie set by something upstream, ask what it does when that header is missing. If the answer is "lets them in," that's the bug, not an edge case.
- Confirm every internal tool you run is either in version control or inside your backup job's scope. If it's neither, it's one bad day away from being unrecoverable.
The zero-trust instincts most of us already apply to anything facing the internet need to apply, with the same rigor, to the stuff that's "just for us." Nobody else was ever going to ask whether it was safe. That was always the job.