CVE-2022-22980: SpEL Injection in Spring Data MongoDB

Summary

24/06/2022
Yes i
Critical
9.0

CVE-2022-22980: SpEL Injection in Spring Data MongoDB. Affects org.springframework.data:spring-data-mongodb across 2 version ranges.

< 3.3.5 >= 3.4.0, < 3.4.1

Fixed in 3.3.5 or 3.4.1, depending on the release line you run. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

Spring Data MongoDB is a library that provides a high-level abstraction for interacting with MongoDB databases in Spring applications. It simplifies the development process by offering convenient features and utilities for querying and manipulating data. However, a vulnerability has been discovered in Spring Data MongoDB that allows for SpEL (Spring Expression Language) Injection. This vulnerability affects versions 0 to 3.3.5 and 3.4.0 to 3.4.1 of the 'org.springframework.data:spring-data-mongodb' package.

Vulnerability Detail

The SpEL Injection vulnerability arises when using @Query or @Aggregation-annotated query methods with SpEL expressions that contain query parameter placeholders for value binding. If the input is not properly sanitized, an attacker can inject malicious SpEL expressions, leading to unauthorized data access, data manipulation, or even remote code execution. This vulnerability has a CVSS score of 9.0, indicating its critical severity.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 3.3.5 3.3.5
  • >= 3.4.0, < 3.4.1 3.4.1

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Workaround

As a temporary workaround, it is advised to sanitize and validate user input before using it in SpEL expressions. Implement input validation and restrict the use of user-supplied values in SpEL expressions to prevent potential injection attacks. Here is an example of how to sanitize user input in a Spring Data MongoDB query method:

import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

public class UserRepository {

  public User findUserByUsername(String username) {
    String sanitizedUsername = sanitizeInput(username);
    Query query = new Query(Criteria.where("username").is(sanitizedUsername));
    return mongoTemplate.findOne(query, User.class);
  }

  private String sanitizeInput(String input) {
    // Implement input sanitization logic
    return input;
  }

}

Conclusion

The SpEL Injection vulnerability in Spring Data MongoDB can have severe consequences if left unaddressed. It is crucial to upgrade to the fixed versions or apply the provided workaround to mitigate the risk of injection attacks. For further assistance or support in remediating this vulnerability, please contact DevNack.com.

See every vulnerability recorded for org.springframework.data:spring-data-mongodb →

Share this vulnerability

FAQ

SpEL Injection is a vulnerability that occurs when untrusted user input is used in Spring Expression Language (SpEL) expressions without proper validation or sanitization. Attackers can exploit this vulnerability to inject malicious SpEL expressions, leading to unauthorized access, data manipulation, or remote code execution.

This vulnerability affects Spring Data MongoDB applications that use @Query or @Aggregation-annotated query methods with SpEL expressions containing query parameter placeholders. If the input is not sanitized, attackers can inject malicious SpEL expressions, potentially compromising the confidentiality, integrity, and availability of the application's data.

This vulnerability has a CVSS score of 9.0, indicating its critical severity. It is crucial to address this vulnerability promptly to prevent potential exploitation and protect the security of your Spring Data MongoDB application.

To fix this vulnerability, you should upgrade the 'org.springframework.data:spring-data-mongodb' package to version 3.4.1 if you are using versions 3.4.0 to 3.4.1. For versions 0 to 3.3.5, upgrade to version 3.3.5. Updating to the fixed versions will patch the vulnerability and ensure the safe usage of SpEL expressions in query methods.

As a temporary workaround, you can sanitize and validate user input before using it in SpEL expressions. Implement input validation and restrict the use of user-supplied values in SpEL expressions to mitigate the risk of injection attacks. Refer to the provided code example in the 'workaround' section for guidance.

Related vulnerabilities

Recent vulnerabilities recorded for org.springframework.data:spring-data-mongodb.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 3.3.5 3.3.5
  • >= 3.4.0, < 3.4.1 3.4.1

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback