diff --git a/python/ql/src/experimental/Security/CWE-943/NoSQLInjection.qhelp b/python/ql/src/experimental/Security/CWE-943/NoSQLInjection.qhelp index 9771f8fd0d98..2bfd56820103 100644 --- a/python/ql/src/experimental/Security/CWE-943/NoSQLInjection.qhelp +++ b/python/ql/src/experimental/Security/CWE-943/NoSQLInjection.qhelp @@ -20,14 +20,14 @@ NoSQL injections can be prevented by escaping user-input's special characters that are passed into the NoSQL query from the user-supplied source. Alternatively, using a sanitize library such as MongoSanitizer will ensure that user-supplied sources can not act as a malicious query.

- +

In the example below, the user-supplied source is passed to a MongoDB function that queries the MongoDB database.

This can be fixed by using a sanitizer library like MongoSanitizer as shown in this annotated code version below.

- +
  • Mongoengine: Documentation.
  • diff --git a/python/ql/src/experimental/semmle/python/security/injection/NoSQLInjection.qll b/python/ql/src/experimental/semmle/python/security/injection/NoSQLInjection.qll index b15a844605c1..fb3890d2f7e9 100644 --- a/python/ql/src/experimental/semmle/python/security/injection/NoSQLInjection.qll +++ b/python/ql/src/experimental/semmle/python/security/injection/NoSQLInjection.qll @@ -17,7 +17,7 @@ class RFSToDictConfig extends TaintTracking::Configuration { override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } override predicate isSink(DataFlow::Node sink) { - exists(Decoding decoding | decoding.getFormat() = "JSON" and sink = decoding) + exists(Decoding decoding | decoding.getFormat() = "JSON" and sink = decoding.getOutput()) } override predicate isSanitizer(DataFlow::Node sanitizer) { @@ -32,7 +32,7 @@ class FromDataDictToSink extends TaintTracking2::Configuration { FromDataDictToSink() { this = "FromDataDictToSink" } override predicate isSource(DataFlow::Node source) { - exists(Decoding decoding | decoding.getFormat() = "JSON" and source = decoding) + exists(Decoding decoding | decoding.getFormat() = "JSON" and source = decoding.getOutput()) } override predicate isSink(DataFlow::Node sink) { sink = any(NoSQLQuery noSQLQuery).getQuery() }