Skip to content

Commit 1918ccf

Browse files
committed
Python: Add QLDocs
1 parent e07070e commit 1918ccf

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

python/ql/lib/semmle/python/security/dataflow/NoSQLInjectionCustomizations.qll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,65 @@
1+
/**
2+
* Provides default sources, sinks and sanitizers for detecting
3+
* "NoSql injection"
4+
* vulnerabilities, as well as extension points for adding your own.
5+
*/
6+
17
import python
28
import semmle.python.dataflow.new.DataFlow
39
import semmle.python.dataflow.new.RemoteFlowSources
410
import semmle.python.Concepts
511

12+
/**
13+
* Provides default sources, sinks and sanitizers for detecting
14+
* "NoSql injection"
15+
* vulnerabilities, as well as extension points for adding your own.
16+
*/
617
module NoSqlInjection {
718
private newtype TFlowState =
819
TStringInput() or
920
TDictInput()
1021

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

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

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

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

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

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

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

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

55+
/** Gets the resulting dictionary. */
3456
abstract DataFlow::Node getOutput();
3557
}
3658

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

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

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

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

python/ql/lib/semmle/python/security/dataflow/NoSQLInjectionQuery.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
/**
2+
* Provides a taint-tracking configuration for detecting NoSQL injection vulnerabilities
3+
*/
4+
15
import python
26
import semmle.python.dataflow.new.DataFlow
37
import semmle.python.dataflow.new.TaintTracking
48
import semmle.python.Concepts
59
private import NoSQLInjectionCustomizations::NoSqlInjection as C
610

11+
/**
12+
* A taint-tracking configuration for detecting NoSQL injection vulnerabilities.
13+
*/
714
module Config implements DataFlow::StateConfigSig {
815
class FlowState = C::FlowState;
916

0 commit comments

Comments
 (0)