Can a link to a real website still be dangerous?

The short answer

Yes. Cross-site scripting, or XSS, slips an attacker's code into a real, trusted site, so your browser runs it as if the site wrote it, even with the padlock showing.

Animated diagram: Can a link to a real website still be dangerous?

XSS

Cross-site scripting, or XSS, is an attack that slips someone else’s code into a real, trusted website. Your browser then runs that code as if the site wrote it. It starts with a simple habit. Many sites paste text you type back into the page, like a search term or a comment. If the site never cleans that text, code can land where words should be.

The padlock in the address bar doesn’t stop this. It comes from TLS (Transport Layer Security), which encrypts the connection and proves the page arrived unchanged from the real site. That proof is exactly why XSS works. The injected code really did come from the real site, so the browser trusts it like every other line on the page. The fix has to come from the website itself, through defenses such as output encoding, sanitization and CSP (Content Security Policy).

What XSS actually does

The attacker’s code reaches you in one of two ways. In reflected XSS, it rides inside a crafted link to the real site, such as one sent in an email. In stored XSS, it’s saved in something like a comment, and the site shows it to everyone who opens the page. Either way, the page drops the text into its HTML without encoding it, for example through innerHTML. Your browser can’t tell it apart from the site’s own code, so it runs it.

The textbook example, from MDN Web Docs, is a link to my-bank.example.com that hides a broken image: an image tag with src=x and an onerror handler. The image fails to load, the onerror handler fires, and the script runs. If it shows an alert, the popup reads ‘my-bank.example.com says’, because the real site’s page ran it. From there the script acts as you. It can read your emails, send requests in your name, and steal your session cookie unless the site set HttpOnly.

How a website protects against XSS

  1. Encode text before showing it. Output encoding turns what a user typed into plain text. The browser then displays it instead of running it.
  2. Sanitize what users submit. Sanitization cleans input such as comments before the site stores it or shows it to others.
  3. Use safe ways to insert text. Safe APIs add text to the page as words rather than as HTML. CSP and Trusted Types add extra layers on top.
  4. Mark session cookies HttpOnly. With the HttpOnly flag set, an injected script can’t read the cookie. It still runs, though, and it can still act through your live session.

All of these sit in the website’s code. Chrome’s old built-in filter, the XSS Auditor, was removed in Chrome 78 in 2019. So don’t count on your browser or antivirus to catch it.

XSS is not a fake website

Many people think a dangerous link always leads to a lookalike site. With XSS, the address is real, the padlock is real, and the page really came from the bank or email provider. A padlock only proves you reached the real site and the page wasn’t changed on the way. It says nothing about whether the site’s own code is clean.

What to do

  • Open your bank and email from a bookmark or by typing the address yourself. Don’t use links in messages, even when the link shows the real address.
  • Keep your browser updated as general good practice. Open the menu, then Help, then About Google Chrome, and click Relaunch if it appears. Your tabs reopen, except Incognito ones. This does not fix a site’s XSS bug.
  • If you build websites, encode user text before it goes into the page and set HttpOnly on session cookies.
  • Treat the padlock as proof of the address, not proof that the page’s code is clean.

#XSS#CrossSiteScripting#WebSecurity#OWASP#AppSec#CyberSecurity#InfoSec#OnlineSafety

Watch it in 60 seconds