Skip to content
Knowledge base Updated: February 4, 2026

What is CWE? Guide to Common Weakness Enumeration

CWE (Common Weakness Enumeration) is a catalog of common software weaknesses. Learn about CWE Top 25, the difference between CWE and CVE, and how to use CWE in secure software development.

A CVE tells you that one product has one flaw. A CWE tells you what kind of mistake produced it — and that is the more useful piece of information, because a team that keeps shipping the same class of weakness will keep generating CVEs. Reading findings by weakness class rather than by individual identifier is what turns a remediation queue into a change in how software is written.

What is CWE?

CWE (Common Weakness Enumeration) is a community-maintained catalog of common software and hardware security weaknesses. Unlike CVE, which describes specific vulnerabilities, CWE defines categories of flaws that can lead to vulnerabilities.

AspectCWECVE
What it describesType of weakness/flawSpecific vulnerability
ExampleCWE-79: Cross-site ScriptingCVE-2021-44228: Log4Shell
Number of entries~1000 types~250,000+ vulnerabilities
VariabilityStable (categories)Grows daily
Use caseEducation, code analysisPatching, alerting

Simple analogy:

  • CWE = type of disease (flu)
  • CVE = specific case of illness (patient #12345 with flu)

Who Maintains CWE?

CWE is developed by MITRE Corporation in collaboration with the security community. The list is funded by CISA (Cybersecurity and Infrastructure Security Agency).

CWE Structure

CWE Hierarchy

CWE is organized hierarchically:

CWE-1000: Research Concepts (root)
└── CWE-699: Software Development (category)
    └── CWE-20: Improper Input Validation (class)
        └── CWE-79: Cross-site Scripting (base)
            └── CWE-80: Basic XSS (variant)

CWE Entry Types

TypeDescriptionExample
PillarHighest abstraction levelCWE-682: Incorrect Calculation
ClassAbstract weakness classCWE-20: Improper Input Validation
BaseSpecific weaknessCWE-79: XSS
VariantSpecific variantCWE-80: Basic XSS
CompoundCombination of weaknessesCWE-352: CSRF

Anatomy of a CWE Entry

Each CWE entry contains:

CWE-89: Improper Neutralization of Special Elements
        used in an SQL Command ('SQL Injection')

├── Description (weakness description)
├── Extended Description (technical details)
├── Relationships (relationships with other CWEs)
├── Applicable Platforms (languages, technologies)
├── Common Consequences (exploitation effects)
├── Likelihood of Exploit (probability)
├── Detection Methods (how to detect)
├── Potential Mitigations (how to prevent)
├── Demonstrative Examples (code examples)
├── Observed Examples (related CVEs)
└── References (sources)

CWE Top 25 Most Dangerous Software Weaknesses

MITRE annually publishes a list of 25 most dangerous weaknesses based on real vulnerability data (CVE) and their impact.

CWE Top 25 (2024)

RankCWE IDNameExample
1CWE-79Cross-site Scripting (XSS)JS injection into page
2CWE-89SQL Injection' OR '1'='1
3CWE-416Use After FreeAccess to freed memory
4CWE-78OS Command Injection; rm -rf /
5CWE-20Improper Input ValidationLack of input validation
6CWE-125Out-of-bounds ReadReading beyond buffer
7CWE-22Path Traversal../../../etc/passwd
8CWE-352Cross-Site Request ForgeryUnauthorized action
9CWE-787Out-of-bounds WriteBuffer overflow
10CWE-287Improper AuthenticationWeak authentication

Full Top 25 List (2024)

RankCWE IDName
11CWE-476NULL Pointer Dereference
12CWE-798Use of Hard-coded Credentials
13CWE-190Integer Overflow
14CWE-502Deserialization of Untrusted Data
15CWE-77Command Injection
16CWE-119Buffer Overflow
17CWE-862Missing Authorization
18CWE-276Incorrect Default Permissions
19CWE-918Server-Side Request Forgery (SSRF)
20CWE-306Missing Authentication
21CWE-362Race Condition
22CWE-269Improper Privilege Management
23CWE-94Code Injection
24CWE-863Incorrect Authorization
25CWE-400Uncontrolled Resource Consumption

Key CWEs - Details

CWE-79: Cross-site Scripting (XSS)

Description: Application does not neutralize or improperly neutralizes user input before including it in HTML output.

XSS Types:

  • Reflected (CWE-79) - payload in URL, executed immediately
  • Stored (CWE-79) - payload stored in database, executed on each view
  • DOM-based (CWE-79) - payload manipulates DOM without server roundtrip

Vulnerable code example (PHP):

// BAD - no encoding
echo "Hello, " . $_GET['name'];

// Attack: ?name=<script>alert('XSS')</script>

Correct solution:

// GOOD - HTML encoding
echo "Hello, " . htmlspecialchars($_GET['name'], ENT_QUOTES, 'UTF-8');

Mitigations:

  1. Output encoding
  2. Content Security Policy (CSP)
  3. Input validation and sanitization
  4. Using frameworks with auto-escape (React, Angular)

CWE-89: SQL Injection

Description: Application constructs SQL queries using user input without proper neutralization.

Vulnerable code example (PHP):

// BAD - concatenation
$query = "SELECT * FROM users WHERE id = " . $_GET['id'];

// Attack: ?id=1 OR 1=1

Correct solution:

// GOOD - prepared statements
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$_GET['id']]);

Mitigations:

  1. Prepared statements / parameterized queries (most important!)
  2. ORM with parameterization
  3. Input type validation
  4. Least privilege principle for DB account

CWE-22: Path Traversal

Description: Application uses user input to construct file paths without proper validation.

Vulnerable code example (Python):

# BAD - no path validation
filename = request.args.get('file')
return send_file(f"/uploads/{filename}")

# Attack: ?file=../../../etc/passwd

Correct solution:

# GOOD - validation and normalization
import os
filename = request.args.get('file')
safe_path = os.path.normpath(os.path.join('/uploads', filename))
if not safe_path.startswith('/uploads/'):
    abort(403)
return send_file(safe_path)

CWE-798: Use of Hard-coded Credentials

Description: Application contains hard-coded passwords, API keys, or other secrets.

Vulnerable code example:

# BAD - password in code
DB_PASSWORD = "SuperSecretPassword123!"
API_KEY = "sk-1234567890abcdef"

Correct solution:

# GOOD - environment variables or secrets manager
import os
DB_PASSWORD = os.environ.get('DB_PASSWORD')
API_KEY = os.environ.get('API_KEY')

# Or: AWS Secrets Manager, HashiCorp Vault, Azure Key Vault

CWE vs OWASP Top 10

CWE and OWASP Top 10 are related but serve different purposes:

AspectCWEOWASP Top 10
ScopeAll weaknessesTop 10 categories for web
GranularityDetailed (950+ entries)High abstraction (10 categories)
UpdatesContinuousEvery ~4 years
Use caseTechnical classificationAwareness, prioritization

OWASP Top 10 (2021) to CWE Mapping

OWASPMain CWEs
A01: Broken Access ControlCWE-200, CWE-284, CWE-285, CWE-639
A02: Cryptographic FailuresCWE-259, CWE-327, CWE-331
A03: InjectionCWE-77, CWE-78, CWE-79, CWE-89
A04: Insecure DesignCWE-209, CWE-256, CWE-501
A05: Security MisconfigurationCWE-16, CWE-611
A06: Vulnerable ComponentsCWE-1104
A07: Auth FailuresCWE-287, CWE-384, CWE-613
A08: Software/Data IntegrityCWE-494, CWE-502, CWE-829
A09: Logging FailuresCWE-117, CWE-223, CWE-532
A10: SSRFCWE-918

How to Use CWE in Practice?

1. Secure Code Review

During code review, look for patterns matching specific CWEs:

Code Review Checklist:
□ CWE-79: Is user data encoded before display?
□ CWE-89: Are we using prepared statements?
□ CWE-22: Are file paths validated?
□ CWE-798: Are there no hardcoded credentials?
□ CWE-502: Are we only deserializing trusted data?

2. SAST/DAST Configuration

SAST tools (e.g., SonarQube, Checkmarx) report findings with CWE references:

Finding: SQL Injection vulnerability
File: UserController.java:45
CWE: CWE-89
Severity: Critical
Recommendation: Use PreparedStatement instead of string concatenation

3. Vulnerability Classification

Assign CWE to discovered vulnerabilities:

Pentest Report:
┌────────────────────────────────────────────────┐
│ Finding #1: Stored XSS in comments            │
│ CWE: CWE-79                                   │
│ CVSS: 6.1 (Medium)                            │
│ OWASP: A03:2021 Injection                     │
│ Remediation: Implement output encoding        │
└────────────────────────────────────────────────┘

4. Developer Training

Developer training based on CWE Top 25:

  1. Week 1: CWE-79 (XSS) - theory + exercises
  2. Week 2: CWE-89 (SQLi) - theory + exercises
  3. Week 3: CWE-22 (Path Traversal) - theory + exercises
  4. …

5. Procurement Requirements

In vendor requirements:

“Delivered software must not contain weaknesses from the CWE Top 25 Most Dangerous Software Weaknesses list, which will be verified through SAST/DAST scanning before acceptance.”

Tools Supporting CWE

ToolTypeCWE Support
SonarQubeSASTRule mapping to CWE
CheckmarxSASTNative CWE reporting
SnykSCA/SASTCWE in reports
OWASP ZAPDASTCWE ID in alerts
Burp SuiteDASTCWE references
SemgrepSASTCustom rules with CWE

CWE in Regulations and Standards

Regulation/StandardCWE Requirements
PCI DSS 4.0Requires addressing OWASP Top 10 (mapped to CWE)
NIST SSDFRecommends using CWE for classification
ISO 27001Indirectly through secure development
NIS2Secure software development requirements
Cyber Resilience ActWill require CWE reporting

FAQ

Does every vulnerability (CVE) have an assigned CWE?

Not always, but NVD tries to assign CWE to all CVEs. The vast majority of CVEs have assigned CWE.

How many CWEs should I know as a developer?

Start with CWE Top 25. This covers most real problems. Then learn CWEs specific to your technology (e.g., CWE-918 SSRF for cloud applications).

Does CWE only apply to web applications?

No. CWE covers weaknesses in:

  • Web applications
  • Desktop applications
  • Embedded systems
  • Hardware
  • Cryptography
  • Configuration

How to report new CWE?

You can submit proposals for new CWEs through the MITRE CWE website. Justification is required that the weakness is common and not covered by existing CWE.

Summary

  • CWE is a catalog of software weakness types (not specific vulnerabilities)
  • CVE describes specific vulnerabilities, CWE classifies the type of flaw
  • CWE Top 25 is the list of most dangerous weaknesses - mandatory knowledge for developers
  • Most important CWEs: CWE-79 (XSS), CWE-89 (SQLi), CWE-22 (Path Traversal)
  • Use CWE for classification in reports, training, vendor requirements
  • SAST/DAST tools automatically report findings with CWE references

Want to check your code security? Order source code audit or application penetration testing. Contact us.

Learn key terms related to this article in our cybersecurity glossary:


Explore Our Services

Need cybersecurity support? Check out:

Share:

Talk to an expert

Have questions about this topic? Get in touch with our specialist.

Sales Representative
Przemysław Widomski

Przemysław Widomski

Sales Representative

Response within 24 hours
Free consultation
Individual approach

Providing your phone number will speed up contact.

Want to Reduce IT Risk and Costs?

Book a free consultation - we respond within 24h

Response in 24h Free quote No obligations