CWE-79 is a Common Weakness Enumeration (CWE) ID that pertains to a vulnerability that exists in a product that does not neutralize or incorrectly neutralizes user-controllable inputs before they are placed in outputs used as web pages served to other users.

It is officially known as “Improper Neutralization of Input during Web Page Generation” or “Cross-Site Scripting (XSS).”

It is comparable to a bad actor providing a trusted employee with another employee’s ID (i.e., someone with greater access privileges), allowing the impersonator to gain unauthorized access to the assets and data only the one being impersonated has access to.

Other interesting terms…

Read More about CWE-79

Did you know that MySpace (2005), Twitter (2009), Yahoo! (2017), British Airways (2018), Uber (2019), and WhatsApp (2020) are just some of the popular platforms that suffered from XSS attacks? Learn more about the weakness here.

How Does CWE-79 Work?

An XSS attack begins when a bad actor finds a website that accepts user inputs (e.g., has a search bar or comment section) without properly validating or sanitizing it. The attacker inserts malicious code into the vulnerable input field. This could take the form of a specially crafted link, a comment, or a form.

The vulnerable site includes this malicious code in the content sent to a victim’s browser. The browser then receives the content and executes the injected script as if it were part of the legitimate website.

Once the script runs within the affected user’s browser, the bad actor can perform malicious actions like steal sensitive information (e.g., session cookies and login credentials), hijack the user’s accounts, or redirect the user to a fake or malicious website.

Watch this video to see an XSS attack in action.

How Can Users Trigger a CWE-79 Attack?

Any user can trigger an XSS attack. They can do so automatically when they load an infected web page or simply hover over certain page elements like hyperlinks.

In some cases, attackers can trigger the attack directly. An example would be embedding a malicious link in an email. Merely opening the message can trigger the attack.

In many instances, XSS attacks do not even have particular targets. Instead, the bad actors exploit a vulnerability in a very popular site or application to steal sensitive information from as many users as possible.

What Are the Usual Causes of a CWE-79 Vulnerability?

At least three scenarios can lead to the success of an XSS attack.

The primary cause is lack of input validation. This happens when an application does not enforce restrictions or sanitize the data users enter through form fields. So, even if the users input a malicious script, the page executes its payload.

In some cases, the attack succeeds due to improper output encoding. The website may have failed to encode special characters like <, >, &, or ‘ in outputs.

In other cases, the site may lack a Content Security Policy (CSP) header. For the less-initiated, CSP is a feature that helps prevent or minimize the risk of certain types of security threats.

The CSP header contains a series of instructions a website issues to a browser, telling the browser to restrict the things the site code is allowed to do. 

What Are the Effects of a CWE-79 Attack Based on Its Target?

The effects of an XSS attack depends on the target.

Static Content

Web applications with static content like news sites without login functionality can suffer least from XSS attacks. Why? Because all users are anonymous and the information on the website is publicly available.

Sensitive Data

Web applications that store sensitive user data, meanwhile, such as financial or health service sites can suffer a lot from XSS attacks. They can give threat actors the ability to compromise user accounts.

Privileged Users

Attackers can employ XSS to take over the session of a privileged user (e.g., web application administrator). If that happens, the cab actors can gain full control of the application and compromise all of its data.

What Are the Types of CWE-79 Attacks?

There are three major types of XSS attacks and we tackled each one below.

Stored or Persistent XSS

In this attack, the bad actor injects a malicious script into a user-facing input field (e.g., a comment box) on a target website. This script then gets saved in the site’s database.

When other users visit the infected page, the malicious script gets retrieved from the database and executed in the users’ browsers.

This type of attack can be very damaging and widespread since the malicious script runs automatically for all users who view the affected page.

How a Stored or Persistent XSS Attack Works

An example of this is the MySpace “Samy” Worm attack of 2005.

Reflected or Nonpersistent XSS

In this attack, the malicious script is part of a request like a link sent to a target web server. The server reflects this script back in the HyperText Transfer Protocol (HTTP) response.

It requires the user to perform an action to execute the script. As such, the attackers need to trick victims into clicking a malicious link or submitting a specially crafted request to the vulnerable server.

As the name suggests, the attack is not persistent, meaning the bad actors must send the payload to victims, often through phishing emails or social media.

How a Reflected or Nonpersistent XSS Attack Works

DOM-Based or Client-Side XSS

In this attack, the vulnerability lies within the client-side code (i.e., JavaScript) rather than the server-side code. The attacker manipulates a target web page’s Document Object Model (DOM) using JavaScript to execute malicious scripts.

It can occur without requiring the attackers to send the malicious script to the server. The JavaScript code on the page is responsible for the exploitation.

Given that the page’s code itself is manipulated, the attacker can compromise user data and actions within the browser.

How a DOM-Based or Client-Side XSS Attack Works

An example of this is the British Airways 2018 breach, which led to the theft of users’ sensitive data.

How Can You Protect against CWE-79 Attacks?

Like any other type of attack, XSS is preventable. Here are some best practices.

1. Increase Awareness

While XSS attacks have existed for years, lack of awareness about them still abounds in the developer community. It does not help that there is confusion about how its variants are classified. Attacks can also stem from a myriad of attack vectors. Only by knowing all there is to know about XSS can users and organizations truly bolster their defenses.

2. Sanitize User Inputs

The best way to counter XSS attacks is by neutralizing all user inputs. How? Using a neutralizing tool is one way to go about this. Another is to use a modern framework like React or ensure the framework you use is not susceptible to XSS attacks.

3. Implement Strict Security Policies

Prevent users from using HyperText Markup Language (HTML) in inputs. Instead, limit their inputs to only alphanumeric values and configure your servers to only accept these. Also, protect cookies using HTTPonly flags.

4. Scan for Vulnerabilities Periodically

Screening all your Internet-facing applications for all kinds of vulnerabilities is also tried-and-tested practice. Attack surface management (ASM) platforms can flag vulnerable packages, enabling your security team to identify, prioritize, and remediate vulnerabilities before attackers can exploit them.

5. Use WAFs

While traditional firewalls can handle many attacks, they cannot effectively handle XSS attacks. Concerned users and organizations must employ web application firewalls (WAFs) instead.

What Are Examples of CWE-79 Attacks?

We listed some infamous examples of XSS attacks below.

MySpace “Samy” Worm Attack

In 2005, security researcher Samy Kamkar created a worm that spread across MySpace. He injected JavaScript code into his profile, which, when viewed by other users, added them as friends and promoted his profile. The worm infected more than a million profiles in a matter of hours, leading to slow site performance and considerable disruption. MySpace even had to temporarily shut down to address the issue.

Twitter Worm Attack

In 2009, a hacker targeted a stored XSS vulnerability in Twitter to create a worm that exploited the “onmouseover” event of links. As such, when users hovered over affected links, the worm retweeted itself, causing it to spread. The worm affected tons of Twitter users, causing great embarrassment for the platform. In fact, Twitter had to take immediate measures to address the issue.

Yahoo! Breach

In 2017, the popular email service was affected by a persistent XSS vulnerability. Attackers were able to send malicious emails containing JavaScript that, when opened, executed in recipients’ email clients. This vulnerability put users at risk of account compromise and personal data exposure. While the company took steps to rectify the issue, threat actors already exploited it. As a result, 3 billion account owners were affected.

British Airways Breach

In 2018, attackers—part of the Magecart organization—used an XSS vulnerability to skim the personal and payment information of around 380,000 British Airways customers. The attackers managed to inject malicious scripts on British Airways payment websites that sent sensitive information to a server under their control.

Uber P3 XSS Attack

In 2019, a security researcher discovered an XSS vulnerability in the Uber website that allowed attackers to craft links that, when clicked by Uber drivers, exposed their account details and allowed unauthorized actions. Uber responded promptly to fix the issue and enhanced its security measures.

WhatsApp Web XSS Attack

In 2020, a security researcher found an XSS vulnerability in WhatsApp’s web client that could let attackers send specially crafted messages containing malicious code. Viewing the message in a web client ran the code. If exploited, the bug could enable attackers to compromise user data and take control of their accounts. WhatsApp addressed the issue promptly.

XSS versus CSRF, What’s the Difference?

While both XSS and cross-site request forgery (CSRF) attacks both target web applications, they have distinct differences as shown below.

XSSCSRF
Attack mechanismInvolves injecting malicious scripts that run in users’ browsers
Malicious scripts exploit the users’ trust in specific websites, letting attackers execute malicious JavaScript without raising suspicion
Involves sending unauthorized requests from browsers to trusted applications
Attackers do not need to inject malicious code
Attackers trick browsers into making malicious requests the target servers assume are legitimate
Security impactLets attackers directly interact with browsers’ DOM and session data
Allows attackers to steal tokens, manipulate page content, log keystrokes, or escalate access through other means
Causes users to unintentionally perform actions like submit forms, update data, or issue transactions
Attackers hijack ongoing sessions to gain access to accounts without knowing victims’ credentials
Defense strategiesInvolves a multilayered approach that sanitizes user inputs, encodes outputs properly, and uses CSP headers to restrict script execution sourcesRequires verifying if each state-changing request comes from an authorized source
Techniques include embedding CSRF tokens in forms, setting cookies with the SameSite attribute to limit cross-origin usage, and requiring users to reauthenticate for critical operations—measures that ensure requests cannot be forged without user intent

—

Did you know that as of this writing, CWE-79 is the most exploited vulnerability with 114,482 reports in total?

Key Takeaways

Sources

  • https://cwe.mitre.org/data/definitions/79.html
  • https://portswigger.net/kb/issues/00200311_cross-site-scripting-reflected-dom-based
  • https://www.cvedetails.com/cwe-details/79/Improper-Neutralization-of-Input-During-Web-Page-Generation-.html
  • https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP