CVE-2021-21351
Unrestricted File Upload in XStream is a Java library to serialize objects to XML and back again
Executive Summary
CVE-2021-21351 is a medium severity vulnerability affecting appsec. It is classified as Unrestricted Upload. Ensure your systems and dependencies are patched immediately to mitigate exposure risks.
Precogs AI Insight
"The XStream Java library contains a vulnerability allowing unsafe deserialization. Attackers supply crafted XML payloads to instantiate arbitrary objects, leading to remote code execution. Precogs API Security Engine identifies unsafe object deserialization pathways."
What is this vulnerability?
CVE-2021-21351 is categorized as a medium Unrestricted File Upload flaw with a CVSS base score of 5.4. Based on our vulnerability intelligence, this issue occurs when the application fails to securely handle untrusted data boundaries.
XStream is a Java library to serialize objects to XML and back again. In XStream before version 1.4.16, there is a vulnerability may allow a remote attacker to load and execute arbitrary code from a remote host only by manipulating the processed input stream. No user is affected, who followed the recommendation to setup XStream's security framework with a whitelist limited to the minimal required types. If you rely on XStream's default blacklist of the Security Framework, you will have to use at least version 1.4.16.
This architectural defect enables adversaries to bypass intended security controls, directly manipulating the application's execution state or data layer. Immediate strategic intervention is required.
Risk Assessment
| Metric | Value |
|---|---|
| CVSS Base Score | 5.4 (MEDIUM) |
| Vector String | CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:C/C:N/I:H/A:N |
| Published | March 23, 2021 |
| Last Modified | May 23, 2025 |
| Related CWEs | CWE-434, CWE-502 |
Impact on Systems
✅ Data Exfiltration: Attackers can extract sensitive data from backend databases, configuration files, or internal services.
✅ Authentication Bypass: Exploiting this flaw may allow unauthorized access to protected resources and administrative interfaces.
✅ Lateral Movement: Once initial access is gained, attackers can pivot to internal systems and escalate privileges.
How to Fix and Mitigate CVE-2021-21351
- Apply Vendor Patches: Upgrade affected components to their latest, non-vulnerable versions immediately.
- Implement Input Validation: Ensure all user-supplied data is validated, sanitized, and type-checked before processing.
- Deploy Runtime Protection: Use Precogs continuous monitoring to detect exploitation attempts in real time.
- Audit Dependencies: Review and update all third-party libraries and transitive dependencies.
Defending with Precogs AI
The XStream Java library contains a vulnerability allowing unsafe deserialization. Attackers supply crafted XML payloads to instantiate arbitrary objects, leading to remote code execution. Precogs API Security Engine identifies unsafe object deserialization pathways.
Use Precogs to continuously scan your codebase, binaries, APIs, and infrastructure for this vulnerability class and related attack patterns. Our AI-powered detection engine combines static analysis with threat intelligence to identify exploitable weaknesses before attackers do.
Vulnerability Code Signature
Attack Data Flow
| Stage | Detail |
|---|---|
| Source | User-uploaded file |
| Vector | File is saved to a web-accessible directory without validation |
| Sink | File system write operation |
| Impact | Remote Code Execution (RCE), full system compromise |
Vulnerable Code Pattern
// ❌ VULNERABLE: Unrestricted Upload
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
// Taint sink: saving file without extension/type validation
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
Secure Code Pattern
// ✅ SECURE: Validated Upload
$target_dir = "uploads/";
$filename = basename($_FILES["fileToUpload"]["name"]);
$filetype = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
// Sanitized validation: strict allowlist
$allowed_types = array("jpg", "png", "gif");
if (in_array($filetype, $allowed_types)) {
// Generate safe unique filename
$safe_filename = uniqid() . "." . $filetype;
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_dir . $safe_filename);
}
How Precogs Detects This
Precogs AI Analysis Engine utilizes semantic taint tracking to detect insecure file upload routines and missing extension validation.\n