Cross-site scripting, commonly referred to as XSS, occurs when hackers execute malicious JavaScript within a victim’s browser.
Unlike Remote Code Execution (RCE) attacks, the code is run within a user’s browser. Upon initial injection, the site typically isn’t fully controlled by the attacker. Instead, the bad actor attaches their malicious code on top of a legitimate website, essentially tricking browsers into executing their malware whenever the site is loaded.
How is JavaScript used in cross-site scripting?
JavaScript is a programming language which runs on web pages inside your browser. This client-side code adds functionality and interactivity to the web page, and is used extensively on all major applications and CMS platforms.
Unlike server-side languages such as PHP, JavaScript code inside your browser cannot impact the website for other visitors. It is sandboxed to your own navigator and can only perform actions within your browser window.
While JavaScript is client side and does not run on the server, it can be used to interact with the server by performing background requests. Attackers can use these background requests to add unwanted spam content to a web page without refreshing it, gather analytics about the client’s browser, or perform actions asynchronously.