# GHSA-m734-r4g6-34f9: NoSQL Injection in loopback-connector-mongodb

> Attackers can execute arbitrary JavaScript on the database via NoSQL injection in the LoopBack MongoDB connector, leading to code execution or denial of service.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 4 Jun 2019

## What is GHSA-m734-r4g6-34f9?

GHSA-m734-r4g6-34f9 is a code injection vulnerability in loopback-connector-mongodb, published on 4 Jun 2019. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Versions of `loopback-connector-mongodb` before 3.6.0 are vulnerable to NoSQL injection.

MongoDB Connector for LoopBack fails to properly sanitize a filter passed to query the database by allowing the dangerous `$where` property to be passed to the MongoDB Driver. The Driver allows the special `$where` property in a filter to execute JavaScript (client can pass in a malicious script) on the database Driver. This is an [intended feature of MongoDB](https://docs.mongodb.com/manual/core/server-side-javascript/) unless disabled ([instructions here](https://docs.mongodb.com/manual/core/server-side-javascript/#disable-server-side-js)).

A proof of concept malicious query:

```
GET /POST filter={"where": {"$where": "function(){sleep(5000); return this.title.contains('Hello');}"}}
```

The above makes the database sleep for 5 seconds and then returns all “Posts” with the title containing the word `Hello`.

## Recommendation

Update to version 3.6.0 or later.

## Which versions are affected by GHSA-m734-r4g6-34f9?

2 open source packages ship an affected version, including loopback-connector-mongodb.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `loopback-connector-mongodb` | npm | All versions | 3.6.0 |
| `loopback-connector-mongodb` | npm | All versions | 3.6.0 |

## How do I fix GHSA-m734-r4g6-34f9?

Upgrade loopback-connector-mongodb to 3.6.0 or later.

## Is GHSA-m734-r4g6-34f9 being exploited?

There is no known exploitation of GHSA-m734-r4g6-34f9 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-m734-r4g6-34f9 and fix it if it is affected.

What it is: GHSA-m734-r4g6-34f9 is a code injection vulnerability in loopback-connector-mongodb, published on 4 Jun 2019. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-m734-r4g6-34f9 in the wild and no public exploit code.

Affected packages and fixed versions:
- loopback-connector-mongodb (npm): affected all versions; fixed in 3.6.0
- loopback-connector-mongodb (npm): affected all versions; fixed in 3.6.0

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-m734-r4g6-34f9/ (Markdown: https://insights.sbomify.com/GHSA-m734-r4g6-34f9/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-m734-r4g6-34f9

---
From sbomify Insights: https://insights.sbomify.com/GHSA-m734-r4g6-34f9/
Summaries are generated and may contain mistakes; the official description above is the record.
