Four checks before an app goes live: secrets in git history, limits on scans, ports open to Cloudflare only and SSH by key only.
The short answer
Before an app goes to production, I check four things:
- There are no secrets anywhere in the git history, not just in the current code.
- A flood of requests for files like
/.envcannot take the server down, even when it finds nothing. - Ports 80 and 443 answer Cloudflare only, not anyone who knows the server's address.
- I log in to the server with a key only, and the
rootaccount cannot log in at all.
I describe them using Aelo, the SaaS platform where I am CTO. The checks run there today, and the numbers below come from its incident register and configuration.
Secrets in the whole git history
A file with keys deleted in the next commit still sits in the repository history. So I scan the history, not just the current files. In Aelo the first such scan found a copy of an .env file that had been in the private repository for 40 days. Since then the scan runs in two places:
- before every commit: a hook checks the staged changes and blocks the commit when the tool is missing from the machine, instead of letting it through unscanned;
- in CI on every pull request: a scan of the whole history, with the tool pinned to version 8.30.1 and the checksum of the download verified.
# before a commit: staged changes only
gitleaks git --pre-commit --staged --redact --no-banner
# in CI: the whole history (checkout with fetch-depth: 0, otherwise the scan sees one commit)
gitleaks git . --redact --no-banner
When a secret does leak, rotation alone does not close the case. With some providers a new key does not invalidate the old one until you delete it. I close such an incident only once the leaked key gets a 401 from the provider.
A scan for /.env does not have to steal anything to take a site down
Bots keep asking servers for files with passwords: /.env, /.aws/credentials, editor configs. In Aelo one address sent 705 such requests in two hours. Every one got a 404, but that 404 page weighed 17 KB and queried the database, so the disk could not keep up and a person working on the site got a 502 error.
Since then the defence has three layers: a request limit in Cloudflare, rules in nginx and fail2ban, which bans an address by the pattern of such requests. The nginx rule closes the connection without a response for any path that starts with a dot:
location ~ ^/\.(?!well-known/) {
return 444;
}
The .well-known/ exception is deliberate: Let's Encrypt certificate renewal goes through it.
The second point is the cost of the 404 page itself. This site is generated ahead of time, so a 404 is a ready HTML file with no database queries.
Ports 80 and 443 for Cloudflare only
Cloudflare filters traffic only when the traffic goes through it. If the server also answers directly, anyone who knows its address bypasses every rule and limit set in Cloudflare.
In Aelo one script sets up the firewall. It works in this order:
- It reads the Cloudflare address ranges from the nginx configuration. There is one list, with no copies that could drift apart.
- It compares them with the current list Cloudflare publishes and with the nginx file on the server. If the test fails, it leaves the firewall alone.
- It first opens ports 80 and 443 for every Cloudflare range and only then closes them to everyone else. The site never stops answering, not even for a moment.
The BlueCode server got its firewall from the same script before launch: ports 80 and 443 are open to the 22 Cloudflare ranges only.
SSH by key only, root switched off
A password can be guessed; a key, in practice, cannot. So I switch off three things in SSH:
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
The script that prepares the server refuses to apply these settings while the admin account has no key installed yet. Without that guard it is easy to lock yourself out of your own server.
A list to copy
| Check | Command | Passing result |
|---|---|---|
| Secrets in history | gitleaks git . --redact | no findings, exit code 0 |
| Dot paths | curl -s -o /dev/null -w '%{http_code}' https://your-domain/.env | any code except 200 |
| Ports bypassing Cloudflare | nmap -Pn -p 22,80,443 <server address> from a network outside Cloudflare | only 22 open |
| SSH | sudo sshd -T | permitrootlogin no and passwordauthentication no |
None of these checks makes a system airtight. Each one closes one specific way apps go down or leak in the first weeks after launch.
