A Publish Gate That Caught My Own Infrastructure
A Publish Gate That Caught My Own Infrastructure
The publishing pipeline is boring on purpose. It reads a Markdown file, renders a few variants, POSTs them to two platforms, records the URLs, and moves the file to an archive folder. I wrote it so I would stop doing that by hand.
Then I added one more step before the first POST: a scan of the article text itself. It is about a hundred lines. It has blocked more drafts than any other part of the pipeline, and every single block was correct.
The gate runs before the network call
The rule is simple: nothing leaves the machine until the text has been read for things that should not be public. The check runs inside publish, and it runs for --dry-run too, because a dry run that skips the safety check trains you to trust a green light that means nothing.
Findings come in two severities, and the distinction matters more than the pattern list.
Blocking. Public IPv4 addresses (excluding 10/8, 172.16/12, 192.168/16, loopback, link-local, and the documentation ranges), private key blocks, platform access tokens, the credential files that cloud CLIs keep in a hidden directory under the home folder, email-style key assignments, mainland mobile numbers, and ID card numbers. Any hit stops the run with a non-zero exit code, and no request is sent.
Warning. Server-style absolute paths, certificate and key file references, .env mentions, email addresses, and git remote URLs. These print and continue, because a paragraph explaining nginx -t legitimately contains a path, and a post about encryption legitimately mentions a private key.
The interesting category is neither of those. It is a third list, in configuration: literal values that the scanner treats as permanent blockers once discovered, plus an allowlist for the values that merely look dangerous.
What it caught in the first full sweep
The first time I ran the scan across the whole queue — twenty-one English drafts and ten Chinese rewrites — twelve files failed. None of them contained a key. All of them contained something that only makes sense if you already have access:
- An article about a small API included the real admin endpoint path and the port it listens on. Both were accurate, which is exactly why they mattered.
- An article about a data-driven sidebar quoted internal repository paths for the JSON files behind the links. Four of them, each a small map of the source tree.
- An article about database migrations used a real backup filename, timestamp and all. That filename encodes the naming convention and the backup cadence.
- An article about cache invalidation referenced a server secrets file by its real path on disk.
- An article about pricing modules listed the actual price points, next to a sentence claiming the numbers were placeholders. One of those two statements had to be false.
- A Chinese draft about consolidating notes mentioned what kind of notes had been excluded — personal finances, family details. Whose, it did not say. It did not need to.
- Another mentioned that fulfillment was confirmed by manually checking a transfer screenshot, which tells a reader exactly how to attempt a fake one.
Twelve files, twelve different leaks, and not one of them a secret in the cryptographic sense. They were operational context: paths, ports, filenames, prices, habits.
The leak is rarely a key
That is the lesson I did not expect. Keys are easy to keep out — they live in a file that is never committed, and everyone knows the file. What leaks is the supporting detail: the port number you debug on, the shape of your directory tree, the naming pattern of your backups, the fact that a human confirms payments by looking at an image.
Individually, each of those is useless. Together they describe how a small system actually runs, which is precisely the part a public blog post does not need to disclose to make its point.
So the replacements followed one rule: keep the mechanism, remove the address.
real admin route + private port → /api/admin/records + 3000 internal data.json paths → data/friend-links.json app-2026-11-26T101500.db → app-TIMESTAMP.db /srv/site-api/secrets.conf → ~/.config/app/production.conf CNY 149 / USD 19.99 → CNY 100 / USD 15 Every replacement is a placeholder a reader can substitute. None of them is a fake fact presented as real: the articles say the values are examples, and the numbers are round enough that nobody mistakes them for a price list.
Why an allowlist exists at all
The scanner's most obvious rule — flag public IP addresses — immediately flags the documentation ranges 203.0.113.0/24, 198.51.100.0/24, and 192.0.2.0/24. That is the point of those ranges: they look exactly like production addresses and are guaranteed not to be. Excluding them in code handles the general case.
The specific cases need a list. When a scan flags a value you have deliberately chosen — a placeholder hostname, a sample address, a yourname/your-images repo path — the wrong fix is to silence the rule. The right fix is to record that exact value as allowed, in configuration, with a comment saying why. The rule stays on; one value gets a documented exception.
The other list is the inverse: when the scan finds a real value that has to stay out forever, the value goes into the blocklist. Then it is not "be careful with that hostname" — it is a permanent tripwire that fails the build if it ever reappears in a draft six months from now.
Turn the failure into instructions
A gate that says "line 68: matched public IPv4" is a puzzle. A gate that writes a file saying which line, what matched, the surrounding sentence, and what to write instead is a task.
The pipeline generates that file on every block, ordered by article, and marks it resolved when the next scan comes back clean. The stale-guide problem is real: a fix document that still lists twelve problems after they are fixed is worse than no document, because the next person spends an hour looking for issues that no longer exist.
Keeping the fix list in the repository also means the replacement decisions are reviewable. When the same class of leak shows up in a new draft, the earlier decision is right there, with its reasoning.
The blind spot: everything already published
The scan runs on the queue. The archive is a different folder, and for a long time it was out of scope — those articles had been published, the URLs were live, and re-scanning them felt like auditing a signed contract.
It is not the same problem, but it is not nothing either. Going back through the archive by hand surfaced four classes of issue that the gate would have blocked if it had been running then: a real subdomain, a hosting-provider hostname that contained the account name, a third-party blog link that had no business being there, and a price with a product name attached.
The honest conclusion is that a gate protects the future, not the past. If the archive is worth cleaning, it needs its own pass and its own decision about whether to edit posts that are already indexed — which is a different trade-off from blocking a draft that nobody has seen.
The checklist I would hand to someone else
- Scan before the first request, in dry runs too, and make the failure exit code non-zero.
- Separate "do not send" from "look at this", and keep the warn list short enough that it stays readable.
- Exclude the documentation IP ranges in code; handle deliberate placeholders with a named allowlist, never by disabling the rule.
- Keep a blocklist of real values that must never appear again, with the reason next to each entry.
- Generate a fix document with line numbers and suggested replacements, and reset it when the scan is clean.
- Run the scan on the archive at least once, and decide explicitly what to do with what you find.
The gate has one job and no cleverness: it assumes the author is tired, the draft is nearly finished, and the sentence that explains the architecture is the sentence that gives it away.
Originally published on wuhuajin.com.
原文:https://www.a8q9.cn/en/article/a-publish-gate-that-caught-my-own-infrastructure-7853ea.html