When looking at the threat landscape of the web, one of the most often underestimated and overlooked vulnerabilities is cross-site scripting.
Cross-site scripting (also known as XSS) attacks are, statistically, one of the most prevalent and damaging web application security risks today. It was the most reported vulnerability at the start of 2023, with vulnerabilities of medium severity (at minimum) increasing exponentially as the year progressed.
These attacks involve malicious client-side scripts being injected into web pages, with an attacker often masquerading as a victim user who can carry out actions that legitimate users can perform. The attackers often circumvent the application and thus compromise the interactions that users have with that application.
While XSS attacks may not always lead directly to a data breach, they are often fundamental parts of a hacker’s reconnaissance efforts, opening the doors for potential additional exploits if not addressed or contained.
These attacks involve injecting malicious client-side scripts into web pages viewed by other users. While XSS attacks may not always lead directly to a data breach, they are often part of a hacker's reconnaissance efforts and can open doors for additional exploits if not addressed. In this article, we will explore what XSS attacks are, the various types, and most importantly, how to prevent them from impacting your organization.
XSS attacks occur when unvalidated, malicious or ‘bad’ scripts and code are entered into a user’s browser. The XSS injection occurs on a credible, legitimate and otherwise trustworthy website with a security vulnerability known to the malicious actor, but not to the website owner.
Many site owners remain unaware of XSS attacks taking place for some time until each user’s browser is slowly and methodically attacked. An example of an XSS injection would see a hacker inputting harmful JavaScript code into a login form which is then displayed unfiltered on a web page. When other users load that page on their browsers, the malicious script can access sensitive data, session cookies, or personal login credentials, or redirect the browser to malicious sites. In essence, XSS vulnerabilities boil down to improper data handling and lax security.
Any web application that allows user input can be vulnerable, which is why it’s crucial to audit websites regularly for vulnerabilities, often consulting third-party penetration testing companies to validate all known security flaws for remediation. Attackers can exploit even the slightest weak spot in a business infrastructure, bypass access controls, exploit users and compromise data if they have the technical know-how.
Want More Tech News? Subscribe to ComputingEdge Newsletter Today!
There are three primary types of cross-site scripting attacks:
Reflected XSS involves injecting a malicious script into a vulnerable HTTP request. If a user visits a URL constructed by the hacker, then the script executes in the user’s browser in the context of that user’s application session, usually in the form of a phishing link disguised in the HTML. The malicious code remains unstored and only impacts an individual session.
Stored XSS (also known as second-order XSS) occurs when an application receives data from an untrusted source, and that data is stored for later HTTP responses.
In other words, malicious scripts are stored on the web application, usually concealed covertly in a database, blog post, forum, or another otherwise native element, with any user visiting or accessing that resource being exploited via their browser. One injection can impact multiple victims over time if that script is allowed to permeate and spread.
DOM XSS exploits vulnerable client-side JavaScript code rather than injecting scripts on the server side. Usually, by writing the data back to the DOM, untrusted data is processed unsafely within an application.
The malicious scripts are executed as part of the client-side JavaScript on loading of the page rather than being permanently stored there. However, the result is the same - malicious code running in the victim's browser.
Although an attack doesn’t inflict direct harm on the website owner, it can have dire consequences for visitors to a compromised site. It can lead to:
Notable examples include the British Airways and T Mobile XSS attacks which resulted in millions of customers’ data being affected.
To understand how dangerous XSS flaws can be, let's look at a hypothetical example:
This is one minor example of how XSS vulnerabilities can exist in otherwise innocent-looking web applications.
The key enabler of XSS attacks is the poor handling of untrusted data in a web application. Unfortunately, many companies fail to recognize or prioritize certain vulnerabilities:
Proactively auditing for such threat vectors across web properties is essential to avoid surprises down the line.
Over 60% of all website applications are statistically vulnerable to XSS attacks. Although mitigating 100% of attacks may be unlikely, there are baseline measures you can take to safeguard valuable business assets and data.
The key principles for preventing XSS flaws include:
While XSS attacks remain highly dangerous and prevalent in this day and age, they are preventable with the right security measures. Don’t rely solely on these baseline security practices to weed out XSS attackers, however, continual education and awareness is key if your infrastructure is to remain stable and uncompromised.
Disclaimer: The author is completely responsible for the content of this article. The opinions expressed are their own and do not represent IEEE's position nor that of the Computer Society nor its Leadership.