Strong pattern — the blast-radius discipline is the part most deploy scripts skip. From an attacker's-eye view, though: a secret in the query string is a secret that lands in plaintext in access logs, proxy logs, and any downstream Referer header, so a token-gated self-modifier living at the web root is one log leak away from being an RCE primitive for whoever reads those logs. Two cheap defenses in depth — move the token to a request header or POST body so it stays out of logs, and stamp each worker with a hard expiry so a forgotten one disarms itself even if the self-delete never fires. An .htaccess IP-allowlist alongside the token is worth the one line too: needle-exactness protects the file, but it doesn't decide who gets to pull the trigger.
Deploying PHP in a Bomb Suit: Token-Gated One-Shot Workers on $3 Shared Hosting
12 Comments
Please log in to add a comment.
The backups are the part I'd move first. If .bak-<worker-id>.bak sits next to the file it copied in public_html, the server doesn't hand it to PHP. It serves it as a plain file, so anyone who requests that name gets the source of whatever you patched, including database credentials if a worker ever touches a config file. The leading dot doesn't hide it either, because Apache's stock rule only blocks names starting with .ht. OWASP's testing guide has a section on old and backup files for this reason, and ZAP ships a scanner rule that guesses backup names.
On cPanel your home directory sits one level above public_html and PHP can usually write there, so I'd point the backups at something like ~/deploy-backups/ instead. If your host won't allow that, a FilesMatch block in .htaccess that denies \.bak$ does the same job. Then add one line to your verify step: curl the backup's URL and expect a 403 or 404, the same way you already check the served page instead of the disk.
@[Mike Dabydeen] You called it. This morning your "verify by request" framing got stress-tested for real: a spot check of the webroot found 40 of 40 sampled backup files answering HTTP 200 - and the .htaccess guard I shipped after your last review had silently vanished from the file entirely. 1,402 files, all readable, protection absent, and no way to know when it went.
Everything from your comment is now live: a vault outside the docroot (all 1,402 moved, nothing deleted), a manifest of every path, a weekly cron that requests each dropping over HTTP and treats a 200 as a failure, and the worker template now writes paths to the manifest and curls them before it reports OK. Wrote the whole thing up - your name is in the intro: https://bryanhamilton.info/writing/1402-backup-files-verify-by-request-not-by-layout/
@[bryanhamiltondev] The line I'd act on in your write-up is "no way to know when it went," and a canary file closes that gap cheaply. Put one file named canary.bak in public_html with a known string inside, and have a cron request it every hour. A 403 or 404 means the guard is still there. A 200 that returns your string means it's gone, and you find out within the hour instead of at the next spot check.
The weekly sweep finds droppings, while the canary watches the guard itself. I'd also have the same cron store a hash of .htaccess and log when it changes, so if a host update rewrites the file again you get the time it happened, not just the result. Thanks for the credit in the intro.
Please log in to add a comment.
Please log in to comment on this post.
More Posts
- © 2026 Coder Legion
- Feedback / Bug
- Privacy
- About Us
- Contacts
- You Tube
- Tiktok
- Premium Subscription
- Terms of Service
- Early Builders
More From bryanhamiltondevverified
Related Jobs
- Senior PHP Engineer (Symfony) — Checkout & APIsNFQ · Full time · New York, NY
- Drupal Developer (PHP)IT Contracting by Pentacomp · Full time · New York, NY
- Backend Engineer (PHP/Symfony)Logintrade S.A. · Full time · New York, NY
Commenters (This Week)
Contribute meaningful comments to climb the leaderboard and earn badges!