Skip to content

Commit

Permalink
Python: Add QLDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
yoff committed Sep 6, 2023
1 parent e07070e commit 1918ccf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,41 +1,65 @@
/**
* Provides default sources, sinks and sanitizers for detecting
* "NoSql injection"
* vulnerabilities, as well as extension points for adding your own.
*/

import python
import semmle.python.dataflow.new.DataFlow
import semmle.python.dataflow.new.RemoteFlowSources
import semmle.python.Concepts

/**
* Provides default sources, sinks and sanitizers for detecting
* "NoSql injection"
* vulnerabilities, as well as extension points for adding your own.
*/
module NoSqlInjection {
private newtype TFlowState =
TStringInput() or
TDictInput()

/** A flow state, tracking the structure of the input. */
abstract class FlowState extends TFlowState {
/** Gets a textual representation of this element. */
abstract string toString();
}

/** A state where input is only a string. */
class StringInput extends FlowState, TStringInput {
override string toString() { result = "StringInput" }
}

/** A state where input is a dictionary. */
class DictInput extends FlowState, TDictInput {
override string toString() { result = "DictInput" }
}

/** A source allowing string inputs. */
abstract class StringSource extends DataFlow::Node { }

/** A source allowing dictionary inputs. */
abstract class DictSource extends DataFlow::Node { }

/** A sink vulnerable to user controlled strings. */
abstract class StringSink extends DataFlow::Node { }

/** A sink vulnerable to user controlled dictionaries. */
abstract class DictSink extends DataFlow::Node { }

/** A data flow node where a string is converted into a dictionary. */
abstract class StringToDictConversion extends DataFlow::Node {
/** Gets the argument that specifies the string to be converted. */
abstract DataFlow::Node getAnInput();

/** Gets the resulting dictionary. */
abstract DataFlow::Node getOutput();
}

/** A remote flow source considered a source of user controlled strings. */
class RemoteFlowSourceAsStringSource extends RemoteFlowSource, StringSource { }

/** A NoSQL query that is vulnerable to user controlled strings. */
class NoSqlQueryAsStringSink extends StringSink {
NoSqlQueryAsStringSink() {
exists(NoSqlQuery noSqlQuery | this = noSqlQuery.getQuery() |
Expand All @@ -44,10 +68,12 @@ module NoSqlInjection {
}
}

/** A NoSQL query that is vulnerable to user controlled dictionaries. */
class NoSqlQueryAsDictSink extends DictSink {
NoSqlQueryAsDictSink() { this = any(NoSqlQuery noSqlQuery).getQuery() }
}

/** A JSON decoding converts a string to a dictionary. */
class JsonDecoding extends Decoding, StringToDictConversion {
JsonDecoding() { this.getFormat() = "JSON" }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/**
* Provides a taint-tracking configuration for detecting NoSQL injection vulnerabilities
*/

import python
import semmle.python.dataflow.new.DataFlow
import semmle.python.dataflow.new.TaintTracking
import semmle.python.Concepts
private import NoSQLInjectionCustomizations::NoSqlInjection as C

/**
* A taint-tracking configuration for detecting NoSQL injection vulnerabilities.
*/
module Config implements DataFlow::StateConfigSig {
class FlowState = C::FlowState;

Expand Down

0 comments on commit 1918ccf

Please sign in to comment.