Hardening Laravel servers on Forge
Site isolation, read-only deploy keys and safer deploy scripts: what we changed on our Forge servers after malware ran in a build.
Nov 15, 2026 · 2 min read
When malware got into one of our repositories, Forge deployed it, and npm run build ran it on the server. It never added a cron job or a systemd service. It didn't need to. While it ran, it could read every .env under /home/forge.
These are the changes that would have limited the damage.
Turn on site isolation
By default every site on a Forge server runs as the forge user. One compromised site can read the files of every other site, including their .env.
With user isolation, each site gets its own Linux user, and other sites can't read its directory. In Forge you choose it when you create the site ("User isolation"). An existing site can't be switched, so create a new isolated site and move the app across.
Use a read-only deploy key per site
If Forge connects to GitHub through its OAuth app, the server can push to your repositories. A server only needs to pull.
Give each site its own deploy key, added to just that repository on GitHub, with write access left off. A compromised server then can't push to anything.
Look at what your deploy script runs
npm ci and npm run build run code from your repository and from every package in your lockfile. If the build only produces static assets, think about building in CI and deploying the output instead, so the server never runs your JavaScript toolchain at all.
At the least:
npm ci --ignore-scripts
npm run build
--ignore-scripts stops install scripts from packages running. Some packages with native modules need them, so test it first.
Catch it before it deploys
Everything above limits the damage once malware is on the server. It is better to find it while it is still only in the repository.
Lockhound's malware check reads the files this kind of attack hides in (VS Code tasks, build configs such as vite.config.js, entry files near the root, font files and batch scripts) on every scan of the default branch, and puts a warning at the top of the repository's page. On a pull request, a file that looks like malware fails the Lockhound check, so it can be stopped before it merges.
It is a narrow check, not an antivirus: it reads a small set of files and looks for known patterns. For how this kind of malware hides in a repository, see PolinRider is still spreading.
Rebuild, don't clean
If malware ran on a server, don't try to clean it. Make a new server, deploy fresh, and rotate every secret the old one held. That means database passwords, APP_KEY, mail and payment keys, and any API token in a .env.