Security weaknessCWE Top 25 · #1
CWE-79 Cross-site scripting (XSS)
Attackers plant scripts in your pages that run in visitors’ browsers and can hijack their sessions or accounts.
- Senior security engineers
- 540+ projects delivered
- Reply within one business day
Quick answer
What is CWE-79?
Improper Neutralization of Input During Web Page Generation: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
Business impact
What CWE-79 could cost your business
MITRE documents what this weakness can do. Here is what that means for a website, store or app.
Confidentiality
Private data exposed
Customer records, credentials, orders or internal files can be read by people who should never see them.
- Bypass Protection Mechanism
- Read Application Data
- Execute Unauthorized Code or Commands
Integrity
Data, pages or code changed
Prices, orders, content or the code your site runs can be altered without your approval.
- Execute Unauthorized Code or Commands
- Bypass Protection Mechanism
- Read Application Data
Availability
Downtime and lost sales
Crashes, slowdowns or exhausted resources can take your site, store or app offline.
- Execute Unauthorized Code or Commands
- Bypass Protection Mechanism
- Read Application Data
Access Control
Accounts and admin areas exposed
Logins and permission checks can be bypassed, putting admin and customer accounts at risk.
- Bypass Protection Mechanism
- Read Application Data
- Execute Unauthorized Code or Commands
In plain English
What Cross-site scripting (XSS) means for your business
- 540+projects delivered
- 9+years in business
- 23+certified experts
A senior engineer replies within one business day.
Cross-site scripting, or XSS, happens when your site takes text that someone typed or sent and puts it into a page without making it safe first. The browser cannot tell your code from the attacker’s, so it runs both. A comment, a search term, a profile name or a product review can all carry a script. Anyone who then views that page runs it with their own login and their own data.
For a business, the damage lands on your customers and your staff. A script running in an admin’s browser can act as that admin: change settings, create users or read orders. A script on a checkout or account page can read what shoppers type. Visitors see your domain in the address bar, so they trust what the page shows them. That trust is what the attacker borrows, and it is your brand that takes the blame.
Where it shows up
- Comment forms, product reviews and forum posts that save what visitors write and show it to everyone else, including logged-in administrators who moderate the content.
- Search results and error pages that repeat the search term or a URL parameter back onto the page without encoding it for HTML first.
- WordPress plugins and theme options that print settings, shortcode attributes or form field values straight into a page or the admin dashboard.
- Single-page apps that build HTML from API responses or URL fragments in JavaScript, which is known as DOM-based XSS because the flaw lives in browser code.
Free security check
Is CWE-79 hiding in your site?
A senior engineer checks your site, store or app for this weakness and the rest of the CWE Top 25, then sends a prioritized fix plan within one business day. No obligation.
Official definition
How MITRE defines CWE-79
Improper Neutralization of Input During Web Page Generation
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
Also known as: Cross-site Scripting, XSS, HTML Injection, Reflected XSS / Non-Persistent XSS / Type 1 XSS, Stored XSS / Persistent XSS / Type 2 XSS, DOM-Based XSS / Type 0 XSS, CSS
Fix it
How to fix Cross-site scripting (XSS)
Practical steps in priority order. Share them with your developer or agency.
Escape output for its context
Encode every dynamic value at the point you print it, using the right function for the context: HTML body, attribute, URL or JavaScript. In WordPress, use esc_html, esc_attr and esc_url. Never rely on input filtering alone.
Use auto-escaping templates and frameworks
Render pages with a template engine or framework that escapes by default, such as React, Twig or Blade. Review every place that turns escaping off, including raw filters and dangerouslySetInnerHTML, and remove the ones you do not need.
Sanitize any HTML you allow
If users may submit rich text, pass it through a maintained allowlist sanitizer such as wp_kses or DOMPurify. Permit only the tags and attributes you need. Strip event handlers, script elements and links that use the javascript scheme.
Add a Content Security Policy
Send a Content-Security-Policy header that blocks inline scripts and limits script sources to hosts you trust. Start in report-only mode, fix what it flags, then enforce it. This limits damage when an escaping mistake slips through.
Protect session cookies
Set HttpOnly on session cookies so page scripts cannot read them, and add the Secure and SameSite attributes as well. This does not remove the flaw, but it makes sessions much harder for an injected script to steal.
Signs you may be affected
- Unexpected pop-ups, redirects or injected ads appear on pages that display content submitted by users.
- A security scanner or plugin audit reports unescaped output, reflected input or a missing Content Security Policy.
- Your templates print request data or database fields directly, without an escaping function around each value.
Questions to ask your developer
- Do our templates escape every dynamic value by default, and where is escaping turned off?
- How do we sanitize rich text that customers or staff can submit?
- Do we send a Content Security Policy, and is it enforced or only reporting?
Prevention
What MITRE recommends, phase by phase
Every mitigation from the CWE entry, in the order a project runs: plan, build, test, operate.
- 01
Architecture and Design
- Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid [REF-1482]. Examples of libraries and frameworks that make it easier to generate properly encoded output include Microsoft’s Anti-XSS library, the OWASP ESAPI Encoding module, and Apache Wicket.
- Understand the context in which your data will be used and the encoding that will be expected. This is especially important when transmitting data between different components, or when generating outputs that can contain multiple encodings at the same time, such as web pages or multi-part mail messages. Study all expected communication protocols and data representations to.
- Understand all the potential areas where untrusted inputs can enter your software: parameters or arguments, cookies, anything read from the network, environment variables, reverse DNS lookups, query results, request headers, URL components, e-mail, files, filenames, databases, and any external systems that provide data to the application. Remember that such inputs may be.
Show 3 more recommendations
- For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the.
- If available, use structured mechanisms that automatically enforce the separation between data and code. These mechanisms may be able to provide the relevant quoting, encoding, and validation automatically, instead of relying on the developer to provide this capability at every point where output is generated.
- When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs.
- 02
Implementation
- Use and specify an output encoding that can be handled by the downstream component that is reading the output. Common encodings include ISO-8859-1, UTF-7, and UTF-8. When an encoding is not specified, a downstream component may choose a different encoding, either by assuming a default encoding or automatically inferring which encoding is being used, which can be erroneous. When.
- With Struts, write all data from form beans with the bean’s filter attribute set to true.
- To help mitigate XSS attacks against the user’s session cookie, set the session cookie to be HttpOnly. In browsers that support the HttpOnly feature (such as more recent versions of Internet Explorer and Firefox), this attribute can prevent the user’s session cookie from being accessible to malicious client-side scripts that use document.cookie. This is not a complete solution.
Show 1 more recommendation
- Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of.
Detection and evidence
How CWE-79 is found, and where it has hit
The testing methods MITRE recommends, and real vulnerabilities this weakness has caused.
How it is detected
- Automated Static AnalysisUse automated static analysis tools that target this type of weakness. Many modern techniques use data flow analysis to minimize the number of false positives. This is not a perfect solution, since 100% accuracy and coverage are not feasible, especially when multiple components are involved.
- Black BoxUse the XSS Cheat Sheet [REF-714] or automated test-generation tools to help launch a wide variety of attacks against your web application. The Cheat Sheet contains many subtle XSS variations that are specifically targeted against weak XSS defenses.
Real vulnerabilities it caused
- CVE-2024-49038XSS in AI assistant
- CVE-2024-54142Plugin that enables AI features allows input with html entities, leading to XSS
- CVE-2021-25926Python Library Manager did not sufficiently neutralize a user-supplied search term, allowing reflected XSS.
- CVE-2021-25963Python-based e-commerce platform did not escape returned content on error pages, allowing for reflected Cross-Site Scripting attacks.
- CVE-2021-1879Universal XSS in mobile operating system, as exploited in the wild per CISA KEV.
- CVE-2020-3580Chain: improper input validation (CWE-20) in firewall product leads to XSS (CWE-79), as exploited in the wild per CISA KEV.
How we fix it
From finding to fixed: how Codefreex closes CWE-79
Scan and confirm
We test your site, store or app for this weakness and the rest of the CWE Top 25 with automated scanning and manual review, and confirm what is actually exploitable.
Fix at the source
We change the code, configuration or dependency that causes it, not just the symptom, and plan the changes to avoid downtime.
Verify the fix
We retest every finding, check that nothing else broke and hand you a short report you can share with your team, client or auditor.
Keep it fixed
Updates, monitoring and maintenance so the weakness does not return with the next plugin, theme, app or code change.
Website SecurityPenetration TestingMalware Removal & Hack RepairWordPress Maintenance
Related weaknesses
Weaknesses related to CWE-79
FAQ
CWE-79: FAQs
Short answers for owners and developers. Not sure whether your site is affected? Ask us to check.
How serious is cross-site scripting for a business website?
It is serious because it turns your own pages against your visitors. A script injected into a page can act as whoever is viewing it. If that person is an administrator, the attacker may gain control of the site. If it is a shopper, the attacker may read what they type. MITRE rates the likelihood of exploitation as high.
What is the difference between stored, reflected and DOM-based XSS?
Stored XSS is saved on your server, for example in a comment, and runs for everyone who views it. Reflected XSS arrives in a link or form and is echoed straight back to one visitor. DOM-based XSS happens entirely in browser JavaScript that writes untrusted data into the page. The fix is the same for all three: encode output for its context.
How do I prevent XSS on my site?
Escape every piece of dynamic data at the moment it is printed, using the function that matches where it lands. Use a framework that escapes by default. Sanitize any HTML you accept with an allowlist. Add a Content Security Policy and HttpOnly cookies as a second layer. Keep plugins and themes updated, because many XSS flaws arrive through third-party code.
What is CWE-79?
CWE-79, “Improper Neutralization of Input During Web Page Generation”, is a software weakness catalogued by MITRE in the Common Weakness Enumeration. The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
How serious is CWE-79?
MITRE rates the likelihood of exploit as High. It can affect access control, confidentiality, integrity, availability, with impacts such as bypass protection mechanism, read application data, execute unauthorized code or commands. It ranks number 1 on the 2025 CWE Top 25 Most Dangerous Software Weaknesses. The real risk depends on where the weakness sits and what data or functions it exposes.
How do you prevent CWE-79?
Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid [REF-1482]. Examples of libraries and frameworks that make it easier to generate properly encoded output include. Understand the context in which your data will be used and the encoding that will be expected. This is especially important when transmitting data between different components, or when generating.
Can Codefreex check my site for CWE-79?
Yes. A senior engineer reviews your site, store or app for CWE-79 and the rest of the CWE Top 25, confirms what is exploitable and sends a prioritized fix plan within one business day. Start with the free security check form on this page.
Free security check
Find out if CWE-79 affects your site
Send your URL. A senior engineer checks for this weakness and the rest of the CWE Top 25, and replies within one business day with what to fix first.
- A senior strategist reviews your request, not a sales bot
- Clear scope, timeline and estimate within one business day
- Free 30-minute discovery call, no obligation
- NDA available on request
- Emailhello@codefreex.com
- CallUSA +1 (209) 375-3475 · India +91 790 3375 530
- Prefer to talk?Book a 30-minute call
Weakness data from the Common Weakness Enumeration (CWE®) version 5.0, Copyright © 2006–2026, The MITRE Corporation. CWE is free to use by any organization or individual for any research, development, and/or commercial purposes under the CWE Terms of Use. CWE is a registered trademark of The MITRE Corporation. The business impact, risk profile and plain-English guidance on this page are written by Codefreex and are general information, not a security assessment of your system.