If your app gets hacked, your job in the first hour is to stop the bleeding without destroying the evidence that tells you how they got in. Contain the account or the server they are using, preserve logs before you rebuild, rotate every secret the process could see, fix the specific hole, and restore data from a backup you trust. Panic pushes people to delete the machine immediately. That feels clean and throws away the log lines you needed. This guide is the sequence for a founder or solo developer who is also the on-call engineer: no war room, no retainer, a dashboard and a repository.
You may be looking at a surprise cloud bill, a user report that they see someone else's data, a crypto miner in the process list, or a provider warning that your API key is calling from a country you have never visited. Treat those as the same class of day until you know otherwise. The security alerts directory is where you check whether a known flaw matches what you run. The work below is what you do with the app in front of you.
The first hour, in order
Do these steps in order during the first hour after you discover the problem. Copy logs before you rebuild the server, and close the open path before you spend that hour reading. Each row below has a finish line you can check.
| Step | Goal | Done when |
|---|---|---|
| Contain | Stop further access and further spend | Keys revoked, exposed port closed, or app taken offline |
| Preserve | Keep logs and a record of what you saw | Copies stored outside the affected host |
| Rotate | Retire secrets the app could read | New credentials deployed, old ones rejected |
| Fix | Close the entry point | The path you found no longer works in a test |
| Restore | Serve clean data and a clean build | Backup or rebuild verified, then traffic returns |
Write times down as you go, even in a notes file. If you later need to tell customers what happened, "around lunch" will not be good enough. "Containment at 14:10 UTC, last malicious request at 14:02" will.
You can take the app offline. A status page that says you pulled the site down on purpose beats an app that keeps serving the caller. If one feature is affected, disable that route. If you cannot tell, disable the public entry.
Contain
Revoke tokens and keys you can revoke from a vendor dashboard you still trust: cloud provider, source host, payment processor, email. If the attacker is in the server, adding a firewall rule or stopping the process limits damage while you copy logs. Remove unfamiliar SSH keys and personal access tokens. Check the cloud console for new virtual machines, new access keys, and billing alerts you did not create. Turn those off.
If they used a stolen password, reset it and sign other sessions out. If they used a leaked key from the repository, revocation matters more than a new commit. Storage and rotation details are in how to store API keys and secrets. Do not send the old secret to a chat while you ask for help. Say the variable name and the provider.
Preserve logs
Copy web server logs, application logs, cloud audit logs, and database logs to a bucket the affected server cannot overwrite. Note the instance id, the deploy SHA, and screenshot any unfamiliar process or cron entry before you kill it. Snapshot the disk if you can. Rebuilding first throws away the lines that show how the caller got in.
Rotate
Assume every secret on the affected host or in the leaked repository is known: database password, signing keys, third-party APIs, webhook secrets, CI tokens, and SSH keys. Issue new values, deploy them, and confirm the old values fail. Create the new admin credential before you delete the old one. Change the database password only when the new app config is ready to restart. If sessions might be stolen, invalidate them and tell people to sign in again.
Fix the hole
Find the entry point before you declare victory. Common ones for small apps: a secret in public git history, an open database port, a route that loads any id, an unpatched framework, or an admin panel with the sample password. Fix the path that matches the evidence. The pre-launch checklist is the backlog once the system is stable.
Evidence looks like a route that should have returned 404, a database connection from an unfamiliar IP, a public commit that contains your .env, or a process you did not install. Match that evidence to one fix, then retry the leaked key, the foreign object id, and the sample password. You want those attempts to fail. If you still cannot name the entry point, keep the app restricted and get help with the logs you saved.
Restore
Restore the database from a backup taken before the malicious activity when data was changed or deleted. A read-only incident still needs secret rotation and a note to the people whose rows were readable. If they ran code on the server, deploy a fresh image from a known commit with the new secrets. Confirm one known row and one login, then watch for the rejected key.
After the app is quiet
The first hour stops the active path. The next day covers the class of bug, the note to affected users, and log retention that outlives a single server. Use the list below once the leaked key is dead and the logs are copied off the machine.
- List what data a stranger could have read. Be specific: emails, password hashes, files, invoices. This list is what you use to decide who to notify.
- Check notice duties with a lawyer if customer data left the app. Look while the timeline is still precise.
- Patch the class of bug, not only the one URL. If one route missed an ownership check, test the others. If one key leaked, scan history for its siblings.
- Turn on billing alerts, admin alerts, and log retention that outlives the server.
- Write a half-page retro: how you noticed, what you rotated, what you fixed, what remains. Future you will not remember the order.
If a dependency advisory matches the hole, record the version you left and the version you run now. Reading those notices is covered in how to read a security alert. If an id in the URL exposed user data, add a regression test before the next feature. Tell affected customers what happened, what you changed, and how to reach you. Dates and actions are enough.
A leaked key and a second server
A developer woke up to a bill alert. The cloud account had a virtual machine they did not create, in a region they do not use. The audit log showed an access key created months ago, last used that morning. The key lived in an old .env committed when the repo was public.
They disabled the key, stopped the unfamiliar machine, copied the audit log, and rotated the rest of the account's keys. The same env file had held the database URL, so they redeployed with a new database password and confirmed the old key was denied.
FAQ
Should I take the app offline?
Take it offline when the attacker still has a working path and you cannot close that path in minutes. Keep it up when you have revoked the key, confirmed no further successful calls, and the remaining risk is cleanup. If you are unsure whether they can still authenticate, offline is the conservative choice. Tell users the outage is intentional.
Do I have to notify users?
Notify the people whose data was exposed or whose accounts may be in someone else's hands. Say what was accessible, what you changed, and what you want them to do. Ask a lawyer about regulatory notice with the timeline you wrote down. Reset stolen sessions before you polish the write-up.
What if a bad deploy exposed data?
Use the same sequence when a public bucket or a committed secret exposed data, even with no sign of a stranger using it. Rotate, fix, and keep the logs. The note to users can be calmer. The rotation still happens.
When do I ask for outside help?
Ask when you cannot contain the account, when access survives rotation, when data is encrypted and you need it back, or when a lawyer should handle a large notice. Bring the timeline and the log copies.
What to do next
If this is happening now, revoke the key or close the port you know about, copy logs off the machine, and only then rebuild. If this is a drill on a quiet afternoon, pick one secret and practice rotating it, and confirm you can still find last week's logs after a server restart.
StaySecure monitors the repo for exposed secrets, vulnerable dependencies, and risky changes, and it explains what to fix. Monitoring will not replace the hour you spend if your app gets hacked. It does shorten the chance that this guide is new to you on a weekday morning.