Can You Get Hacked Just by Visiting a Site?
Yes, it is possible, but it is uncommon: a web page can attack a device, usually only when the browser is out of date, a brand-new bug is being abused, or the visitor clicks, downloads or types something.
This post is for two people. The first is a worried visitor who just opened a strange link. The second is a site owner who wants to be sure their own site is not harming customers. You will get a plain explanation of how these attacks work, a short list of what to do if you already clicked, and a checklist for owners.
The short answer: what can and cannot happen
When you open a page, your browser runs the page's code. Most of that code is JavaScript (a programming language that makes pages interactive). Browsers run it inside a sandbox, which is a locked room that stops page code from touching your files or the rest of your computer.
So simply loading a normal page does not give an attacker control of your device. The risk appears when something breaks out of that locked room, or when you are tricked into opening the door yourself. Both happen, but the second one is far more common.
The main ways a page can attack you
| Attack | What happens | Does it need you to act? | What protects you |
|---|---|---|---|
| Drive-by download | A page quietly exploits a flaw in your browser or an extension to install malware | Usually no | Updated browser and operating system |
| Fake prompt | A pop-up says your browser is out of date, your PC has a virus, or you must verify you are human | Yes, you must click, install or paste something | Knowing the tricks below |
| Malicious script on a real site | Injected code steals what you type, such as card numbers at checkout | You just use the site normally | Owner's defenses (see the owner section) |
| Silent redirect | A hacked site sends you to a scam or phishing page | Often no, but the next step needs you | Check the address bar before typing anything |
| Notification spam | You click Allow and the site pushes scam alerts to your screen | Yes, one click | Block notifications |
Drive-by downloads
A drive-by download means malware is installed just because you visited a page. It needs a security hole in your browser, an extension, or your operating system. Browser makers fix these holes quickly, so keeping everything updated is your best defense. CISA, the US cybersecurity agency, explains this in its guide to updating software.
The scariest version is a zero-day, a flaw nobody has patched yet. These exist, but they are valuable and mostly used against specific targets, not random visitors.
Fake prompts and social engineering
Most real-world harm comes from tricking the person, not breaking the browser. Watch for these:
- A full-screen warning that says your device is infected and you must call a number or install a cleaner.
- A fake browser or video-player update that downloads a file for you to run.
- A fake CAPTCHA that asks you to press keys like Win+R or open a terminal and paste a command. A real CAPTCHA never asks for that. If you paste and run it, you have given an attacker control.
- A page that asks you to Allow notifications to prove you are not a robot.
CISA's page on recognizing and reporting phishing covers the same habits in more detail.
Malicious scripts on real sites
Sometimes the page is a normal shop or blog that was hacked. Attackers add a few lines of JavaScript that copy card details typed into the checkout form, or that redirect visitors. The visitor did nothing wrong. This is why owners carry real responsibility. The underlying problem is often cross-site scripting (XSS), where a site lets an attacker's code run on its pages. OWASP explains it here: Cross Site Scripting.
Can websites get hacked, and does that put visitors at risk?
Yes. Any site can get hacked, including small ones. Attackers often use automated tools to find outdated WordPress plugins, weak admin passwords or exposed login pages, then plant code that targets visitors. Small sites are not too small to matter, because a hijacked site is a free place to host malware.
If you own a site and suspect this, see our page on what to do if your website was hacked. If you want to understand your own exposure, read is my website hackable.
If you already clicked: what to do
Stay calm. Match your situation to the steps below.
If you only opened the page and did nothing else:
- Close the tab or the whole browser.
- Update your browser and operating system.
- Run a full scan with built-in protection (Microsoft Defender on Windows, or your Mac's built-in protections plus any reputable scanner you already trust).
If you downloaded a file but did not open it: delete it and empty the trash. Do not open it to see what it is.
If you opened or ran a downloaded file, or pasted a command:
- Disconnect the device from Wi-Fi or unplug the network cable.
- From a different, clean device, change the passwords for your email first, then your bank and other important accounts. Turn on two-factor authentication (a second code or app prompt when you log in).
- Changing passwords alone may not be enough, because malware often steals logged-in sessions as well. After you change your passwords, sign out of all sessions or devices in your email and other key accounts.
- Run a full antivirus scan. If it finds something it cannot clean, or you are not sure, back up your documents and reinstall the operating system. This is the safest fix.
- Watch bank and card statements, and call your bank if anything looks wrong.
If you typed a password or card number into the page: change that password right away, and contact your bank about the card.
If you clicked Allow on notifications: in Chrome go to Settings, Privacy and security, Site settings, Notifications, and remove the site. Other browsers have a similar setting.
If you installed a browser extension: open chrome://extensions (or the extensions page in your browser) and remove anything you do not recognize.
How to lower your risk as a visitor
- Turn on automatic updates for your browser and operating system.
- Never install software because a web page told you to.
- Never paste a command into a terminal or Run box because a web page told you to.
- Check the address bar before you enter a password. A padlock only means the connection is encrypted, not that the site is honest.
- Keep your browser's built-in safe browsing protection turned on.
Owners: make sure your site does not hurt visitors
Your visitors trust you. Here is a checklist you can work through in an afternoon.
1. Check whether Google flags your site
Open the Security issues report in Google Search Console, and look your domain up in the Google Safe Browsing site status tool. If either shows a warning, treat it as a real incident.
2. Update and prune
Update your CMS (the system that runs your site, like WordPress), themes and plugins. Delete any plugin or theme you do not use. Outdated plugins are a common way in.
3. Lock down admin access
- Use long, unique admin passwords and turn on two-factor authentication.
- Review your user list for admin accounts you do not recognize.
- Remove old staff and freelancer accounts.
4. Look at your third-party scripts
Every analytics, chat or ad script you load runs with full power on your page. List them all, and remove the ones you do not need. For scripts you keep loading from another server, use Subresource Integrity (SRI), which makes the browser refuse the file if it changes:
<script src="https://cdn.example.com/lib.js"
integrity="sha384-BASE64HASH"
crossorigin="anonymous"></script>
You can generate the hash with:
openssl dgst -sha384 -binary lib.js | openssl base64 -A
SRI only works for files that never change, so it suits pinned library versions, not vendor scripts that update themselves.
5. Add a Content Security Policy
A Content Security Policy (CSP) is a header that tells the browser which sources of script it may trust. Even if an attacker injects code, a good policy can stop it from running or from sending data out. Start in report-only mode so you do not break your site. This example allows Stripe's checkout scripts, frames and API calls, and sends violation reports to an endpoint at /csp-report that you would need to create:
Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self' https://js.stripe.com; frame-src https://js.stripe.com https://hooks.stripe.com; connect-src 'self' https://api.stripe.com; report-uri /csp-report
Adjust the sources to match what your site really loads. Open your browser's DevTools console (the Console tab) to see what the policy would have blocked, or point report-uri (or the newer report-to) at an endpoint to collect violations. Fix what you see, then switch to Content-Security-Policy when it is clean. One note: the frame-ancestors directive, which controls who may embed your pages in a frame, only takes effect in the enforced Content-Security-Policy header. Browsers ignore it in report-only mode. The MDN guide to CSP explains each directive. You can check which security headers your site sends with our free security headers tool.
6. Look for signs of injected code
On a WordPress server with shell access, this finds a classic pattern of hidden code:
grep -rIl "eval(base64_decode" wp-content/
A hit is not proof of a hack, since some legitimate plugins use odd code, but every hit deserves a look. Also view the page source of your homepage and checkout page and search for scripts loading from domains you do not recognize.
7. Keep backups and a way to recover
Keep a recent backup stored away from the server. If something goes wrong, a clean restore beats guessing.
Where a human audit fits
Automated checks catch known patterns. They can miss a flaw that only shows up when someone tries to abuse your login, forms or checkout the way an attacker would. Our free website security check is a passive look from the outside. A paid audit is manual testing by a person. For the difference, see manual vs automated penetration testing.
Key takeaways
- A page can attack your device, but usually only through an unpatched browser, a rare zero-day or a trick that gets you to click, install or paste.
- Keep your browser and operating system updated, and never run software or commands because a web page says so.
- If you already clicked, close the page and scan. If you ran a file or command, disconnect, change passwords from a clean device, sign out of all sessions and consider reinstalling.
- Owners should update plugins, lock down admin accounts, audit third-party scripts and add a Content Security Policy.
- Check Google Search Console and Safe Browsing for warnings, since a hacked site can harm visitors without you noticing.
Next step
If you want a person to test your site by hand, a Bug Circuit audit is $49 one-time on the Essential plan. You get a full written report with every issue, its severity, evidence and fix steps. Fixing is separate and quoted per issue. It is a focused small-site audit, not a compliance certificate or a multi-week enterprise test.
A real human security engineer audits your whole site by hand and sends a full report: every issue, its severity, and the exact fix. From $49, with a 14-day money-back guarantee.