diff --git a/python/ql/test/2/query-tests/Classes/new-style/PropertyInOldStyleClass.qlref b/python/ql/test/2/query-tests/Classes/new-style/PropertyInOldStyleClass.qlref
index 297295c006e6..fa1947665113 100644
--- a/python/ql/test/2/query-tests/Classes/new-style/PropertyInOldStyleClass.qlref
+++ b/python/ql/test/2/query-tests/Classes/new-style/PropertyInOldStyleClass.qlref
@@ -1 +1,2 @@
-Classes/PropertyInOldStyleClass.ql
+query: Classes/PropertyInOldStyleClass.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Classes/new-style/SlotsInOldStyleClass.qlref b/python/ql/test/2/query-tests/Classes/new-style/SlotsInOldStyleClass.qlref
index 62fb3202a16f..688f31402ad0 100644
--- a/python/ql/test/2/query-tests/Classes/new-style/SlotsInOldStyleClass.qlref
+++ b/python/ql/test/2/query-tests/Classes/new-style/SlotsInOldStyleClass.qlref
@@ -1 +1,2 @@
-Classes/SlotsInOldStyleClass.ql
\ No newline at end of file
+query: Classes/SlotsInOldStyleClass.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Classes/new-style/SuperInOldStyleClass.qlref b/python/ql/test/2/query-tests/Classes/new-style/SuperInOldStyleClass.qlref
index 08f737893eff..293fc72d86ca 100644
--- a/python/ql/test/2/query-tests/Classes/new-style/SuperInOldStyleClass.qlref
+++ b/python/ql/test/2/query-tests/Classes/new-style/SuperInOldStyleClass.qlref
@@ -1 +1,2 @@
-Classes/SuperInOldStyleClass.ql
\ No newline at end of file
+query: Classes/SuperInOldStyleClass.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Classes/new-style/newstyle_test.py b/python/ql/test/2/query-tests/Classes/new-style/newstyle_test.py
index f1e3ea8e42c8..44dce333ef90 100644
--- a/python/ql/test/2/query-tests/Classes/new-style/newstyle_test.py
+++ b/python/ql/test/2/query-tests/Classes/new-style/newstyle_test.py
@@ -1,7 +1,7 @@
#Only works for Python2
-class OldStyle1:
+class OldStyle1: # $ Alert[py/slots-in-old-style-class]
__slots__ = [ 'a', 'b' ]
@@ -12,7 +12,7 @@ def __init__(self, a, b):
class OldStyle2:
def __init__(self, x):
- super().__init__(x)
+ super().__init__(x) # $ Alert[py/super-in-old-style]
class NewStyle1(object):
diff --git a/python/ql/test/2/query-tests/Classes/new-style/property_old_style.py b/python/ql/test/2/query-tests/Classes/new-style/property_old_style.py
index 8291feab26c1..0b529d9edb7e 100644
--- a/python/ql/test/2/query-tests/Classes/new-style/property_old_style.py
+++ b/python/ql/test/2/query-tests/Classes/new-style/property_old_style.py
@@ -5,6 +5,6 @@ class OldStyle:
def __init__(self, x):
self._x = x
- @property
+ @property # $ Alert[py/property-in-old-style-class]
def piosc(self):
return self._x
\ No newline at end of file
diff --git a/python/ql/test/2/query-tests/Exceptions/general/CatchingBaseException.qlref b/python/ql/test/2/query-tests/Exceptions/general/CatchingBaseException.qlref
index 5588dbf2c7b4..33b4697e7ef7 100644
--- a/python/ql/test/2/query-tests/Exceptions/general/CatchingBaseException.qlref
+++ b/python/ql/test/2/query-tests/Exceptions/general/CatchingBaseException.qlref
@@ -1 +1,2 @@
-Exceptions/CatchingBaseException.ql
\ No newline at end of file
+query: Exceptions/CatchingBaseException.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Exceptions/general/EmptyExcept.qlref b/python/ql/test/2/query-tests/Exceptions/general/EmptyExcept.qlref
index 3f4987046b12..7a046d008cd2 100644
--- a/python/ql/test/2/query-tests/Exceptions/general/EmptyExcept.qlref
+++ b/python/ql/test/2/query-tests/Exceptions/general/EmptyExcept.qlref
@@ -1 +1,2 @@
-Exceptions/EmptyExcept.ql
\ No newline at end of file
+query: Exceptions/EmptyExcept.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Exceptions/general/IncorrectExceptOrder.qlref b/python/ql/test/2/query-tests/Exceptions/general/IncorrectExceptOrder.qlref
index bc4c3a070813..f4278558baae 100644
--- a/python/ql/test/2/query-tests/Exceptions/general/IncorrectExceptOrder.qlref
+++ b/python/ql/test/2/query-tests/Exceptions/general/IncorrectExceptOrder.qlref
@@ -1 +1,2 @@
-Exceptions/IncorrectExceptOrder.ql
+query: Exceptions/IncorrectExceptOrder.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Exceptions/generators/UnguardedNextInGenerator.qlref b/python/ql/test/2/query-tests/Exceptions/generators/UnguardedNextInGenerator.qlref
index 7fe5d609705b..f174a4a96f57 100644
--- a/python/ql/test/2/query-tests/Exceptions/generators/UnguardedNextInGenerator.qlref
+++ b/python/ql/test/2/query-tests/Exceptions/generators/UnguardedNextInGenerator.qlref
@@ -1 +1,2 @@
-Exceptions/UnguardedNextInGenerator.ql
\ No newline at end of file
+query: Exceptions/UnguardedNextInGenerator.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Exceptions/generators/test.py b/python/ql/test/2/query-tests/Exceptions/generators/test.py
index e8b3f0b2b344..0c5ca29f798a 100644
--- a/python/ql/test/2/query-tests/Exceptions/generators/test.py
+++ b/python/ql/test/2/query-tests/Exceptions/generators/test.py
@@ -2,12 +2,12 @@
def bad1(it):
while True:
- yield next(it)
+ yield next(it) # $ Alert
def bad2(seq):
it = iter(seq)
#Not OK as seq may be empty
- raise KeyError(next(it))
+ raise KeyError(next(it)) # $ Alert
yield 0
def ok1(seq):
diff --git a/python/ql/test/2/query-tests/Exceptions/raising/RaisingTuple.qlref b/python/ql/test/2/query-tests/Exceptions/raising/RaisingTuple.qlref
index 55d1f5e1d4f9..1cefef85d8a5 100644
--- a/python/ql/test/2/query-tests/Exceptions/raising/RaisingTuple.qlref
+++ b/python/ql/test/2/query-tests/Exceptions/raising/RaisingTuple.qlref
@@ -1 +1,2 @@
-Exceptions/RaisingTuple.ql
+query: Exceptions/RaisingTuple.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Exceptions/raising/test.py b/python/ql/test/2/query-tests/Exceptions/raising/test.py
index ff991f642e2f..1e5f3cb35fca 100644
--- a/python/ql/test/2/query-tests/Exceptions/raising/test.py
+++ b/python/ql/test/2/query-tests/Exceptions/raising/test.py
@@ -5,11 +5,11 @@ def ok():
def bad1():
ex = Exception, "message"
- raise ex
+ raise ex # $ Alert
def bad2():
- raise (Exception, "message")
+ raise (Exception, "message") # $ Alert
def bad3():
ex = Exception,
- raise ex, "message"
+ raise ex, "message" # $ Alert
diff --git a/python/ql/test/2/query-tests/Expressions/UseofApply.py b/python/ql/test/2/query-tests/Expressions/UseofApply.py
index 9109636f99ec..6c2255012e6c 100644
--- a/python/ql/test/2/query-tests/Expressions/UseofApply.py
+++ b/python/ql/test/2/query-tests/Expressions/UseofApply.py
@@ -16,7 +16,7 @@ def foo():
# This use of `apply` is a reference to the builtin function and so SHOULD be
# caught by the query.
- apply(foo, [1])
+ apply(foo, [1]) # $ Alert[py/use-of-apply]
diff --git a/python/ql/test/2/query-tests/Expressions/UseofApply.qlref b/python/ql/test/2/query-tests/Expressions/UseofApply.qlref
index abf684e3918a..4add79acdb3c 100644
--- a/python/ql/test/2/query-tests/Expressions/UseofApply.qlref
+++ b/python/ql/test/2/query-tests/Expressions/UseofApply.qlref
@@ -1 +1,2 @@
-Expressions/UseofApply.ql
+query: Expressions/UseofApply.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Expressions/UseofInput.qlref b/python/ql/test/2/query-tests/Expressions/UseofInput.qlref
index 3f9590f48b2c..2684126de5ee 100644
--- a/python/ql/test/2/query-tests/Expressions/UseofInput.qlref
+++ b/python/ql/test/2/query-tests/Expressions/UseofInput.qlref
@@ -1 +1,2 @@
-Expressions/UseofInput.ql
\ No newline at end of file
+query: Expressions/UseofInput.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Expressions/expressions_test.py b/python/ql/test/2/query-tests/Expressions/expressions_test.py
index c31681e35353..6889822b7914 100644
--- a/python/ql/test/2/query-tests/Expressions/expressions_test.py
+++ b/python/ql/test/2/query-tests/Expressions/expressions_test.py
@@ -1,9 +1,9 @@
def use_of_apply(func, args):
- apply(func, args)
+ apply(func, args) # $ Alert[py/use-of-apply]
def use_of_input():
- return input() # NOT OK
+ return input() # $ Alert[py/use-of-input] # NOT OK
def not_use_of_input():
diff --git a/python/ql/test/2/query-tests/Functions/DeprecatedSliceMethod.qlref b/python/ql/test/2/query-tests/Functions/DeprecatedSliceMethod.qlref
index c38b8d1f7619..3043411c1ce4 100644
--- a/python/ql/test/2/query-tests/Functions/DeprecatedSliceMethod.qlref
+++ b/python/ql/test/2/query-tests/Functions/DeprecatedSliceMethod.qlref
@@ -1 +1,2 @@
-Functions/DeprecatedSliceMethod.ql
\ No newline at end of file
+query: Functions/DeprecatedSliceMethod.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Imports/encoding_error/EncodingError.qlref b/python/ql/test/2/query-tests/Imports/encoding_error/EncodingError.qlref
index a7e91769ded1..bc78d28db329 100644
--- a/python/ql/test/2/query-tests/Imports/encoding_error/EncodingError.qlref
+++ b/python/ql/test/2/query-tests/Imports/encoding_error/EncodingError.qlref
@@ -1 +1,2 @@
-Imports/EncodingError.ql
+query: Imports/EncodingError.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Imports/syntax_error/EncodingError.qlref b/python/ql/test/2/query-tests/Imports/syntax_error/EncodingError.qlref
index e742356f8658..bc78d28db329 100644
--- a/python/ql/test/2/query-tests/Imports/syntax_error/EncodingError.qlref
+++ b/python/ql/test/2/query-tests/Imports/syntax_error/EncodingError.qlref
@@ -1 +1,2 @@
-Imports/EncodingError.ql
\ No newline at end of file
+query: Imports/EncodingError.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Imports/syntax_error/SyntaxError.qlref b/python/ql/test/2/query-tests/Imports/syntax_error/SyntaxError.qlref
index c143a01fe8b3..5d0698be3de5 100644
--- a/python/ql/test/2/query-tests/Imports/syntax_error/SyntaxError.qlref
+++ b/python/ql/test/2/query-tests/Imports/syntax_error/SyntaxError.qlref
@@ -1 +1,2 @@
-Imports/SyntaxError.ql
\ No newline at end of file
+query: Imports/SyntaxError.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Imports/syntax_error/bad_encoding.py b/python/ql/test/2/query-tests/Imports/syntax_error/bad_encoding.py
index 9c61b1e1b114..5e3308df0f57 100644
--- a/python/ql/test/2/query-tests/Imports/syntax_error/bad_encoding.py
+++ b/python/ql/test/2/query-tests/Imports/syntax_error/bad_encoding.py
@@ -8,5 +8,5 @@
# encoding:shift-jis
def f():
- print "Python の開発は、1990 年ごろから開始されています"
+ print "Python の開発は、1990 年ごろから開始されています" # $ Alert[py/encoding-error]
"""
diff --git a/python/ql/test/2/query-tests/Imports/syntax_error/nonsense.py b/python/ql/test/2/query-tests/Imports/syntax_error/nonsense.py
index e413967af412..f5cd27b313b6 100644
--- a/python/ql/test/2/query-tests/Imports/syntax_error/nonsense.py
+++ b/python/ql/test/2/query-tests/Imports/syntax_error/nonsense.py
@@ -1,4 +1,4 @@
-`Twas brillig, and the slithy toves
+`Twas brillig, and the slithy toves # $ Alert[py/syntax-error]
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.
diff --git a/python/ql/test/2/query-tests/Lexical/OldOctalLiteral.qlref b/python/ql/test/2/query-tests/Lexical/OldOctalLiteral.qlref
index 40040c873d63..e5b4fdfec578 100644
--- a/python/ql/test/2/query-tests/Lexical/OldOctalLiteral.qlref
+++ b/python/ql/test/2/query-tests/Lexical/OldOctalLiteral.qlref
@@ -1 +1,2 @@
-Lexical/OldOctalLiteral.ql
\ No newline at end of file
+query: Lexical/OldOctalLiteral.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Lexical/lexical_test.py b/python/ql/test/2/query-tests/Lexical/lexical_test.py
index 4b82b17cc65f..412c24683d19 100644
--- a/python/ql/test/2/query-tests/Lexical/lexical_test.py
+++ b/python/ql/test/2/query-tests/Lexical/lexical_test.py
@@ -1,6 +1,6 @@
#Bad Octal literal
-017
+017 # $ Alert
#Good Octal literal
0o17
#Special case file permissions
diff --git a/python/ql/test/2/query-tests/Statements/ExecUsed.qlref b/python/ql/test/2/query-tests/Statements/ExecUsed.qlref
index ccff89d6815f..286996305ed1 100644
--- a/python/ql/test/2/query-tests/Statements/ExecUsed.qlref
+++ b/python/ql/test/2/query-tests/Statements/ExecUsed.qlref
@@ -1 +1,2 @@
-Statements/ExecUsed.ql
\ No newline at end of file
+query: Statements/ExecUsed.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Statements/TopLevelPrint.qlref b/python/ql/test/2/query-tests/Statements/TopLevelPrint.qlref
index 8271065261d0..e91717901f3d 100644
--- a/python/ql/test/2/query-tests/Statements/TopLevelPrint.qlref
+++ b/python/ql/test/2/query-tests/Statements/TopLevelPrint.qlref
@@ -1 +1,2 @@
-Statements/TopLevelPrint.ql
\ No newline at end of file
+query: Statements/TopLevelPrint.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Statements/module.py b/python/ql/test/2/query-tests/Statements/module.py
index 0b1f4d26546b..af34eedf0dc3 100644
--- a/python/ql/test/2/query-tests/Statements/module.py
+++ b/python/ql/test/2/query-tests/Statements/module.py
@@ -1,2 +1,2 @@
#Top level prints in modules are bad
-print ("Side effect on import")
\ No newline at end of file
+print ("Side effect on import") # $ Alert[py/print-during-import]
\ No newline at end of file
diff --git a/python/ql/test/2/query-tests/Statements/statements_test.py b/python/ql/test/2/query-tests/Statements/statements_test.py
index e540608964d2..46e91c25c311 100644
--- a/python/ql/test/2/query-tests/Statements/statements_test.py
+++ b/python/ql/test/2/query-tests/Statements/statements_test.py
@@ -2,7 +2,7 @@
def exec_used(val):
- exec (val)
+ exec (val) # $ Alert[py/use-of-exec]
#Top level print
import module
diff --git a/python/ql/test/2/query-tests/Variables/LeakyComp/LeakyComp.qlref b/python/ql/test/2/query-tests/Variables/LeakyComp/LeakyComp.qlref
index 0f6dd50a2814..6b4ece7f1273 100644
--- a/python/ql/test/2/query-tests/Variables/LeakyComp/LeakyComp.qlref
+++ b/python/ql/test/2/query-tests/Variables/LeakyComp/LeakyComp.qlref
@@ -1 +1,2 @@
-Variables/LeakingListComprehension.ql
\ No newline at end of file
+query: Variables/LeakingListComprehension.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/2/query-tests/Variables/LeakyComp/test.py b/python/ql/test/2/query-tests/Variables/LeakyComp/test.py
index 0cd6a0d25202..bbb5d33328f8 100644
--- a/python/ql/test/2/query-tests/Variables/LeakyComp/test.py
+++ b/python/ql/test/2/query-tests/Variables/LeakyComp/test.py
@@ -2,12 +2,12 @@
def undefined_in_3():
[x for x in range(3)]
- print(x)
+ print(x) # $ Alert
def different_in_3():
y = 10
[y for y in range(3)]
- print(y)
+ print(y) # $ Alert
def ok():
[z for z in range(4)]
diff --git a/python/ql/test/3/query-tests/Expressions/UseofApply/UseofApply.qlref b/python/ql/test/3/query-tests/Expressions/UseofApply/UseofApply.qlref
index abf684e3918a..4add79acdb3c 100644
--- a/python/ql/test/3/query-tests/Expressions/UseofApply/UseofApply.qlref
+++ b/python/ql/test/3/query-tests/Expressions/UseofApply/UseofApply.qlref
@@ -1 +1,2 @@
-Expressions/UseofApply.ql
+query: Expressions/UseofApply.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/3/query-tests/Imports/encoding_error/EncodingError.qlref b/python/ql/test/3/query-tests/Imports/encoding_error/EncodingError.qlref
index a7e91769ded1..bc78d28db329 100644
--- a/python/ql/test/3/query-tests/Imports/encoding_error/EncodingError.qlref
+++ b/python/ql/test/3/query-tests/Imports/encoding_error/EncodingError.qlref
@@ -1 +1,2 @@
-Imports/EncodingError.ql
+query: Imports/EncodingError.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/3/query-tests/Imports/syntax_error/EncodingError.qlref b/python/ql/test/3/query-tests/Imports/syntax_error/EncodingError.qlref
index e742356f8658..bc78d28db329 100644
--- a/python/ql/test/3/query-tests/Imports/syntax_error/EncodingError.qlref
+++ b/python/ql/test/3/query-tests/Imports/syntax_error/EncodingError.qlref
@@ -1 +1,2 @@
-Imports/EncodingError.ql
\ No newline at end of file
+query: Imports/EncodingError.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/3/query-tests/Imports/syntax_error/SyntaxError.qlref b/python/ql/test/3/query-tests/Imports/syntax_error/SyntaxError.qlref
index c143a01fe8b3..5d0698be3de5 100644
--- a/python/ql/test/3/query-tests/Imports/syntax_error/SyntaxError.qlref
+++ b/python/ql/test/3/query-tests/Imports/syntax_error/SyntaxError.qlref
@@ -1 +1,2 @@
-Imports/SyntaxError.ql
\ No newline at end of file
+query: Imports/SyntaxError.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/3/query-tests/Imports/syntax_error/bad_encoding.py b/python/ql/test/3/query-tests/Imports/syntax_error/bad_encoding.py
index 9c61b1e1b114..5e3308df0f57 100644
--- a/python/ql/test/3/query-tests/Imports/syntax_error/bad_encoding.py
+++ b/python/ql/test/3/query-tests/Imports/syntax_error/bad_encoding.py
@@ -8,5 +8,5 @@
# encoding:shift-jis
def f():
- print "Python の開発は、1990 年ごろから開始されています"
+ print "Python の開発は、1990 年ごろから開始されています" # $ Alert[py/encoding-error]
"""
diff --git a/python/ql/test/3/query-tests/Imports/syntax_error/nonsense.py b/python/ql/test/3/query-tests/Imports/syntax_error/nonsense.py
index 66cdd526fbab..e0819afbc5ee 100644
--- a/python/ql/test/3/query-tests/Imports/syntax_error/nonsense.py
+++ b/python/ql/test/3/query-tests/Imports/syntax_error/nonsense.py
@@ -1,4 +1,4 @@
- `Twas brillig, and the slithy toves
+ `Twas brillig, and the slithy toves # $ Alert[py/syntax-error]
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.
diff --git a/python/ql/test/3/query-tests/Statements/general/ExecUsed.qlref b/python/ql/test/3/query-tests/Statements/general/ExecUsed.qlref
index ccff89d6815f..286996305ed1 100644
--- a/python/ql/test/3/query-tests/Statements/general/ExecUsed.qlref
+++ b/python/ql/test/3/query-tests/Statements/general/ExecUsed.qlref
@@ -1 +1,2 @@
-Statements/ExecUsed.ql
\ No newline at end of file
+query: Statements/ExecUsed.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/3/query-tests/Statements/general/TopLevelPrint.qlref b/python/ql/test/3/query-tests/Statements/general/TopLevelPrint.qlref
index 8271065261d0..e91717901f3d 100644
--- a/python/ql/test/3/query-tests/Statements/general/TopLevelPrint.qlref
+++ b/python/ql/test/3/query-tests/Statements/general/TopLevelPrint.qlref
@@ -1 +1,2 @@
-Statements/TopLevelPrint.ql
\ No newline at end of file
+query: Statements/TopLevelPrint.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/3/query-tests/Statements/general/module.py b/python/ql/test/3/query-tests/Statements/general/module.py
index 0b1f4d26546b..af34eedf0dc3 100644
--- a/python/ql/test/3/query-tests/Statements/general/module.py
+++ b/python/ql/test/3/query-tests/Statements/general/module.py
@@ -1,2 +1,2 @@
#Top level prints in modules are bad
-print ("Side effect on import")
\ No newline at end of file
+print ("Side effect on import") # $ Alert[py/print-during-import]
\ No newline at end of file
diff --git a/python/ql/test/3/query-tests/Statements/general/statements_test.py b/python/ql/test/3/query-tests/Statements/general/statements_test.py
index 2baee458c04c..a4414a40f80c 100644
--- a/python/ql/test/3/query-tests/Statements/general/statements_test.py
+++ b/python/ql/test/3/query-tests/Statements/general/statements_test.py
@@ -2,7 +2,7 @@
def exec_used(val):
- exec(val)
+ exec(val) # $ Alert[py/use-of-exec]
#Top level print
import module
diff --git a/python/ql/test/3/query-tests/Statements/unreachable/UnreachableCode.qlref b/python/ql/test/3/query-tests/Statements/unreachable/UnreachableCode.qlref
index 5b7891f0026a..b95a67d24949 100644
--- a/python/ql/test/3/query-tests/Statements/unreachable/UnreachableCode.qlref
+++ b/python/ql/test/3/query-tests/Statements/unreachable/UnreachableCode.qlref
@@ -1 +1,2 @@
-Statements/UnreachableCode.ql
+query: Statements/UnreachableCode.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/3/query-tests/Statements/unreachable_suppressed/UnreachableCode.qlref b/python/ql/test/3/query-tests/Statements/unreachable_suppressed/UnreachableCode.qlref
index 5b7891f0026a..b95a67d24949 100644
--- a/python/ql/test/3/query-tests/Statements/unreachable_suppressed/UnreachableCode.qlref
+++ b/python/ql/test/3/query-tests/Statements/unreachable_suppressed/UnreachableCode.qlref
@@ -1 +1,2 @@
-Statements/UnreachableCode.ql
+query: Statements/UnreachableCode.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Classes/Naming/NamingConventionsClasses.py b/python/ql/test/experimental/query-tests/Classes/Naming/NamingConventionsClasses.py
index c07bdb57234a..46633a009f72 100644
--- a/python/ql/test/experimental/query-tests/Classes/Naming/NamingConventionsClasses.py
+++ b/python/ql/test/experimental/query-tests/Classes/Naming/NamingConventionsClasses.py
@@ -1,5 +1,5 @@
# BAD, do not start class or interface name with lowercase letter
-class badName:
+class badName: # $ Alert
def hello(self):
print("hello")
diff --git a/python/ql/test/experimental/query-tests/Classes/Naming/NamingConventionsClasses.qlref b/python/ql/test/experimental/query-tests/Classes/Naming/NamingConventionsClasses.qlref
index 7ed945d782c4..b5b73c19bf81 100644
--- a/python/ql/test/experimental/query-tests/Classes/Naming/NamingConventionsClasses.qlref
+++ b/python/ql/test/experimental/query-tests/Classes/Naming/NamingConventionsClasses.qlref
@@ -1 +1,2 @@
-experimental/Classes/NamingConventionsClasses.ql
\ No newline at end of file
+query: experimental/Classes/NamingConventionsClasses.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Functions/general/NamingConventionsFunctions.py b/python/ql/test/experimental/query-tests/Functions/general/NamingConventionsFunctions.py
index fb3e89ab8e92..5923ce5919f3 100644
--- a/python/ql/test/experimental/query-tests/Functions/general/NamingConventionsFunctions.py
+++ b/python/ql/test/experimental/query-tests/Functions/general/NamingConventionsFunctions.py
@@ -1,7 +1,7 @@
class Test:
# BAD, do not start function name with uppercase letter
- def HelloWorld(self):
+ def HelloWorld(self): # $ Alert
print("hello world")
# GOOD, function name starts with lowercase letter
diff --git a/python/ql/test/experimental/query-tests/Functions/general/NamingConventionsFunctions.qlref b/python/ql/test/experimental/query-tests/Functions/general/NamingConventionsFunctions.qlref
index 0204694de0a3..21d3e5fe1358 100644
--- a/python/ql/test/experimental/query-tests/Functions/general/NamingConventionsFunctions.qlref
+++ b/python/ql/test/experimental/query-tests/Functions/general/NamingConventionsFunctions.qlref
@@ -1 +1,2 @@
-experimental/Functions/NamingConventionsFunctions.ql
\ No newline at end of file
+query: experimental/Functions/NamingConventionsFunctions.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/TarSlip.qlref b/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/TarSlip.qlref
index a518196b6982..2842a87d0803 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/TarSlip.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/TarSlip.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-022bis/TarSlipImprov.ql
+query: experimental/Security/CWE-022bis/TarSlipImprov.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/TarSlipImprov.py b/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/TarSlipImprov.py
index 15bc66b4aea5..3b59f24e4026 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/TarSlipImprov.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/TarSlipImprov.py
@@ -12,14 +12,14 @@
unsafe_filename_tar = sys.argv[2]
safe_filename_tar = "safe_path.tar"
-tar = tarfile.open(unsafe_filename_tar)
+tar = tarfile.open(unsafe_filename_tar) # $ Source[py/tarslip-extended]
result = []
for member in tar:
if ".." in member.name:
raise ValueError("Path in member name !!!")
result.append(member)
path = unsafe_filename_tar
-tar.extractall(path=path, members=result)
+tar.extractall(path=path, members=result) # $ Alert[py/tarslip-extended]
tar.close()
@@ -35,27 +35,27 @@ def members_filter1(tarfile):
result.append(member)
return result
-tar = tarfile.open(unsafe_filename_tar)
-tar.extractall(path=tempfile.mkdtemp(), members=members_filter1(tar))
+tar = tarfile.open(unsafe_filename_tar) # $ Source[py/tarslip-extended]
+tar.extractall(path=tempfile.mkdtemp(), members=members_filter1(tar)) # $ Alert[py/tarslip-extended]
tar.close()
-with tarfile.open(unsafe_filename_tar) as tar:
+with tarfile.open(unsafe_filename_tar) as tar: # $ Source[py/tarslip-extended]
for entry in tar:
if ".." in entry.name:
raise ValueError("Illegal tar archive entry")
- tar.extract(entry, "/tmp/unpack/")
+ tar.extract(entry, "/tmp/unpack/") # $ Alert[py/tarslip-extended]
def _validate_archive_name(name, target):
if not os.path.abspath(os.path.join(target, name)).startswith(target + os.path.sep):
raise ValueError(f"Provided language pack contains invalid name {name}")
-with tarfile.open(unsafe_filename_tar) as tar:
+with tarfile.open(unsafe_filename_tar) as tar: # $ Source[py/tarslip-extended]
target = "/tmp/unpack"
for entry in tar:
_validate_archive_name(entry.name, target)
- tar.extract(entry, target)
+ tar.extract(entry, target) # $ Alert[py/tarslip-extended]
def members_filter2(tarfile):
@@ -85,10 +85,10 @@ def _validate_archive_name(name, target):
raise ValueError(f"Provided language pack contains invalid name {name}")
target = "/tmp/unpack"
-with tarfile.open(unsafe_filename_tar, "r") as tar:
+with tarfile.open(unsafe_filename_tar, "r") as tar: # $ Source[py/tarslip-extended]
for info in tar.getmembers():
_validate_tar_info(info, target)
- tar.extractall(target)
+ tar.extractall(target) # $ Alert[py/tarslip-extended]
def members_filter3(tarfile):
@@ -108,11 +108,11 @@ def members_filter3(tarfile):
tar.close()
-tar = tarfile.open(unsafe_filename_tar)
+tar = tarfile.open(unsafe_filename_tar) # $ Source[py/tarslip-extended]
tarf = tar.getmembers()
for f in tarf:
if not f.issym():
- tar.extractall(path=tempfile.mkdtemp(), members=[f])
+ tar.extractall(path=tempfile.mkdtemp(), members=[f]) # $ Alert[py/tarslip-extended]
tar.close()
@@ -120,27 +120,27 @@ class MKTar(TarFile):
pass
tarball = unsafe_filename_tar
-with MKTar.open(name=tarball) as tar:
+with MKTar.open(name=tarball) as tar: # $ Source[py/tarslip-extended]
for entry in tar:
- tar._extract_member(entry, entry.name)
+ tar._extract_member(entry, entry.name) # $ Alert[py/tarslip-extended]
tarball = unsafe_filename_tar
-with tarfile.open(tarball) as tar:
- tar.extractall()
+with tarfile.open(tarball) as tar: # $ Source[py/tarslip-extended]
+ tar.extractall() # $ Alert[py/tarslip-extended]
-tar = tarfile.open(unsafe_filename_tar)
-tar.extractall(path=tempfile.mkdtemp(), members=None)
+tar = tarfile.open(unsafe_filename_tar) # $ Source[py/tarslip-extended]
+tar.extractall(path=tempfile.mkdtemp(), members=None) # $ Alert[py/tarslip-extended]
class MKTar(tarfile.TarFile):
pass
tarball = unsafe_filename_tar
-with MKTar.open(name=tarball) as tar:
+with MKTar.open(name=tarball) as tar: # $ Source[py/tarslip-extended]
for entry in tar:
- tar._extract_member(entry, entry.name)
+ tar._extract_member(entry, entry.name) # $ Alert[py/tarslip-extended]
@contextmanager
@@ -148,7 +148,7 @@ def py2_tarxz(filename):
with tempfile.TemporaryFile() as tmp:
subprocess.check_call(["xz", "-dc", filename], stdout=tmp.fileno())
tmp.seek(0)
- with closing(tarfile.TarFile(fileobj=tmp)) as tf:
+ with closing(tarfile.TarFile(fileobj=tmp)) as tf: # $ Source[py/tarslip-extended]
yield tf
def unpack_tarball(tar_filename, dest):
@@ -156,7 +156,7 @@ def unpack_tarball(tar_filename, dest):
# Py 2.7 lacks lzma support
tar_cm = py2_tarxz(tar_filename)
else:
- tar_cm = closing(tarfile.open(tar_filename))
+ tar_cm = closing(tarfile.open(tar_filename)) # $ Source[py/tarslip-extended]
base_dir = None
with tar_cm as tarc:
@@ -166,32 +166,32 @@ def unpack_tarball(tar_filename, dest):
base_dir = base_name
elif base_dir != base_name:
print('Unexpected path in %s: %s' % (tar_filename, base_name))
- tarc.extractall(dest)
+ tarc.extractall(dest) # $ Alert[py/tarslip-extended]
return os.path.join(dest, base_dir)
unpack_tarball(unsafe_filename_tar, "/tmp/unpack")
tarball = unsafe_filename_tar
-with tarfile.open(name=tarball) as tar:
+with tarfile.open(name=tarball) as tar: # $ Source[py/tarslip-extended]
for entry in tar:
- tar._extract_member(entry, entry.name)
+ tar._extract_member(entry, entry.name) # $ Alert[py/tarslip-extended]
tarball = unsafe_filename_tar
-with tarfile.open(name=tarball) as tar:
+with tarfile.open(name=tarball) as tar: # $ Source[py/tarslip-extended]
for entry in tar:
- tar.extract(entry, "/tmp/unpack/")
+ tar.extract(entry, "/tmp/unpack/") # $ Alert[py/tarslip-extended]
tarball = unsafe_filename_tar
-tar = tarfile.open(tarball)
-tar.extractall("/tmp/unpack/")
+tar = tarfile.open(tarball) # $ Source[py/tarslip-extended]
+tar.extractall("/tmp/unpack/") # $ Alert[py/tarslip-extended]
tarball = unsafe_filename_tar
-with tarfile.open(tarball, "r") as tar:
- tar.extractall(path="/tmp/unpack/", members=tar)
+with tarfile.open(tarball, "r") as tar: # $ Source[py/tarslip-extended]
+ tar.extractall(path="/tmp/unpack/", members=tar) # $ Alert[py/tarslip-extended]
def members_filter4(tarfile):
@@ -207,8 +207,8 @@ def members_filter4(tarfile):
tar.close()
-with tarfile.open(unsafe_filename_tar, "r") as tar:
- tar.extractall(path="/tmp/unpack")
+with tarfile.open(unsafe_filename_tar, "r") as tar: # $ Source[py/tarslip-extended]
+ tar.extractall(path="/tmp/unpack") # $ Alert[py/tarslip-extended]
def members_filter5(tarfile):
@@ -228,12 +228,12 @@ def members_filter5(tarfile):
tmp_dir = "/tmp/"
read_type = "r:gz" if filename.endswith("tgz") else "r"
-with tarfile.open(filename, read_type) as corpus_tar:
+with tarfile.open(filename, read_type) as corpus_tar: # $ Source[py/tarslip-extended]
members = []
for f in corpus_tar:
if not os.path.isfile(os.path.join(tmp_dir, f.name)):
members.append(f)
- corpus_tar.extractall(tmp_dir, members=members)
+ corpus_tar.extractall(tmp_dir, members=members) # $ Alert[py/tarslip-extended]
def members_filter6(tarfile):
@@ -251,66 +251,66 @@ def members_filter6(tarfile):
archive_path = unsafe_filename_tar
target_dir = "/tmp/unpack"
-tarfile.open(archive_path, "r").extractall(path=target_dir)
+tarfile.open(archive_path, "r").extractall(path=target_dir) # $ Alert[py/tarslip-extended]
tarball = unsafe_filename_tar
-with tarfile.open(tarball) as tar:
+with tarfile.open(tarball) as tar: # $ Source[py/tarslip-extended]
for entry in tar:
if entry.isfile():
- tar.extract(entry, "/tmp/unpack/")
+ tar.extract(entry, "/tmp/unpack/") # $ Alert[py/tarslip-extended]
-with tarfile.open(unsafe_filename_tar) as tar:
+with tarfile.open(unsafe_filename_tar) as tar: # $ Source[py/tarslip-extended]
for entry in tar:
if entry.name.startswith("/"):
raise ValueError("Illegal tar archive entry")
- tar.extract(entry, "/tmp/unpack/")
+ tar.extract(entry, "/tmp/unpack/") # $ Alert[py/tarslip-extended]
tarball = unsafe_filename_tar
-with tarfile.TarFile(tarball, mode="r") as tar:
+with tarfile.TarFile(tarball, mode="r") as tar: # $ Source[py/tarslip-extended]
for entry in tar:
if entry.isfile():
- tar.extract(entry, "/tmp/unpack/")
+ tar.extract(entry, "/tmp/unpack/") # $ Alert[py/tarslip-extended]
-with tarfile.open(unsafe_filename_tar) as tar:
+with tarfile.open(unsafe_filename_tar) as tar: # $ Source[py/tarslip-extended]
for entry in tar:
if os.path.isabs(entry.name):
raise ValueError("Illegal tar archive entry")
- tar.extract(entry, "/tmp/unpack/")
+ tar.extract(entry, "/tmp/unpack/") # $ Alert[py/tarslip-extended]
-with tarfile.TarFile(unsafe_filename_tar, mode="r") as tar:
- tar.extractall(path="/tmp/unpack")
+with tarfile.TarFile(unsafe_filename_tar, mode="r") as tar: # $ Source[py/tarslip-extended]
+ tar.extractall(path="/tmp/unpack") # $ Alert[py/tarslip-extended]
-tar = tarfile.open(filename)
-tar.extractall(path=tempfile.mkdtemp(), members=tar.getmembers())
+tar = tarfile.open(filename) # $ Source[py/tarslip-extended]
+tar.extractall(path=tempfile.mkdtemp(), members=tar.getmembers()) # $ Alert[py/tarslip-extended]
tar.close()
-tar = tarfile.open(unsafe_filename_tar)
-tar.extractall(path=tempfile.mkdtemp(), members=None)
+tar = tarfile.open(unsafe_filename_tar) # $ Source[py/tarslip-extended]
+tar.extractall(path=tempfile.mkdtemp(), members=None) # $ Alert[py/tarslip-extended]
tar.extractall(path=tempfile.mkdtemp(), members=members_filter4(tar))
tar.close()
-with tarfile.TarFile(unsafe_filename_tar, mode="r") as tar:
- tar.extractall(path="/tmp/unpack/", members=tar)
+with tarfile.TarFile(unsafe_filename_tar, mode="r") as tar: # $ Source[py/tarslip-extended]
+ tar.extractall(path="/tmp/unpack/", members=tar) # $ Alert[py/tarslip-extended]
-tar = tarfile.open(unsafe_filename_tar)
+tar = tarfile.open(unsafe_filename_tar) # $ Source[py/tarslip-extended]
result = []
for member in tar:
if member.issym():
raise ValueError("But it is a symlink")
result.append(member)
-tar.extractall(path=tempfile.mkdtemp(), members=result)
+tar.extractall(path=tempfile.mkdtemp(), members=result) # $ Alert[py/tarslip-extended]
tar.close()
archive_path = unsafe_filename_tar
target_dir = "/tmp/unpack"
-tarfile.TarFile(unsafe_filename_tar, mode="r").extractall(path=target_dir)
\ No newline at end of file
+tarfile.TarFile(unsafe_filename_tar, mode="r").extractall(path=target_dir) # $ Alert[py/tarslip-extended]
\ No newline at end of file
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/ZipSlip.qlref b/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/ZipSlip.qlref
index 717dc9d0f105..177a74d6bd74 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/ZipSlip.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/ZipSlip.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-022/ZipSlip.ql
+query: experimental/Security/CWE-022/ZipSlip.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/zipslip_bad.py b/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/zipslip_bad.py
index c622ead874cb..4e7195cf856d 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/zipslip_bad.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-022-TarSlip/zipslip_bad.py
@@ -5,35 +5,35 @@
import zipfile
def unzip(filename):
- with tarfile.open(filename) as zipf:
+ with tarfile.open(filename) as zipf: # $ Alert[py/zipslip]
#BAD : This could write any file on the filesystem.
for entry in zipf:
- shutil.move(entry, "/tmp/unpack/")
+ shutil.move(entry, "/tmp/unpack/") # $ Sink[py/zipslip]
def unzip1(filename):
- with gzip.open(filename) as zipf:
+ with gzip.open(filename) as zipf: # $ Alert[py/zipslip]
#BAD : This could write any file on the filesystem.
for entry in zipf:
- shutil.copy2(entry, "/tmp/unpack/")
+ shutil.copy2(entry, "/tmp/unpack/") # $ Sink[py/zipslip]
def unzip2(filename):
- with bz2.open(filename) as zipf:
+ with bz2.open(filename) as zipf: # $ Alert[py/zipslip]
#BAD : This could write any file on the filesystem.
for entry in zipf:
- shutil.copyfile(entry, "/tmp/unpack/")
+ shutil.copyfile(entry, "/tmp/unpack/") # $ Sink[py/zipslip]
def unzip3(filename):
zf = zipfile.ZipFile(filename)
- with zf.namelist() as filelist:
+ with zf.namelist() as filelist: # $ Alert[py/zipslip]
#BAD : This could write any file on the filesystem.
for x in filelist:
- shutil.copy(x, "/tmp/unpack/")
+ shutil.copy(x, "/tmp/unpack/") # $ Sink[py/zipslip]
def unzip4(filename):
zf = zipfile.ZipFile(filename)
- filelist = zf.namelist()
+ filelist = zf.namelist() # $ Alert[py/zipslip]
for x in filelist:
with zf.open(x) as srcf:
- shutil.copyfileobj(x, "/tmp/unpack/")
+ shutil.copyfileobj(x, "/tmp/unpack/") # $ Sink[py/zipslip]
import tty # to set the import root so we can identify the standard library
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/AsyncSsh.py b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/AsyncSsh.py
index 492c8a0f1deb..fe41e75e0643 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/AsyncSsh.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/AsyncSsh.py
@@ -12,8 +12,8 @@
session.userauth_password("user", "password")
@app.get("/bad1")
-async def bad1(cmd: str):
+async def bad1(cmd: str): # $ Source
async with asyncssh.connect('localhost') as conn:
- result = await conn.run(cmd, check=True) # $ result=BAD getRemoteCommand=cmd
+ result = await conn.run(cmd, check=True) # $ Alert result=BAD getRemoteCommand=cmd
print(result.stdout, end='')
return {"success": "Dangerous"}
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Netmiko.py b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Netmiko.py
index dd12357214dc..75b6be33baa4 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Netmiko.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Netmiko.py
@@ -15,11 +15,11 @@
}
@app.get("/bad1")
-async def bad1(cmd: str):
+async def bad1(cmd: str): # $ Source
net_connect = ConnectHandler(**cisco_881)
- net_connect.send_command(command_string=cmd) # $ result=BAD getRemoteCommand=cmd
- net_connect.send_command_expect(command_string=cmd) # $ result=BAD getRemoteCommand=cmd
- net_connect.send_command_timing(command_string=cmd) # $ result=BAD getRemoteCommand=cmd
- net_connect.send_multiline(commands=[[cmd, "expect"]]) # $ result=BAD getRemoteCommand=List
- net_connect.send_multiline_timing(commands=cmd) # $ result=BAD getRemoteCommand=cmd
+ net_connect.send_command(command_string=cmd) # $ Alert result=BAD getRemoteCommand=cmd
+ net_connect.send_command_expect(command_string=cmd) # $ Alert result=BAD getRemoteCommand=cmd
+ net_connect.send_command_timing(command_string=cmd) # $ Alert result=BAD getRemoteCommand=cmd
+ net_connect.send_multiline(commands=[[cmd, "expect"]]) # $ Alert result=BAD getRemoteCommand=List
+ net_connect.send_multiline_timing(commands=cmd) # $ Alert result=BAD getRemoteCommand=cmd
return {"success": "Dangerous"}
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Pexpect.py b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Pexpect.py
index f2b05a075c94..4615bbc0246e 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Pexpect.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Pexpect.py
@@ -12,10 +12,10 @@
app = FastAPI()
@app.get("/bad1")
-async def bad1(cmd: str):
- ssh.send(cmd) # $ result=BAD getRemoteCommand=cmd
+async def bad1(cmd: str): # $ Source
+ ssh.send(cmd) # $ Alert result=BAD getRemoteCommand=cmd
ssh.prompt()
- ssh.sendline(cmd) # $ result=BAD getRemoteCommand=cmd
+ ssh.sendline(cmd) # $ Alert result=BAD getRemoteCommand=cmd
ssh.prompt()
ssh.logout()
return {"success": stdout}
\ No newline at end of file
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/RemoteCommandExecution.qlref b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/RemoteCommandExecution.qlref
index dc5c7028f329..b95082533a7c 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/RemoteCommandExecution.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/RemoteCommandExecution.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-074/remoteCommandExecution/RemoteCommandExecution.ql
\ No newline at end of file
+query: experimental/Security/CWE-074/remoteCommandExecution/RemoteCommandExecution.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Scrapli.py b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Scrapli.py
index 47abfb2f669a..985028aebec3 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Scrapli.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Scrapli.py
@@ -10,7 +10,7 @@
app = FastAPI()
@app.get("/bad1")
-async def bad1(cmd: str):
+async def bad1(cmd: str): # $ Source
dev_connect = {
"host": host,
"auth_username": user,
@@ -21,23 +21,23 @@ async def bad1(cmd: str):
}
driver = AsyncIOSXEDriver
async with driver(**dev_connect) as conn:
- output = await conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ output = await conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
driver = AsyncIOSXRDriver
async with driver(**dev_connect) as conn:
- output = await conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ output = await conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
driver = AsyncNXOSDriver
async with driver(**dev_connect) as conn:
- output = await conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ output = await conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
driver = AsyncEOSDriver
async with driver(**dev_connect) as conn:
- output = await conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ output = await conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
driver = AsyncJunosDriver
async with driver(**dev_connect) as conn:
- output = await conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ output = await conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
return {"success": "Dangerous"}
@app.get("/bad1")
-def bad2(cmd: str):
+def bad2(cmd: str): # $ Source
dev_connect = {
"host": host,
"auth_username": user,
@@ -48,19 +48,19 @@ def bad2(cmd: str):
}
driver = NXOSDriver
with driver(**dev_connect) as conn:
- output = conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ output = conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
driver = IOSXRDriver
with driver(**dev_connect) as conn:
- output = conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ output = conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
driver = IOSXEDriver
with driver(**dev_connect) as conn:
- output = conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ output = conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
driver = EOSDriver
with driver(**dev_connect) as conn:
- output = conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ output = conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
driver = JunosDriver
with driver(**dev_connect) as conn:
- output = conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ output = conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
dev_connect = {
"host": "65.65.65.65",
@@ -71,7 +71,7 @@ def bad2(cmd: str):
"platform": "cisco_iosxe",
}
with Scrapli(**dev_connect) as conn:
- result = conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ result = conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
dev_connect = {
"host": "65.65.65.65",
@@ -81,5 +81,5 @@ def bad2(cmd: str):
"transport": "ssh2",
}
with GenericDriver(**dev_connect) as conn:
- result = conn.send_command(cmd) # $ result=BAD getRemoteCommand=cmd
+ result = conn.send_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
return {"success": "Dangerous"}
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Twisted.py b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Twisted.py
index 016745e9e02b..c9718853b4e7 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Twisted.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/Twisted.py
@@ -10,10 +10,10 @@
@app.get("/bad1")
-async def bad1(cmd: bytes):
+async def bad1(cmd: bytes): # $ Source
endpoint = SSHCommandClientEndpoint.newConnection(
reactor,
- cmd, # $ result=BAD getRemoteCommand=cmd
+ cmd, # $ Alert result=BAD getRemoteCommand=cmd
b"username",
b"ssh.example.com",
22,
@@ -21,7 +21,7 @@ async def bad1(cmd: bytes):
SSHCommandClientEndpoint.existingConnection(
endpoint,
- cmd) # $ result=BAD getRemoteCommand=cmd
+ cmd) # $ Alert result=BAD getRemoteCommand=cmd
factory = Factory()
d = endpoint.connect(factory)
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/paramiko.py b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/paramiko.py
index e1c17362bebd..f4997f90116f 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/paramiko.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/paramiko.py
@@ -12,11 +12,11 @@
@app.get("/bad1")
-async def bad1(cmd: str):
- stdin, stdout, stderr = paramiko_ssh_client.exec_command(cmd) # $ result=BAD getRemoteCommand=cmd
+async def bad1(cmd: str): # $ Source
+ stdin, stdout, stderr = paramiko_ssh_client.exec_command(cmd) # $ Alert result=BAD getRemoteCommand=cmd
return {"success": "Dangerous"}
@app.get("/bad2")
-async def bad2(cmd: str):
- stdin, stdout, stderr = paramiko_ssh_client.exec_command(command=cmd) # $ result=BAD getRemoteCommand=cmd
+async def bad2(cmd: str): # $ Source
+ stdin, stdout, stderr = paramiko_ssh_client.exec_command(command=cmd) # $ Alert result=BAD getRemoteCommand=cmd
return {"success": "Dangerous"}
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/ssh2.py b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/ssh2.py
index 312aaadb5ae9..e1c4d31ca22b 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/ssh2.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-074-RemoteCommandExecution/ssh2.py
@@ -12,9 +12,9 @@
session.userauth_password("user", "password")
@app.get("/bad1")
-async def bad1(cmd: str):
+async def bad1(cmd: str): # $ Source
channel = session.open_session()
- channel.execute(cmd) # $ result=BAD getRemoteCommand=cmd
+ channel.execute(cmd) # $ Alert result=BAD getRemoteCommand=cmd
channel.wait_eof()
channel.close()
channel.wait_closed()
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-079/EmailXss.qlref b/python/ql/test/experimental/query-tests/Security/CWE-079/EmailXss.qlref
index fcc132dd66c5..c141aa6746b3 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-079/EmailXss.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-079/EmailXss.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-079/EmailXss.ql
+query: experimental/Security/CWE-079/EmailXss.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-079/django_mail.py b/python/ql/test/experimental/query-tests/Security/CWE-079/django_mail.py
index 178e8decc798..fb42c22f02ed 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-079/django_mail.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-079/django_mail.py
@@ -11,7 +11,7 @@ def django_response(request):
https://github.com/django/django/blob/ca9872905559026af82000e46cde6f7dedc897b6/django/core/mail/__init__.py#L64
"""
send_mail("Subject", "plain-text body", "from@example.com",
- ["to@example.com"], html_message=django.http.request.GET.get("html"))
+ ["to@example.com"], html_message=django.http.request.GET.get("html")) # $ Alert
def django_response(request):
@@ -20,6 +20,6 @@ def django_response(request):
https://github.com/django/django/blob/ca9872905559026af82000e46cde6f7dedc897b6/django/core/mail/__init__.py#L90-L121
"""
mail_admins("Subject", "plain-text body",
- html_message=django.http.request.GET.get("html"))
+ html_message=django.http.request.GET.get("html")) # $ Alert
mail_managers("Subject", "plain-text body",
- html_message=django.http.request.GET.get("html"))
+ html_message=django.http.request.GET.get("html")) # $ Alert
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-079/flask_mail.py b/python/ql/test/experimental/query-tests/Security/CWE-079/flask_mail.py
index e8bdcc93634c..6978ad741f6a 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-079/flask_mail.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-079/flask_mail.py
@@ -1,4 +1,4 @@
-from flask import request, Flask
+from flask import request, Flask # $ Source
from flask_mail import Mail, Message
app = Flask(__name__)
@@ -10,12 +10,12 @@ def send():
sender="from@example.com",
recipients=["to@example.com"],
body="plain-text body",
- html=request.args["html"])
+ html=request.args["html"]) # $ Alert
# The message can contain a body and/or HTML:
msg.body = "plain-text body"
# The email's HTML can be set via msg.html or as an initialize argument when creating a Message object.
- msg.html = request.args["html"]
+ msg.html = request.args["html"] # $ Alert
mail.send(msg)
@@ -28,5 +28,5 @@ def connect():
msg = Message(subject="Subject",
sender="from@example.com",
recipients=["to@example.com"],
- html=request.args["html"])
+ html=request.args["html"]) # $ Alert
conn.send(msg)
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-079/sendgrid_mail.py b/python/ql/test/experimental/query-tests/Security/CWE-079/sendgrid_mail.py
index e10e8a030a81..4d89056f3fed 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-079/sendgrid_mail.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-079/sendgrid_mail.py
@@ -1,4 +1,4 @@
-from flask import request, Flask
+from flask import request, Flask # $ Source
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail, Email, To, Content, MimeType, HtmlContent
@@ -11,7 +11,7 @@ def send():
from_email='from_email@example.com',
to_emails='to@example.com',
subject='Sending with Twilio SendGrid is Fun',
- html_content=request.args["html_content"])
+ html_content=request.args["html_content"]) # $ Alert
sg = SendGridAPIClient('SENDGRID_API_KEY')
sg.send(message)
@@ -23,7 +23,7 @@ def send():
from_email='from_email@example.com',
to_emails='to@example.com',
subject='Sending with Twilio SendGrid is Fun',
- html_content=HtmlContent(request.args["html_content"]))
+ html_content=HtmlContent(request.args["html_content"])) # $ Alert
sg = SendGridAPIClient('SENDGRID_API_KEY')
sg.send(message)
@@ -34,7 +34,7 @@ def send_post():
from_email = Email("test@example.com")
to_email = To("test@example.com")
subject = "Sending with SendGrid is Fun"
- html_content = Content("text/html", request.args["html_content"])
+ html_content = Content("text/html", request.args["html_content"]) # $ Alert
plain_content = Content("text/plain", request.args["plain_content"])
mail = Mail(from_email, to_email, subject, plain_content, html_content)
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-079/sendgrid_via_mail_send_post_request_body_bad.py b/python/ql/test/experimental/query-tests/Security/CWE-079/sendgrid_via_mail_send_post_request_body_bad.py
index fca641057da6..30a67213b487 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-079/sendgrid_via_mail_send_post_request_body_bad.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-079/sendgrid_via_mail_send_post_request_body_bad.py
@@ -1,6 +1,6 @@
import sendgrid
import os
-from flask import request, Flask
+from flask import request, Flask # $ Source
app = Flask(__name__)
@@ -13,7 +13,7 @@ def send():
"content": [
{
"type": "text/html",
- "value": "{}".format(request.args["html_content"])
+ "value": "{}".format(request.args["html_content"]) # $ Alert
}
],
"from": {
@@ -24,7 +24,7 @@ def send():
"mail_settings": {
"footer": {
"enable": True,
- "html": "{}".format(request.args["html_footer"]),
+ "html": "{}".format(request.args["html_footer"]), # $ Alert
"text": "Thanks,/n The SendGrid Team"
},
},
@@ -38,7 +38,7 @@ def send():
"tracking_settings": {
"subscription_tracking": {
"enable": True,
- "html": "{}".format(request.args["html_tracking"]),
+ "html": "{}".format(request.args["html_tracking"]), # $ Alert
"substitution_tag": "<%click here%>",
"text": "If you would like to unsubscribe and stop receiving these emails <% click here %>."
}
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-079/smtplib_bad_subparts.py b/python/ql/test/experimental/query-tests/Security/CWE-079/smtplib_bad_subparts.py
index 209bd889393f..20c8e3466aef 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-079/smtplib_bad_subparts.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-079/smtplib_bad_subparts.py
@@ -1,5 +1,5 @@
# This test checks that the developer doesn't pass a MIMEText instance to a MIMEMultipart initializer via the subparts parameter.
-from flask import Flask, request
+from flask import Flask, request # $ Source
import json
import smtplib
import ssl
@@ -21,7 +21,7 @@ def email_person():
# Turn these into plain/html MIMEText objects
part1 = MIMEText(text, "plain")
- part2 = MIMEText(html, "html")
+ part2 = MIMEText(html, "html") # $ Alert
message = MIMEMultipart(_subparts=(part1, part2))
message["Subject"] = "multipart test"
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-079/smtplib_bad_via_attach.py b/python/ql/test/experimental/query-tests/Security/CWE-079/smtplib_bad_via_attach.py
index 48a228b0bc6e..d50ab028087f 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-079/smtplib_bad_via_attach.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-079/smtplib_bad_via_attach.py
@@ -1,5 +1,5 @@
# This test checks that the developer doesn't pass a MIMEText instance to a MIMEMultipart message.
-from flask import Flask, request
+from flask import Flask, request # $ Source
import json
import smtplib, ssl
from email.mime.text import MIMEText
@@ -24,7 +24,7 @@ def email_person():
# Turn these into plain/html MIMEText objects
part1 = MIMEText(text, "plain")
- part2 = MIMEText(html, "html")
+ part2 = MIMEText(html, "html") # $ Alert
# Add HTML/plain-text parts to MIMEMultipart message
# The email client will try to render the last part first
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/XsltInjection.expected b/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/XsltInjection.expected
index 8d960a22dfde..28c85388a97f 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/XsltInjection.expected
+++ b/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/XsltInjection.expected
@@ -1,3 +1,10 @@
+#select
+| xslt.py:14:29:14:37 | ControlFlowNode for xslt_root | xslt.py:3:26:3:32 | ControlFlowNode for ImportMember | xslt.py:14:29:14:37 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xslt.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
+| xsltInjection.py:12:28:12:36 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:12:28:12:36 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
+| xsltInjection.py:21:29:21:37 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:21:29:21:37 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
+| xsltInjection.py:31:24:31:32 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:31:24:31:32 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
+| xsltInjection.py:40:24:40:32 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:40:24:40:32 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
+| xsltInjection.py:50:24:50:32 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:50:24:50:32 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
edges
| xslt.py:3:26:3:32 | ControlFlowNode for ImportMember | xslt.py:3:26:3:32 | ControlFlowNode for request | provenance | |
| xslt.py:3:26:3:32 | ControlFlowNode for request | xslt.py:10:17:10:23 | ControlFlowNode for request | provenance | |
@@ -122,10 +129,3 @@ nodes
| xsltInjection.py:46:38:46:48 | ControlFlowNode for xsltStrings [List element] | semmle.label | ControlFlowNode for xsltStrings [List element] |
| xsltInjection.py:50:24:50:32 | ControlFlowNode for xslt_root | semmle.label | ControlFlowNode for xslt_root |
subpaths
-#select
-| xslt.py:14:29:14:37 | ControlFlowNode for xslt_root | xslt.py:3:26:3:32 | ControlFlowNode for ImportMember | xslt.py:14:29:14:37 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xslt.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
-| xsltInjection.py:12:28:12:36 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:12:28:12:36 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
-| xsltInjection.py:21:29:21:37 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:21:29:21:37 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
-| xsltInjection.py:31:24:31:32 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:31:24:31:32 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
-| xsltInjection.py:40:24:40:32 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:40:24:40:32 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
-| xsltInjection.py:50:24:50:32 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:50:24:50:32 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/XsltInjection.qlref b/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/XsltInjection.qlref
index 4d432d461cab..5bde608133c6 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/XsltInjection.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/XsltInjection.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-091/XsltInjection.ql
+query: experimental/Security/CWE-091/XsltInjection.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/xslt.py b/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/xslt.py
index 1655916c7e06..b589f453a9bd 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/xslt.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/xslt.py
@@ -1,6 +1,6 @@
from lxml import etree
from io import StringIO
-from flask import Flask, request
+from flask import Flask, request # $ Source
app = Flask(__name__)
@@ -11,4 +11,4 @@ def bad():
xslt_root = etree.XML(xsltQuery)
f = StringIO('')
tree = etree.parse(f)
- result_tree = tree.xslt(xslt_root) # Not OK
+ result_tree = tree.xslt(xslt_root) # $ Alert # Not OK
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/xsltInjection.py b/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/xsltInjection.py
index ddab954bbff8..2e56ff487ca9 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/xsltInjection.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-091-XsltInjection/xsltInjection.py
@@ -1,6 +1,6 @@
from lxml import etree
from io import StringIO
-from flask import Flask, request
+from flask import Flask, request # $ Source
app = Flask(__name__)
@@ -9,7 +9,7 @@
def a():
xsltQuery = request.args.get('xml', '')
xslt_root = etree.XML(xsltQuery)
- transform = etree.XSLT(xslt_root) # Not OK
+ transform = etree.XSLT(xslt_root) # $ Alert # Not OK
@app.route("/xslt2")
@@ -18,7 +18,7 @@ def b():
xslt_root = etree.XML(xsltQuery)
f = StringIO('')
tree = etree.parse(f)
- result_tree = tree.xslt(xslt_root) # Not OK
+ result_tree = tree.xslt(xslt_root) # $ Alert # Not OK
@app.route("/xslt3")
@@ -28,7 +28,7 @@ def c():
f = StringIO('')
tree = etree.parse(f)
- result = tree.xslt(xslt_root, a="'A'") # Not OK
+ result = tree.xslt(xslt_root, a="'A'") # $ Alert # Not OK
@app.route("/xslt4")
def d():
@@ -37,7 +37,7 @@ def d():
f = StringIO('')
tree = etree.parse(f)
- result = tree.xslt(xslt_root, a="'A'") # Not OK
+ result = tree.xslt(xslt_root, a="'A'") # $ Alert # Not OK
@app.route("/xslt5")
def e():
@@ -47,7 +47,7 @@ def e():
f = StringIO('')
tree = etree.parse(f)
- result = tree.xslt(xslt_root, a="'A'") # Not OK
+ result = tree.xslt(xslt_root, a="'A'") # $ Alert # Not OK
@app.route("/xslt6")
@@ -76,4 +76,4 @@ def h():
f = StringIO('')
tree = etree.parse(f)
- result = tree.xslt(xslt_root, a="'A'") # OK
\ No newline at end of file
+ result = tree.xslt(xslt_root, a="'A'") # OK
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-094/Js2Py.qlref b/python/ql/test/experimental/query-tests/Security/CWE-094/Js2Py.qlref
index 457bfe2aacca..b88e9d7f392b 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-094/Js2Py.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-094/Js2Py.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-094/Js2Py.ql
+query: experimental/Security/CWE-094/Js2Py.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-094/Js2PyTest.py b/python/ql/test/experimental/query-tests/Security/CWE-094/Js2PyTest.py
index f7aae16a9eed..d62cabef965c 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-094/Js2PyTest.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-094/Js2PyTest.py
@@ -6,5 +6,5 @@
@bp.route("/bad")
def bad():
- jk = flask.request.form["jk"]
- jk = eval_js(f"{jk} f()")
\ No newline at end of file
+ jk = flask.request.form["jk"] # $ Source
+ jk = eval_js(f"{jk} f()") # $ Alert
\ No newline at end of file
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-1236/CsvInjection.expected b/python/ql/test/experimental/query-tests/Security/CWE-1236/CsvInjection.expected
index 5152f7353f25..aa90dfaeea0d 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-1236/CsvInjection.expected
+++ b/python/ql/test/experimental/query-tests/Security/CWE-1236/CsvInjection.expected
@@ -1,3 +1,7 @@
+#select
+| csv_bad.py:18:24:18:31 | ControlFlowNode for csv_data | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | csv_bad.py:18:24:18:31 | ControlFlowNode for csv_data | Csv injection might include code from $@. | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | this user input |
+| csv_bad.py:19:25:19:32 | ControlFlowNode for csv_data | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | csv_bad.py:19:25:19:32 | ControlFlowNode for csv_data | Csv injection might include code from $@. | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | this user input |
+| csv_bad.py:25:46:25:53 | ControlFlowNode for csv_data | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | csv_bad.py:25:46:25:53 | ControlFlowNode for csv_data | Csv injection might include code from $@. | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | this user input |
edges
| csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | csv_bad.py:9:19:9:25 | ControlFlowNode for request | provenance | |
| csv_bad.py:9:19:9:25 | ControlFlowNode for request | csv_bad.py:16:16:16:22 | ControlFlowNode for request | provenance | |
@@ -26,7 +30,3 @@ nodes
| csv_bad.py:24:16:24:38 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
| csv_bad.py:25:46:25:53 | ControlFlowNode for csv_data | semmle.label | ControlFlowNode for csv_data |
subpaths
-#select
-| csv_bad.py:18:24:18:31 | ControlFlowNode for csv_data | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | csv_bad.py:18:24:18:31 | ControlFlowNode for csv_data | Csv injection might include code from $@. | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | this user input |
-| csv_bad.py:19:25:19:32 | ControlFlowNode for csv_data | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | csv_bad.py:19:25:19:32 | ControlFlowNode for csv_data | Csv injection might include code from $@. | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | this user input |
-| csv_bad.py:25:46:25:53 | ControlFlowNode for csv_data | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | csv_bad.py:25:46:25:53 | ControlFlowNode for csv_data | Csv injection might include code from $@. | csv_bad.py:9:19:9:25 | ControlFlowNode for ImportMember | this user input |
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-1236/CsvInjection.qlref b/python/ql/test/experimental/query-tests/Security/CWE-1236/CsvInjection.qlref
index d9cd7e9ca51c..6fe779d1b362 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-1236/CsvInjection.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-1236/CsvInjection.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-1236/CsvInjection.ql
\ No newline at end of file
+query: experimental/Security/CWE-1236/CsvInjection.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-1236/csv_bad.py b/python/ql/test/experimental/query-tests/Security/CWE-1236/csv_bad.py
index 6e204d1f3c54..199f96912b59 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-1236/csv_bad.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-1236/csv_bad.py
@@ -6,7 +6,7 @@
import copy
import csv
from flask import Flask
-from flask import request
+from flask import request # $ Source
from typing import List
app = Flask(__name__)
@@ -15,17 +15,17 @@
def bad1():
csv_data = request.args.get('csv')
csvWriter = csv.writer(open("test.csv", "wt"))
- csvWriter.writerow(csv_data) # bad
- csvWriter.writerows(csv_data) # bad
+ csvWriter.writerow(csv_data) # $ Alert # bad
+ csvWriter.writerows(csv_data) # $ Alert # bad
return "bad1"
@app.route('/bad2')
def bad2():
csv_data = request.args.get('csv')
- csvWriter = csv.DictWriter(f, fieldnames=csv_data) # bad
+ csvWriter = csv.DictWriter(f, fieldnames=csv_data) # $ Alert # bad
csvWriter.writeheader()
return "bad2"
if __name__ == '__main__':
app.debug = True
- app.run()
\ No newline at end of file
+ app.run()
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-176/UnicodeBypassValidation.qlref b/python/ql/test/experimental/query-tests/Security/CWE-176/UnicodeBypassValidation.qlref
index ee372b368404..0cb6079b74a5 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-176/UnicodeBypassValidation.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-176/UnicodeBypassValidation.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-176/UnicodeBypassValidation.ql
+query: experimental/Security/CWE-176/UnicodeBypassValidation.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-176/samples.py b/python/ql/test/experimental/query-tests/Security/CWE-176/samples.py
index 37ebfd25d418..5d0962e0c502 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-176/samples.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-176/samples.py
@@ -1,5 +1,5 @@
import unicodedata
-from flask import Flask, request, escape, render_template
+from flask import Flask, request, escape, render_template # $ Source
app = Flask(__name__)
@@ -7,7 +7,7 @@
@app.route("/unsafe1")
def unsafe1():
user_input = escape(request.args.get("ui"))
- normalized_user_input = unicodedata.normalize("NFKC", user_input) # $ result=BAD
+ normalized_user_input = unicodedata.normalize("NFKC", user_input) # $ Alert result=BAD
return render_template("result.html", normalized_user_input=normalized_user_input)
@@ -17,7 +17,7 @@ def unsafe1bis():
if user_input.isascii():
normalized_user_input = user_input
else:
- normalized_user_input = unicodedata.normalize("NFC", user_input) # $ result=BAD
+ normalized_user_input = unicodedata.normalize("NFC", user_input) # $ Alert result=BAD
return render_template("result.html", normalized_user_input=normalized_user_input)
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/PossibleTimingAttackAgainstHash.expected b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/PossibleTimingAttackAgainstHash.expected
index 1577182b2dcd..bd32259294e0 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/PossibleTimingAttackAgainstHash.expected
+++ b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/PossibleTimingAttackAgainstHash.expected
@@ -1,3 +1,6 @@
+#select
+| TimingAttackAgainstHash.py:27:24:27:32 | ControlFlowNode for signature | TimingAttackAgainstHash.py:26:17:26:41 | ControlFlowNode for Attribute() | TimingAttackAgainstHash.py:27:24:27:32 | ControlFlowNode for signature | Possible Timing attack against $@ validation. | TimingAttackAgainstHash.py:26:17:26:41 | ControlFlowNode for Attribute() | signature message |
+| TimingAttackAgainstHash.py:37:19:37:48 | ControlFlowNode for sign() | TimingAttackAgainstHash.py:30:12:30:47 | ControlFlowNode for Attribute() | TimingAttackAgainstHash.py:37:19:37:48 | ControlFlowNode for sign() | Possible Timing attack against $@ validation. | TimingAttackAgainstHash.py:30:12:30:47 | ControlFlowNode for Attribute() | MAC message |
edges
| TimingAttackAgainstHash.py:26:5:26:13 | ControlFlowNode for signature | TimingAttackAgainstHash.py:27:24:27:32 | ControlFlowNode for signature | provenance | |
| TimingAttackAgainstHash.py:26:17:26:41 | ControlFlowNode for Attribute() | TimingAttackAgainstHash.py:26:5:26:13 | ControlFlowNode for signature | provenance | |
@@ -9,6 +12,3 @@ nodes
| TimingAttackAgainstHash.py:30:12:30:47 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
| TimingAttackAgainstHash.py:37:19:37:48 | ControlFlowNode for sign() | semmle.label | ControlFlowNode for sign() |
subpaths
-#select
-| TimingAttackAgainstHash.py:27:24:27:32 | ControlFlowNode for signature | TimingAttackAgainstHash.py:26:17:26:41 | ControlFlowNode for Attribute() | TimingAttackAgainstHash.py:27:24:27:32 | ControlFlowNode for signature | Possible Timing attack against $@ validation. | TimingAttackAgainstHash.py:26:17:26:41 | ControlFlowNode for Attribute() | signature message |
-| TimingAttackAgainstHash.py:37:19:37:48 | ControlFlowNode for sign() | TimingAttackAgainstHash.py:30:12:30:47 | ControlFlowNode for Attribute() | TimingAttackAgainstHash.py:37:19:37:48 | ControlFlowNode for sign() | Possible Timing attack against $@ validation. | TimingAttackAgainstHash.py:30:12:30:47 | ControlFlowNode for Attribute() | MAC message |
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/PossibleTimingAttackAgainstHash.qlref b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/PossibleTimingAttackAgainstHash.qlref
index 73a8e6960ef8..5ac00932072c 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/PossibleTimingAttackAgainstHash.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/PossibleTimingAttackAgainstHash.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-208/TimingAttackAgainstHash/PossibleTimingAttackAgainstHash.ql
+query: experimental/Security/CWE-208/TimingAttackAgainstHash/PossibleTimingAttackAgainstHash.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/TimingAttackAgainstHash.py b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/TimingAttackAgainstHash.py
index 1d312f028eba..e9b5be0eb36b 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/TimingAttackAgainstHash.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/TimingAttackAgainstHash.py
@@ -16,25 +16,25 @@ def UnsafeCmacCheck(actualCmac):
expected = cmac.CMAC(algorithms.AES(key))
expected.update(b"message to authenticate")
expected.finalize()
- return actualCmac == expected
+ return actualCmac == expected
def UnsafeCheckSignature(expected):
message = b'To be signed'
key = RSA.import_key(open('private_key.der').read())
h = SHA256.new(message)
- signature = pkcs1_15.new(key).sign(h)
- return expected == signature
+ signature = pkcs1_15.new(key).sign(h) # $ Source[py/possible-timing-attack-against-hash]
+ return expected == signature # $ Alert[py/possible-timing-attack-against-hash]
def sign(pre_key, msg, alg):
- return hmac.new(pre_key, msg, alg).digest()
+ return hmac.new(pre_key, msg, alg).digest() # $ Source[py/possible-timing-attack-against-hash]
def verifyGood(msg, sig):
return constant_time_string_compare(sig, sign(key, msg, hashlib.sha256)) #good
-
+
def verifyBad(msg, sig):
key = "e179017a-62b0-4996-8a38-e91aa9f1"
- return sig == sign(key, msg, hashlib.sha256) #bad
+ return sig == sign(key, msg, hashlib.sha256) # $ Alert[py/possible-timing-attack-against-hash] #bad
def constant_time_string_compare(a, b):
if len(a) != len(b):
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/TimingAttackAgainstHash.qlref b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/TimingAttackAgainstHash.qlref
index 50c9d84b1f96..2829d76e85d2 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/TimingAttackAgainstHash.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHash/TimingAttackAgainstHash.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-208/TimingAttackAgainstHash/TimingAttackAgainstHash.ql
+query: experimental/Security/CWE-208/TimingAttackAgainstHash/TimingAttackAgainstHash.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHeaderValue/TimingAttackAgainstHeader.py b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHeaderValue/TimingAttackAgainstHeader.py
index 211c36274d74..591764ed4f89 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHeaderValue/TimingAttackAgainstHeader.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHeaderValue/TimingAttackAgainstHeader.py
@@ -11,7 +11,7 @@
@app.route('/bad')
def bad():
- if not request.headers.get('X-Auth-Token') == "token":
+ if not request.headers.get('X-Auth-Token') == "token": # $ Alert
raise Exception('bad token')
return 'bad'
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHeaderValue/TimingAttackAgainstHeaderValue.qlref b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHeaderValue/TimingAttackAgainstHeaderValue.qlref
index 9da35da9d6d2..0d31d85dc3f2 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHeaderValue/TimingAttackAgainstHeaderValue.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstHeaderValue/TimingAttackAgainstHeaderValue.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-208/TimingAttackAgainstHeaderValue/TimingAttackAgainstHeaderValue.ql
+query: experimental/Security/CWE-208/TimingAttackAgainstHeaderValue/TimingAttackAgainstHeaderValue.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstSensitiveInfo/PossibleTimingAttackAgainstSensitiveInfo.qlref b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstSensitiveInfo/PossibleTimingAttackAgainstSensitiveInfo.qlref
index acfe13f6aad2..bd9d8272f981 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstSensitiveInfo/PossibleTimingAttackAgainstSensitiveInfo.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstSensitiveInfo/PossibleTimingAttackAgainstSensitiveInfo.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-208/TimingAttackAgainstSensitiveInfo/PossibleTimingAttackAgainstSensitiveInfo.ql
+query: experimental/Security/CWE-208/TimingAttackAgainstSensitiveInfo/PossibleTimingAttackAgainstSensitiveInfo.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstSensitiveInfo/TimingAttackAgainstSensitiveInfo.py b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstSensitiveInfo/TimingAttackAgainstSensitiveInfo.py
index a34b3b7c5ae5..4619821174ea 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstSensitiveInfo/TimingAttackAgainstSensitiveInfo.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-208/TimingAttackAgainstSensitiveInfo/TimingAttackAgainstSensitiveInfo.py
@@ -12,8 +12,8 @@
@app.route('/bad', methods = ['POST', 'GET'])
def bad():
if request.method == 'POST':
- password = request.form['pwd']
- return password == "1234"
+ password = request.form['pwd'] # $ Source
+ return password == "1234" # $ Alert
@app.route('/good', methods = ['POST', 'GET'])
def good():
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/ConstantSecretKey.qlref b/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/ConstantSecretKey.qlref
index e77b304f62c4..535dfacbac40 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/ConstantSecretKey.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/ConstantSecretKey.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-287-ConstantSecretKey/WebAppConstantSecretKey.ql
+query: experimental/Security/CWE-287-ConstantSecretKey/WebAppConstantSecretKey.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/app_safe.py b/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/app_safe.py
index 442a23e2c3a1..3fcb38acbf93 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/app_safe.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/app_safe.py
@@ -2,7 +2,7 @@
from flask_session import Session
app = Flask(__name__)
-app.config['SECRET_KEY'] = 'CHANGEME'
+app.config['SECRET_KEY'] = 'CHANGEME' # $ Alert
Session(app)
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/app_unsafe.py b/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/app_unsafe.py
index 5aeeb6f7003b..c108dfd45611 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/app_unsafe.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/app_unsafe.py
@@ -1,11 +1,11 @@
from flask import Flask, session
app = Flask(__name__)
-aConstant = 'CHANGEME1'
-app.config['SECRET_KEY'] = aConstant
-app.secret_key = aConstant
-app.config.update(SECRET_KEY=aConstant)
-app.config.from_mapping(SECRET_KEY=aConstant)
+aConstant = 'CHANGEME1' # $ Source
+app.config['SECRET_KEY'] = aConstant # $ Alert
+app.secret_key = aConstant # $ Alert
+app.config.update(SECRET_KEY=aConstant) # $ Alert
+app.config.from_mapping(SECRET_KEY=aConstant) # $ Alert
app.config.from_pyfile("config.py")
app.config.from_object('config.Config')
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/config.py b/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/config.py
index 1a512c0d9f08..12dacb516e62 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/config.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/config.py
@@ -4,16 +4,16 @@
import random
FLASK_DEBUG = True
-aConstant = 'CHANGEME2'
+aConstant = 'CHANGEME2' # $ Source
class Config:
SECRET_KEY = environ.get("envKey")
- SECRET_KEY = aConstant
+ SECRET_KEY = aConstant # $ Alert
SECRET_KEY = os.getenv('envKey')
SECRET_KEY = os.environ.get('envKey')
SECRET_KEY = os.environ.get('envKey', random.randint)
SECRET_KEY = os.getenv('envKey', random.randint)
- SECRET_KEY = os.getenv('envKey', aConstant)
- SECRET_KEY = os.environ.get('envKey', aConstant)
+ SECRET_KEY = os.getenv('envKey', aConstant) # $ Alert
+ SECRET_KEY = os.environ.get('envKey', aConstant) # $ Alert
SECRET_KEY = os.environ['envKey']
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/config2.py b/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/config2.py
index dc3508783e22..96b08fead125 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/config2.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-287-ConstantSecretKey/config2.py
@@ -2,4 +2,4 @@
# General Config
FLASK_DEBUG = True
-SECRET_KEY = "CHANGEME5"
+SECRET_KEY = "CHANGEME5" # $ Alert
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-287/ImproperLdapAuth.qlref b/python/ql/test/experimental/query-tests/Security/CWE-287/ImproperLdapAuth.qlref
index 9f5c6e4c43f4..edd5c17e2b18 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-287/ImproperLdapAuth.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-287/ImproperLdapAuth.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-287/ImproperLdapAuth.ql
+query: experimental/Security/CWE-287/ImproperLdapAuth.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-287/auth_bad_2.py b/python/ql/test/experimental/query-tests/Security/CWE-287/auth_bad_2.py
index d37cc09cfd06..ef274090f91a 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-287/auth_bad_2.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-287/auth_bad_2.py
@@ -16,7 +16,7 @@ def simple_bind_example():
search_filter = "(user={})".format(ldap.filter.escape_filter_chars(request.args['search']))
ldap_connection = ldap.initialize("ldap://127.0.0.1:1337")
- ldap_connection.simple_bind('cn=root')
+ ldap_connection.simple_bind('cn=root') # $ Alert
user = ldap_connection.search_s(dn, ldap.SCOPE_SUBTREE, search_filter)
@@ -30,7 +30,7 @@ def simple_bind_s_example():
search_filter = "(user={})".format(ldap.filter.escape_filter_chars(request.args['search']))
ldap_connection = ldap.initialize("ldap://127.0.0.1:1337")
- ldap_connection.simple_bind_s('cn=root')
+ ldap_connection.simple_bind_s('cn=root') # $ Alert
user = ldap_connection.search_s(dn, ldap.SCOPE_SUBTREE, search_filter)
@@ -44,7 +44,7 @@ def bind_s_example():
search_filter = "(user={})".format(ldap.filter.escape_filter_chars(request.args['search']))
ldap_connection = ldap.initialize("ldap://127.0.0.1:1337")
- ldap_connection.bind_s('cn=root', None)
+ ldap_connection.bind_s('cn=root', None) # $ Alert
user = ldap_connection.search_s(dn, ldap.SCOPE_SUBTREE, search_filter)
@app.route("/bind_s_example")
@@ -57,7 +57,7 @@ def bind_s_example_kwargs():
search_filter = "(user={})".format(ldap.filter.escape_filter_chars(request.args['search']))
ldap_connection = ldap.initialize("ldap://127.0.0.1:1337")
- ldap_connection.bind_s(who='cn=root', cred=None)
+ ldap_connection.bind_s(who='cn=root', cred=None) # $ Alert
user = ldap_connection.search_s(dn, ldap.SCOPE_SUBTREE, search_filter)
@app.route("/bind_example")
@@ -70,7 +70,7 @@ def bind_example():
search_filter = "(user={})".format(ldap.filter.escape_filter_chars(request.args['search']))
ldap_connection = ldap.initialize("ldap://127.0.0.1:1337")
- ldap_connection.bind('cn=root', "")
+ ldap_connection.bind('cn=root', "") # $ Alert
user = ldap_connection.search_s(dn, ldap.SCOPE_SUBTREE, search_filter)
@@ -84,7 +84,7 @@ def bind_example():
search_filter = "(user={})".format(ldap.filter.escape_filter_chars(request.args['search']))
ldap_connection = ldap.initialize("ldap://127.0.0.1:1337")
- ldap_connection.bind(who='cn=root', cred="")
+ ldap_connection.bind(who='cn=root', cred="") # $ Alert
user = ldap_connection.search_s(dn, ldap.SCOPE_SUBTREE, search_filter)
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-287/auth_bad_3.py b/python/ql/test/experimental/query-tests/Security/CWE-287/auth_bad_3.py
index 2500b4cadb6b..3b99754ec401 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-287/auth_bad_3.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-287/auth_bad_3.py
@@ -16,7 +16,7 @@ def passwordNone():
search_filter = "(user={})".format(escape_filter_chars(request.args['search']))
srv = Server('servername', get_info=ALL)
- conn = Connection(srv, 'user_dn', None)
+ conn = Connection(srv, 'user_dn', None) # $ Alert
status, result, response, _ = conn.search(dn, search_filter)
@@ -30,7 +30,7 @@ def passwordNoneKwargs():
search_filter = "(user={})".format(escape_filter_chars(request.args['search']))
srv = Server('servername', get_info=ALL)
- conn = Connection(srv, user='user_dn', password=None)
+ conn = Connection(srv, user='user_dn', password=None) # $ Alert
status, result, response, _ = conn.search(dn, search_filter)
@app.route("/passwordEmpty")
@@ -43,7 +43,7 @@ def passwordEmpty():
search_filter = "(user={})".format(escape_filter_chars(request.args['search']))
srv = Server('servername', get_info=ALL)
- conn = Connection(srv, user='user_dn', password="")
+ conn = Connection(srv, user='user_dn', password="") # $ Alert
status, result, response, _ = conn.search(dn, search_filter)
@@ -57,7 +57,7 @@ def notPassword():
search_filter = "(user={})".format(escape_filter_chars(request.args['search']))
srv = Server('servername', get_info=ALL)
- conn = Connection(srv, user='user_dn')
+ conn = Connection(srv, user='user_dn') # $ Alert
status, result, response, _ = conn.search(dn, search_filter)
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/UnsafeUsageOfClientSideEncryptionVersion.expected b/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/UnsafeUsageOfClientSideEncryptionVersion.expected
index 097e3580fb1d..8ffc7ac31d9b 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/UnsafeUsageOfClientSideEncryptionVersion.expected
+++ b/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/UnsafeUsageOfClientSideEncryptionVersion.expected
@@ -1,3 +1,9 @@
+#select
+| test.py:11:9:11:19 | ControlFlowNode for blob_client | test.py:3:7:3:51 | ControlFlowNode for Attribute() | test.py:11:9:11:19 | ControlFlowNode for blob_client | Unsafe usage of v1 version of Azure Storage client-side encryption |
+| test.py:21:9:21:19 | ControlFlowNode for blob_client | test.py:15:27:15:71 | ControlFlowNode for Attribute() | test.py:21:9:21:19 | ControlFlowNode for blob_client | Unsafe usage of v1 version of Azure Storage client-side encryption |
+| test.py:31:9:31:19 | ControlFlowNode for blob_client | test.py:25:24:25:66 | ControlFlowNode for Attribute() | test.py:31:9:31:19 | ControlFlowNode for blob_client | Unsafe usage of v1 version of Azure Storage client-side encryption |
+| test.py:43:9:43:19 | ControlFlowNode for blob_client | test.py:3:7:3:51 | ControlFlowNode for Attribute() | test.py:43:9:43:19 | ControlFlowNode for blob_client | Unsafe usage of v1 version of Azure Storage client-side encryption |
+| test.py:75:9:75:10 | ControlFlowNode for bc | test.py:3:7:3:51 | ControlFlowNode for Attribute() | test.py:75:9:75:10 | ControlFlowNode for bc | Unsafe usage of v1 version of Azure Storage client-side encryption |
edges
| test.py:3:1:3:3 | ControlFlowNode for BSC | test.py:7:19:7:21 | ControlFlowNode for BSC | provenance | |
| test.py:3:1:3:3 | ControlFlowNode for BSC | test.py:35:19:35:21 | ControlFlowNode for BSC | provenance | |
@@ -86,9 +92,3 @@ nodes
| test.py:73:10:73:33 | ControlFlowNode for get_unsafe_blob_client() | semmle.label | ControlFlowNode for get_unsafe_blob_client() |
| test.py:75:9:75:10 | ControlFlowNode for bc | semmle.label | ControlFlowNode for bc |
subpaths
-#select
-| test.py:11:9:11:19 | ControlFlowNode for blob_client | test.py:3:7:3:51 | ControlFlowNode for Attribute() | test.py:11:9:11:19 | ControlFlowNode for blob_client | Unsafe usage of v1 version of Azure Storage client-side encryption |
-| test.py:21:9:21:19 | ControlFlowNode for blob_client | test.py:15:27:15:71 | ControlFlowNode for Attribute() | test.py:21:9:21:19 | ControlFlowNode for blob_client | Unsafe usage of v1 version of Azure Storage client-side encryption |
-| test.py:31:9:31:19 | ControlFlowNode for blob_client | test.py:25:24:25:66 | ControlFlowNode for Attribute() | test.py:31:9:31:19 | ControlFlowNode for blob_client | Unsafe usage of v1 version of Azure Storage client-side encryption |
-| test.py:43:9:43:19 | ControlFlowNode for blob_client | test.py:3:7:3:51 | ControlFlowNode for Attribute() | test.py:43:9:43:19 | ControlFlowNode for blob_client | Unsafe usage of v1 version of Azure Storage client-side encryption |
-| test.py:75:9:75:10 | ControlFlowNode for bc | test.py:3:7:3:51 | ControlFlowNode for Attribute() | test.py:75:9:75:10 | ControlFlowNode for bc | Unsafe usage of v1 version of Azure Storage client-side encryption |
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/UnsafeUsageOfClientSideEncryptionVersion.qlref b/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/UnsafeUsageOfClientSideEncryptionVersion.qlref
index b737b32c8159..b5ed8a0d6364 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/UnsafeUsageOfClientSideEncryptionVersion.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/UnsafeUsageOfClientSideEncryptionVersion.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-327/Azure/UnsafeUsageOfClientSideEncryptionVersion.ql
+query: experimental/Security/CWE-327/Azure/UnsafeUsageOfClientSideEncryptionVersion.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/test.py b/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/test.py
index 32fa60c61930..de1d6a3f5c60 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/test.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-327-UnsafeUsageOfClientSideEncryptionVersion/test.py
@@ -1,6 +1,6 @@
from azure.storage.blob import BlobServiceClient, ContainerClient, BlobClient
-BSC = BlobServiceClient.from_connection_string(...)
+BSC = BlobServiceClient.from_connection_string(...) # $ Source
def unsafe():
# does not set encryption_version to 2.0, default is unsafe
@@ -8,27 +8,27 @@ def unsafe():
blob_client.require_encryption = True
blob_client.key_encryption_key = ...
with open("decryptedcontentfile.txt", "rb") as stream:
- blob_client.upload_blob(stream) # BAD
+ blob_client.upload_blob(stream) # $ Alert # BAD
def unsafe_setting_on_blob_service_client():
- blob_service_client = BlobServiceClient.from_connection_string(...)
+ blob_service_client = BlobServiceClient.from_connection_string(...) # $ Source
blob_service_client.require_encryption = True
blob_service_client.key_encryption_key = ...
blob_client = blob_service_client.get_blob_client(...)
with open("decryptedcontentfile.txt", "rb") as stream:
- blob_client.upload_blob(stream)
+ blob_client.upload_blob(stream) # $ Alert
def unsafe_setting_on_container_client():
- container_client = ContainerClient.from_connection_string(...)
+ container_client = ContainerClient.from_connection_string(...) # $ Source
container_client.require_encryption = True
container_client.key_encryption_key = ...
blob_client = container_client.get_blob_client(...)
with open("decryptedcontentfile.txt", "rb") as stream:
- blob_client.upload_blob(stream)
+ blob_client.upload_blob(stream) # $ Alert
def potentially_unsafe(use_new_version=False):
@@ -40,7 +40,7 @@ def potentially_unsafe(use_new_version=False):
blob_client.encryption_version = '2.0'
with open("decryptedcontentfile.txt", "rb") as stream:
- blob_client.upload_blob(stream) # BAD
+ blob_client.upload_blob(stream) # $ Alert # BAD
def safe():
@@ -72,7 +72,7 @@ def get_unsafe_blob_client():
def unsafe_with_calls():
bc = get_unsafe_blob_client()
with open("decryptedcontentfile.txt", "rb") as stream:
- bc.upload_blob(stream) # BAD
+ bc.upload_blob(stream) # $ Alert # BAD
def get_safe_blob_client():
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-338/InsecureRandomness.py b/python/ql/test/experimental/query-tests/Security/CWE-338/InsecureRandomness.py
index 9f0439549672..ee94baf9eee1 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-338/InsecureRandomness.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-338/InsecureRandomness.py
@@ -2,4 +2,4 @@
def generatePassword():
# BAD: the random is not cryptographically secure
- return random.random()
+ return random.random() # $ Alert
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-338/InsecureRandomness.qlref b/python/ql/test/experimental/query-tests/Security/CWE-338/InsecureRandomness.qlref
index 447fc2cf6b25..84cbc2412d91 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-338/InsecureRandomness.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-338/InsecureRandomness.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-338/InsecureRandomness.ql
\ No newline at end of file
+query: experimental/Security/CWE-338/InsecureRandomness.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-346/Cors.py b/python/ql/test/experimental/query-tests/Security/CWE-346/Cors.py
index cc12e1273fbb..e01d99bde754 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-346/Cors.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-346/Cors.py
@@ -4,8 +4,8 @@ def bad():
request = cherrypy.request
validCors = "domain.com"
if request.method in ['POST', 'PUT', 'PATCH', 'DELETE']:
- origin = request.headers.get('Origin', None)
- if origin.startswith(validCors):
+ origin = request.headers.get('Origin', None) # $ Source
+ if origin.startswith(validCors): # $ Alert
print("Origin Valid")
def good():
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-346/CorsBypass.qlref b/python/ql/test/experimental/query-tests/Security/CWE-346/CorsBypass.qlref
index b652fd93088b..35c42c39e854 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-346/CorsBypass.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-346/CorsBypass.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-346/CorsBypass.ql
\ No newline at end of file
+query: experimental/Security/CWE-346/CorsBypass.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-347/JWTEmptyKeyOrAlgorithm.qlref b/python/ql/test/experimental/query-tests/Security/CWE-347/JWTEmptyKeyOrAlgorithm.qlref
index fe0d2ea00043..d225e37a0d38 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-347/JWTEmptyKeyOrAlgorithm.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-347/JWTEmptyKeyOrAlgorithm.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-347/JWTEmptyKeyOrAlgorithm.ql
+query: experimental/Security/CWE-347/JWTEmptyKeyOrAlgorithm.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-347/JWTMissingSecretOrPublicKeyVerification.qlref b/python/ql/test/experimental/query-tests/Security/CWE-347/JWTMissingSecretOrPublicKeyVerification.qlref
index d289ff151f42..38402ddd457b 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-347/JWTMissingSecretOrPublicKeyVerification.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-347/JWTMissingSecretOrPublicKeyVerification.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-347/JWTMissingSecretOrPublicKeyVerification.ql
+query: experimental/Security/CWE-347/JWTMissingSecretOrPublicKeyVerification.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-347/authlib.py b/python/ql/test/experimental/query-tests/Security/CWE-347/authlib.py
index 2f7367897033..94eb4a38c875 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-347/authlib.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-347/authlib.py
@@ -8,8 +8,8 @@
JsonWebToken().encode({"alg": "HS256"}, token, "key")
# bad - empty key
-jwt.encode({"alg": "HS256"}, token, "")
-JsonWebToken().encode({"alg": "HS256"}, token, "")
+jwt.encode({"alg": "HS256"}, token, "") # $ Alert[py/jwt-empty-secret-or-algorithm]
+JsonWebToken().encode({"alg": "HS256"}, token, "") # $ Alert[py/jwt-empty-secret-or-algorithm]
# Decoding
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-347/pyjwt.py b/python/ql/test/experimental/query-tests/Security/CWE-347/pyjwt.py
index 39892b33dcb9..c08375ef9f4f 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-347/pyjwt.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-347/pyjwt.py
@@ -7,11 +7,11 @@
jwt.encode(token, key="key", algorithm="HS256")
# bad - both key and algorithm set to None
-jwt.encode(token, None, None)
+jwt.encode(token, None, None) # $ Alert[py/jwt-empty-secret-or-algorithm]
# bad - empty key
-jwt.encode(token, "", algorithm="HS256")
-jwt.encode(token, key="", algorithm="HS256")
+jwt.encode(token, "", algorithm="HS256") # $ Alert[py/jwt-empty-secret-or-algorithm]
+jwt.encode(token, key="", algorithm="HS256") # $ Alert[py/jwt-empty-secret-or-algorithm]
# Decoding
@@ -19,8 +19,8 @@
jwt.decode(token, "key", "HS256")
# bad - unverified decoding
-jwt.decode(token, verify=False)
-jwt.decode(token, key, options={"verify_signature": False})
+jwt.decode(token, verify=False) # $ Alert[py/jwt-missing-verification]
+jwt.decode(token, key, options={"verify_signature": False}) # $ Alert[py/jwt-missing-verification]
# good - verified decoding
jwt.decode(token, verify=True)
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-347/python_jose.py b/python/ql/test/experimental/query-tests/Security/CWE-347/python_jose.py
index eeb050184d85..8c2bfe90879b 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-347/python_jose.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-347/python_jose.py
@@ -7,8 +7,8 @@
jwt.encode(token, key="key", algorithm="HS256")
# bad - empty key
-jwt.encode(token, "", algorithm="HS256")
-jwt.encode(token, key="", algorithm="HS256")
+jwt.encode(token, "", algorithm="HS256") # $ Alert[py/jwt-empty-secret-or-algorithm]
+jwt.encode(token, key="", algorithm="HS256") # $ Alert[py/jwt-empty-secret-or-algorithm]
# Decoding
@@ -16,7 +16,7 @@
jwt.decode(token, "key", "HS256")
# bad - unverified decoding
-jwt.decode(token, key, options={"verify_signature": False})
+jwt.decode(token, key, options={"verify_signature": False}) # $ Alert[py/jwt-missing-verification]
# good - verified decoding
jwt.decode(token, key, options={"verify_signature": True})
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-347/python_jwt.py b/python/ql/test/experimental/query-tests/Security/CWE-347/python_jwt.py
index 42a3fc35f075..77e67b2dd904 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-347/python_jwt.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-347/python_jwt.py
@@ -11,4 +11,4 @@ def good(token):
def bad(token):
- python_jwt.process_jwt(token)
+ python_jwt.process_jwt(token) # $ Alert[py/jwt-missing-verification]
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-348/ClientSuppliedIpUsedInSecurityCheck.qlref b/python/ql/test/experimental/query-tests/Security/CWE-348/ClientSuppliedIpUsedInSecurityCheck.qlref
index 2a1775fe06aa..51f11c6dfcdd 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-348/ClientSuppliedIpUsedInSecurityCheck.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-348/ClientSuppliedIpUsedInSecurityCheck.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-348/ClientSuppliedIpUsedInSecurityCheck.ql
\ No newline at end of file
+query: experimental/Security/CWE-348/ClientSuppliedIpUsedInSecurityCheck.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-348/flask_bad.py b/python/ql/test/experimental/query-tests/Security/CWE-348/flask_bad.py
index b357a9316fd0..491a13399706 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-348/flask_bad.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-348/flask_bad.py
@@ -10,15 +10,15 @@
@app.route('/bad1')
def bad1():
- client_ip = request.headers.get('x-forwarded-for')
- if not client_ip.startswith('192.168.'):
+ client_ip = request.headers.get('x-forwarded-for') # $ Source
+ if not client_ip.startswith('192.168.'): # $ Alert
raise Exception('ip illegal')
return 'bad1'
@app.route('/bad2')
def bad2():
- client_ip = request.headers.get('x-forwarded-for')
- if not client_ip == '127.0.0.1':
+ client_ip = request.headers.get('x-forwarded-for') # $ Source
+ if not client_ip == '127.0.0.1': # $ Alert
raise Exception('ip illegal')
return 'bad2'
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-348/tornado_bad.py b/python/ql/test/experimental/query-tests/Security/CWE-348/tornado_bad.py
index 23ad29d8b09a..9899922d019b 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-348/tornado_bad.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-348/tornado_bad.py
@@ -19,8 +19,8 @@ def get(self):
if client_ip:
client_ip = client_ip.split(',')[len(client_ip.split(',')) - 1]
else:
- client_ip = self.request.headers.get('REMOTE_ADDR', None)
- if not client_ip == '127.0.0.1':
+ client_ip = self.request.headers.get('REMOTE_ADDR', None) # $ Source
+ if not client_ip == '127.0.0.1': # $ Alert
raise Exception('ip illegal')
self.write("hello.")
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-522-global-option/LdapInsecureAuth.qlref b/python/ql/test/experimental/query-tests/Security/CWE-522-global-option/LdapInsecureAuth.qlref
index 7b867cb31867..cd63387a1a70 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-522-global-option/LdapInsecureAuth.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-522-global-option/LdapInsecureAuth.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-522/LdapInsecureAuth.ql
+query: experimental/Security/CWE-522/LdapInsecureAuth.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-522/LdapInsecureAuth.qlref b/python/ql/test/experimental/query-tests/Security/CWE-522/LdapInsecureAuth.qlref
index 7b867cb31867..cd63387a1a70 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-522/LdapInsecureAuth.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-522/LdapInsecureAuth.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-522/LdapInsecureAuth.ql
+query: experimental/Security/CWE-522/LdapInsecureAuth.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-522/ldap2_remote.py b/python/ql/test/experimental/query-tests/Security/CWE-522/ldap2_remote.py
index 3119ca2d28a7..75f5b0b0ea34 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-522/ldap2_remote.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-522/ldap2_remote.py
@@ -42,7 +42,7 @@ def two():
@app.route("/one_bad")
def one_bad():
- ldap_connection_7 = ldap.initialize(schema + remote_host)
+ ldap_connection_7 = ldap.initialize(schema + remote_host) # $ Alert
ldap_connection_7.set_option(ldap.OPT_X_TLS_DEMAND, False)
ldap_connection_7.simple_bind_s('', '')
user = ldap_connection_7.search_s(
@@ -53,7 +53,7 @@ def one_bad():
@app.route("/one_bad_2")
def one_bad_2():
- ldap_connection_8 = ldap.initialize(schema + remote_host)
+ ldap_connection_8 = ldap.initialize(schema + remote_host) # $ Alert
ldap_connection_8.set_option(ldap.OPT_X_TLS_NEVER, True)
ldap_connection_8.simple_bind_s('', '')
user = ldap_connection_8.search_s(
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-522/ldap3_remote.py b/python/ql/test/experimental/query-tests/Security/CWE-522/ldap3_remote.py
index 269e03e41fef..ff5c5998ec23 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-522/ldap3_remote.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-522/ldap3_remote.py
@@ -1,5 +1,5 @@
from ldap3 import Server, Connection, ALL
-from flask import request, Flask
+from flask import request, Flask # $ Source
app = Flask(__name__)
@@ -98,8 +98,8 @@ def seven():
@app.route("/eight")
def eight():
- host = schema + "somethingon.theinternet.com"
- srv = Server(host, port=1337)
+ host = schema + "somethingon.theinternet.com" # $ Source
+ srv = Server(host, port=1337) # $ Alert
conn = Connection(srv, "dn", "password")
conn.start_tls()
conn.search("dn", "search_filter")
@@ -111,8 +111,8 @@ def eight():
@app.route("/nine")
def nine():
- host = schema + "somethingon.theinternet.com"
- srv = Server(host, 1337, False)
+ host = schema + "somethingon.theinternet.com" # $ Source
+ srv = Server(host, 1337, False) # $ Alert
conn = Connection(srv, "dn", "password")
conn.search("dn", "search_filter")
return conn.response
@@ -123,8 +123,8 @@ def nine():
@app.route("/ten")
def ten():
- host = schema + remote_host
- srv = Server(host, port=1337, use_ssl=False)
+ host = schema + remote_host # $ Source
+ srv = Server(host, port=1337, use_ssl=False) # $ Alert
conn = Connection(srv, "dn", "password")
conn.search("dn", "search_filter")
return conn.response
@@ -136,7 +136,7 @@ def ten():
@app.route("/eleven")
def eleven():
host = schema + request.args['host']
- srv = Server(host, port=1337)
+ srv = Server(host, port=1337) # $ Alert
conn = Connection(srv, "dn", "password")
conn.search("dn", "search_filter")
return conn.response
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-611-SimpleXmlRpcServer/SimpleXmlRpcServer.qlref b/python/ql/test/experimental/query-tests/Security/CWE-611-SimpleXmlRpcServer/SimpleXmlRpcServer.qlref
index a0b30e6d69b8..f9b2ebd03909 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-611-SimpleXmlRpcServer/SimpleXmlRpcServer.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-611-SimpleXmlRpcServer/SimpleXmlRpcServer.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-611/SimpleXmlRpcServer.ql
+query: experimental/Security/CWE-611/SimpleXmlRpcServer.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-611-SimpleXmlRpcServer/xmlrpc_server.py b/python/ql/test/experimental/query-tests/Security/CWE-611-SimpleXmlRpcServer/xmlrpc_server.py
index 83c18b549b3d..f2463a752bcb 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-611-SimpleXmlRpcServer/xmlrpc_server.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-611-SimpleXmlRpcServer/xmlrpc_server.py
@@ -4,7 +4,7 @@ def foo(n: str):
print("foo called with arg:", n, type(n))
return "ok"
-server = SimpleXMLRPCServer(("127.0.0.1", 8000))
+server = SimpleXMLRPCServer(("127.0.0.1", 8000)) # $ Alert
server.register_function(foo, "foo")
server.serve_forever()
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-770/UnicodeDoS.qlref b/python/ql/test/experimental/query-tests/Security/CWE-770/UnicodeDoS.qlref
index aff380880ea0..1124c1683447 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-770/UnicodeDoS.qlref
+++ b/python/ql/test/experimental/query-tests/Security/CWE-770/UnicodeDoS.qlref
@@ -1 +1,2 @@
-experimental/Security/CWE-770/UnicodeDoS.ql
\ No newline at end of file
+query: experimental/Security/CWE-770/UnicodeDoS.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/experimental/query-tests/Security/CWE-770/tests.py b/python/ql/test/experimental/query-tests/Security/CWE-770/tests.py
index 1007bcc89858..f359cdaca1c9 100644
--- a/python/ql/test/experimental/query-tests/Security/CWE-770/tests.py
+++ b/python/ql/test/experimental/query-tests/Security/CWE-770/tests.py
@@ -1,4 +1,4 @@
-from flask import Flask, jsonify, request
+from flask import Flask, jsonify, request # $ Source
import unicodedata
app = Flask(__name__)
@@ -13,7 +13,7 @@ def bad_1():
# Normalize the file path using NFKC Unicode normalization
return (
- unicodedata.normalize("NFKC", file_path),
+ unicodedata.normalize("NFKC", file_path), # $ Alert
200,
{"Content-Type": "application/octet-stream"},
)
@@ -25,7 +25,7 @@ def bad_2():
if len(r) >= 10:
# Normalize the r using NFKD Unicode normalization
- r = unicodedata.normalize("NFKD", r)
+ r = unicodedata.normalize("NFKD", r) # $ Alert
return r, 200, {"Content-Type": "application/octet-stream"}
else:
return jsonify({"error": "File not found"}), 404
@@ -37,7 +37,7 @@ def bad_3():
length = len(r)
if length >= 1_000:
# Normalize the r using NFKD Unicode normalization
- r = unicodedata.normalize("NFKD", r)
+ r = unicodedata.normalize("NFKD", r) # $ Alert
return r, 200, {"Content-Type": "application/octet-stream"}
else:
return jsonify({"error": "File not found"}), 404
@@ -49,7 +49,7 @@ def bad_4():
length = len(r)
if 1_000 <= length:
# Normalize the r using NFKD Unicode normalization
- r = unicodedata.normalize("NFKD", r)
+ r = unicodedata.normalize("NFKD", r) # $ Alert
return r, 200, {"Content-Type": "application/octet-stream"}
else:
return jsonify({"error": "File not found"}), 404
@@ -61,7 +61,7 @@ def bad_5():
length = len(r)
if not length < 1_000:
# Normalize the r using NFKD Unicode normalization
- r = unicodedata.normalize("NFKD", r)
+ r = unicodedata.normalize("NFKD", r) # $ Alert
return r, 200, {"Content-Type": "application/octet-stream"}
else:
return jsonify({"error": "File not found"}), 404
@@ -73,7 +73,7 @@ def bad_6():
length = len(r)
if not 1_000 > length:
# Normalize the r using NFKD Unicode normalization
- r = unicodedata.normalize("NFKD", r)
+ r = unicodedata.normalize("NFKD", r) # $ Alert
return r, 200, {"Content-Type": "application/octet-stream"}
else:
return jsonify({"error": "File not found"}), 404
diff --git a/python/ql/test/library-tests/frameworks/django-orm/ReflectedXss.qlref b/python/ql/test/library-tests/frameworks/django-orm/ReflectedXss.qlref
index e0efe1024162..9cd0122e556e 100644
--- a/python/ql/test/library-tests/frameworks/django-orm/ReflectedXss.qlref
+++ b/python/ql/test/library-tests/frameworks/django-orm/ReflectedXss.qlref
@@ -1 +1,2 @@
-Security/CWE-079/ReflectedXss.ql
+query: Security/CWE-079/ReflectedXss.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/library-tests/frameworks/django-orm/testapp/orm_security_tests.py b/python/ql/test/library-tests/frameworks/django-orm/testapp/orm_security_tests.py
index 74d23d950096..86c8dc804182 100644
--- a/python/ql/test/library-tests/frameworks/django-orm/testapp/orm_security_tests.py
+++ b/python/ql/test/library-tests/frameworks/django-orm/testapp/orm_security_tests.py
@@ -16,7 +16,7 @@ class Person(models.Model):
name = models.CharField(max_length=256)
age = models.IntegerField()
-def person(request):
+def person(request): # $ Source
if request.method == "POST":
person = Person()
person.name = request.POST["name"]
@@ -41,18 +41,18 @@ def person(request):
resp_text = "
Persons:
"
for person in Person.objects.all():
resp_text += "\n{} (age {})".format(person.name, person.age)
- return HttpResponse(resp_text) # NOT OK
+ return HttpResponse(resp_text) # $ Alert // NOT OK
def show_name(request):
person = Person.objects.get(id=request.GET["id"])
- return HttpResponse("Name is: {}".format(person.name)) # NOT OK
+ return HttpResponse("Name is: {}".format(person.name)) # $ Alert // NOT OK
def show_age(request):
person = Person.objects.get(id=request.GET["id"])
assert isinstance(person.age, int)
# Since the age is an integer, there is not actually XSS in the line below
- return HttpResponse("Age is: {}".format(person.age)) # OK
+ return HttpResponse("Age is: {}".format(person.age)) # $ SPURIOUS: Alert // OK
# look at the log after doing
"""
@@ -92,14 +92,14 @@ def only_az(value):
class CommentValidatorNotUsed(models.Model):
text = models.CharField(max_length=256, validators=[only_az])
-def save_comment_validator_not_used(request): # $ requestHandler
+def save_comment_validator_not_used(request): # $ Source requestHandler
comment = CommentValidatorNotUsed(text=request.POST["text"])
comment.save()
return HttpResponse("ok")
def display_comment_validator_not_used(request): # $ requestHandler
comment = CommentValidatorNotUsed.objects.last()
- return HttpResponse(comment.text) # NOT OK
+ return HttpResponse(comment.text) # $ Alert // NOT OK
# To test this
"""
@@ -111,14 +111,14 @@ def display_comment_validator_not_used(request): # $ requestHandler
class CommentValidatorUsed(models.Model):
text = models.CharField(max_length=256, validators=[only_az])
-def save_comment_validator_used(request): # $ requestHandler
+def save_comment_validator_used(request): # $ Source requestHandler
comment = CommentValidatorUsed(text=request.POST["text"])
comment.full_clean()
comment.save()
def display_comment_validator_used(request): # $ requestHandler
comment = CommentValidatorUsed.objects.last()
- return HttpResponse(comment.text) # sort of OK
+ return HttpResponse(comment.text) # $ Alert // sort of OK
# Doing the following will raise a ValidationError
"""
diff --git a/python/ql/test/library-tests/frameworks/gradio/taint_step_test.py b/python/ql/test/library-tests/frameworks/gradio/taint_step_test.py
index eb1614e99b03..c599420f4c88 100644
--- a/python/ql/test/library-tests/frameworks/gradio/taint_step_test.py
+++ b/python/ql/test/library-tests/frameworks/gradio/taint_step_test.py
@@ -2,15 +2,15 @@
import os
with gr.Blocks() as demo:
- path = gr.Textbox(label="Path") # $ source=gr.Textbox(..)
- file = gr.Textbox(label="File") # $ source=gr.Textbox(..)
+ path = gr.Textbox(label="Path") # $ Source source=gr.Textbox(..)
+ file = gr.Textbox(label="File") # $ Source source=gr.Textbox(..)
output = gr.Textbox(label="Output Box")
# path injection sink
def fileread(path, file):
filepath = os.path.join(path, file)
- with open(filepath, "r") as f:
+ with open(filepath, "r") as f: # $ Alert
return f.read()
diff --git a/python/ql/test/library-tests/frameworks/gradio/taint_step_test.qlref b/python/ql/test/library-tests/frameworks/gradio/taint_step_test.qlref
index d43482cc509e..6a680f6d5ff5 100644
--- a/python/ql/test/library-tests/frameworks/gradio/taint_step_test.qlref
+++ b/python/ql/test/library-tests/frameworks/gradio/taint_step_test.qlref
@@ -1 +1,2 @@
-Security/CWE-022/PathInjection.ql
+query: Security/CWE-022/PathInjection.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Classes/init-calls-subclass-method/InitCallsSubclassMethod.qlref b/python/ql/test/query-tests/Classes/init-calls-subclass-method/InitCallsSubclassMethod.qlref
index 6530409f90ac..c396a4dbc3d7 100644
--- a/python/ql/test/query-tests/Classes/init-calls-subclass-method/InitCallsSubclassMethod.qlref
+++ b/python/ql/test/query-tests/Classes/init-calls-subclass-method/InitCallsSubclassMethod.qlref
@@ -1 +1,2 @@
-Classes/InitCallsSubclass/InitCallsSubclassMethod.ql
+query: Classes/InitCallsSubclass/InitCallsSubclassMethod.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Classes/init-calls-subclass-method/init_calls_subclass.py b/python/ql/test/query-tests/Classes/init-calls-subclass-method/init_calls_subclass.py
index ef944a9c7ef5..626f11b1f226 100644
--- a/python/ql/test/query-tests/Classes/init-calls-subclass-method/init_calls_subclass.py
+++ b/python/ql/test/query-tests/Classes/init-calls-subclass-method/init_calls_subclass.py
@@ -5,7 +5,7 @@ class Super:
def __init__(self, arg):
self._state = "Not OK"
- self.set_up(arg) # BAD: set_up is overriden.
+ self.set_up(arg) # $ Alert # BAD: set_up is overriden.
self._state = "OK"
def set_up(self, arg):
@@ -29,7 +29,7 @@ def __init__(self, arg):
self.a = arg
# BAD: postproc is called after initialization. This is still an issue
# since it may still occur before all initialization on a subclass is complete.
- self.postproc()
+ self.postproc() # $ Alert
def postproc(self):
if self.a == 1:
@@ -72,4 +72,4 @@ def _set_b(self):
class Sub(Super):
def _set_b(self):
- self.b = self.a+1
\ No newline at end of file
+ self.b = self.a+1
diff --git a/python/ql/test/query-tests/Classes/should-be-context-manager/ShouldBeContextManager.qlref b/python/ql/test/query-tests/Classes/should-be-context-manager/ShouldBeContextManager.qlref
index f555b0af07a3..b13b7d8b7b9a 100644
--- a/python/ql/test/query-tests/Classes/should-be-context-manager/ShouldBeContextManager.qlref
+++ b/python/ql/test/query-tests/Classes/should-be-context-manager/ShouldBeContextManager.qlref
@@ -1 +1,2 @@
-Classes/ShouldBeContextManager.ql
\ No newline at end of file
+query: Classes/ShouldBeContextManager.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Classes/should-be-context-manager/should_be_context_manager.py b/python/ql/test/query-tests/Classes/should-be-context-manager/should_be_context_manager.py
index 68fc81206a37..869d19f3d862 100644
--- a/python/ql/test/query-tests/Classes/should-be-context-manager/should_be_context_manager.py
+++ b/python/ql/test/query-tests/Classes/should-be-context-manager/should_be_context_manager.py
@@ -1,6 +1,6 @@
#Should be context manager
-class MegaDel(object):
+class MegaDel(object): # $ Alert
def __del__(self):
a = self.x + self.y
@@ -13,7 +13,7 @@ def __del__(self):
sum += a
print(sum)
-class MiniDel(object):
+class MiniDel(object): # $ Alert
def close(self):
pass
diff --git a/python/ql/test/query-tests/Classes/useless/UselessClass.qlref b/python/ql/test/query-tests/Classes/useless/UselessClass.qlref
index 9c8e87e962cd..6dac346e62bb 100644
--- a/python/ql/test/query-tests/Classes/useless/UselessClass.qlref
+++ b/python/ql/test/query-tests/Classes/useless/UselessClass.qlref
@@ -1 +1,2 @@
-Classes/UselessClass.ql
+query: Classes/UselessClass.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Classes/useless/test.py b/python/ql/test/query-tests/Classes/useless/test.py
index 40c9e56e117e..063da81c1727 100644
--- a/python/ql/test/query-tests/Classes/useless/test.py
+++ b/python/ql/test/query-tests/Classes/useless/test.py
@@ -25,7 +25,7 @@ def do_something_else(self):
pass
-class Useless1(object):
+class Useless1(object): # $ Alert
def __init__(self):
pass
@@ -34,7 +34,7 @@ def do_something(self):
pass
-class Useless2(object):
+class Useless2(object): # $ Alert
def do_something(self):
pass
diff --git a/python/ql/test/query-tests/Exceptions/general/NotImplementedIsNotAnException.qlref b/python/ql/test/query-tests/Exceptions/general/NotImplementedIsNotAnException.qlref
index 61ac527ffb99..a5e0761210e7 100644
--- a/python/ql/test/query-tests/Exceptions/general/NotImplementedIsNotAnException.qlref
+++ b/python/ql/test/query-tests/Exceptions/general/NotImplementedIsNotAnException.qlref
@@ -1 +1,2 @@
-Exceptions/NotImplementedIsNotAnException.ql
\ No newline at end of file
+query: Exceptions/NotImplementedIsNotAnException.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Exceptions/general/exceptions_test.py b/python/ql/test/query-tests/Exceptions/general/exceptions_test.py
index e5e9ea67a6e0..81ec5b523024 100644
--- a/python/ql/test/query-tests/Exceptions/general/exceptions_test.py
+++ b/python/ql/test/query-tests/Exceptions/general/exceptions_test.py
@@ -193,7 +193,7 @@ def ee8(x):
#These are so common, we give warnings not errors.
def foo():
- raise NotImplemented
+ raise NotImplemented # $ Alert[py/raise-not-implemented]
def bar():
- raise NotImplemented()
+ raise NotImplemented() # $ Alert[py/raise-not-implemented]
diff --git a/python/ql/test/query-tests/Expressions/Formatting/MixedExplicitImplicitIn3101Format.qlref b/python/ql/test/query-tests/Expressions/Formatting/MixedExplicitImplicitIn3101Format.qlref
index 3b9a8dc0ccf9..044e500615f5 100644
--- a/python/ql/test/query-tests/Expressions/Formatting/MixedExplicitImplicitIn3101Format.qlref
+++ b/python/ql/test/query-tests/Expressions/Formatting/MixedExplicitImplicitIn3101Format.qlref
@@ -1 +1,2 @@
-Expressions/Formatting/MixedExplicitImplicitIn3101Format.ql
\ No newline at end of file
+query: Expressions/Formatting/MixedExplicitImplicitIn3101Format.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/Formatting/UnusedArgumentIn3101Format.qlref b/python/ql/test/query-tests/Expressions/Formatting/UnusedArgumentIn3101Format.qlref
index b3e654ad0526..8de137448b61 100644
--- a/python/ql/test/query-tests/Expressions/Formatting/UnusedArgumentIn3101Format.qlref
+++ b/python/ql/test/query-tests/Expressions/Formatting/UnusedArgumentIn3101Format.qlref
@@ -1 +1,2 @@
-Expressions/Formatting/UnusedArgumentIn3101Format.ql
\ No newline at end of file
+query: Expressions/Formatting/UnusedArgumentIn3101Format.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/Formatting/UnusedNamedArgumentIn3101Format.qlref b/python/ql/test/query-tests/Expressions/Formatting/UnusedNamedArgumentIn3101Format.qlref
index 6a77d8910797..a1e71b6cd8b9 100644
--- a/python/ql/test/query-tests/Expressions/Formatting/UnusedNamedArgumentIn3101Format.qlref
+++ b/python/ql/test/query-tests/Expressions/Formatting/UnusedNamedArgumentIn3101Format.qlref
@@ -1 +1,2 @@
-Expressions/Formatting/UnusedNamedArgumentIn3101Format.ql
\ No newline at end of file
+query: Expressions/Formatting/UnusedNamedArgumentIn3101Format.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/Formatting/WrongNameInArgumentsFor3101Format.qlref b/python/ql/test/query-tests/Expressions/Formatting/WrongNameInArgumentsFor3101Format.qlref
index e0b308870342..6bd5b9c75dad 100644
--- a/python/ql/test/query-tests/Expressions/Formatting/WrongNameInArgumentsFor3101Format.qlref
+++ b/python/ql/test/query-tests/Expressions/Formatting/WrongNameInArgumentsFor3101Format.qlref
@@ -1 +1,2 @@
-Expressions/Formatting/WrongNameInArgumentsFor3101Format.ql
\ No newline at end of file
+query: Expressions/Formatting/WrongNameInArgumentsFor3101Format.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/Formatting/WrongNumberArgumentsFor3101Format.qlref b/python/ql/test/query-tests/Expressions/Formatting/WrongNumberArgumentsFor3101Format.qlref
index 130a6525a901..02168e01c644 100644
--- a/python/ql/test/query-tests/Expressions/Formatting/WrongNumberArgumentsFor3101Format.qlref
+++ b/python/ql/test/query-tests/Expressions/Formatting/WrongNumberArgumentsFor3101Format.qlref
@@ -1 +1,2 @@
-Expressions/Formatting/WrongNumberArgumentsFor3101Format.ql
\ No newline at end of file
+query: Expressions/Formatting/WrongNumberArgumentsFor3101Format.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/Formatting/test.py b/python/ql/test/query-tests/Expressions/Formatting/test.py
index e9fd23c8aad6..3117a9de2a48 100755
--- a/python/ql/test/query-tests/Expressions/Formatting/test.py
+++ b/python/ql/test/query-tests/Expressions/Formatting/test.py
@@ -1,11 +1,11 @@
from __future__ import unicode_literals
-mixed_format1 = "{}{1}"
+mixed_format1 = "{}{1}" # $ Alert[py/str-format/mixed-fields]
named_format1 = "{name!r}, {0}"
explicit_format1 = "{0}, {1}"
implicit_format1 = "{}, {}"
-mixed_format2 = "{}{1}"
+mixed_format2 = "{}{1}" # $ Alert[py/str-format/mixed-fields]
named_format2 = "{name!r}, {0}"
explicit_format2 = "{0}, {1}"
implicit_format2 = "{}, {}"
@@ -14,23 +14,23 @@
mixed_format1.format("Hello", "World")
format(mixed_format2, "Hello", "World")
-named_format1.format("Hello", world="World")
-format(named_format2, "Hello", world="World")
+named_format1.format("Hello", world="World") # $ Alert[py/str-format/missing-named-argument] Alert[py/str-format/surplus-named-argument]
+format(named_format2, "Hello", world="World") # $ Alert[py/str-format/missing-named-argument] Alert[py/str-format/surplus-named-argument]
-named_format1.format(name="Hello", world="World")
-format(named_format2, name="Hello", world="World")
+named_format1.format(name="Hello", world="World") # $ Alert[py/str-format/missing-argument] Alert[py/str-format/surplus-named-argument]
+format(named_format2, name="Hello", world="World") # $ Alert[py/str-format/missing-argument] Alert[py/str-format/surplus-named-argument]
-explicit_format1.format("Hello")
-format(explicit_format2, "Hello")
+explicit_format1.format("Hello") # $ Alert[py/str-format/missing-argument]
+format(explicit_format2, "Hello") # $ Alert[py/str-format/missing-argument]
-implicit_format1.format("Hello")
-format(implicit_format2, "Hello")
+implicit_format1.format("Hello") # $ Alert[py/str-format/missing-argument]
+format(implicit_format2, "Hello") # $ Alert[py/str-format/missing-argument]
-explicit_format1.format("Hello", "World", "Extra")
-format(explicit_format2, "Hello", "World", "Extra")
+explicit_format1.format("Hello", "World", "Extra") # $ Alert[py/str-format/surplus-argument]
+format(explicit_format2, "Hello", "World", "Extra") # $ Alert[py/str-format/surplus-argument]
-implicit_format1.format("Hello", "World", "Extra")
-format(implicit_format2, "Hello", "World", "Extra")
+implicit_format1.format("Hello", "World", "Extra") # $ Alert[py/str-format/surplus-argument]
+format(implicit_format2, "Hello", "World", "Extra") # $ Alert[py/str-format/surplus-argument]
#OK ODASA-3197
if cond:
@@ -42,8 +42,8 @@
x_or_y.format(x="x", y="y")
#Still fail for multiple formats
-format(x_or_y, x="x", y="y", z="z")
-x_or_y.format(x="x", y="y", z="z")
+format(x_or_y, x="x", y="y", z="z") # $ Alert[py/str-format/surplus-named-argument]
+x_or_y.format(x="x", y="y", z="z") # $ Alert[py/str-format/surplus-named-argument]
#False positive reported by customer. -- Verify fix.
"{{}}> | ".format(html_class)
diff --git a/python/ql/test/query-tests/Expressions/Formatting/unknown_format_string.py b/python/ql/test/query-tests/Expressions/Formatting/unknown_format_string.py
index a3b32a504db3..690716e20b2d 100644
--- a/python/ql/test/query-tests/Expressions/Formatting/unknown_format_string.py
+++ b/python/ql/test/query-tests/Expressions/Formatting/unknown_format_string.py
@@ -6,7 +6,7 @@ def possibly_unknown_format_string1(x):
fmt = user_specified
else:
fmt = "{a}"
- return fmt.format(a=1,b=2)
+ return fmt.format(a=1,b=2) # $ Alert[py/str-format/surplus-named-argument]
def possibly_unknown_format_string2(x):
user_specified = input()
@@ -14,7 +14,7 @@ def possibly_unknown_format_string2(x):
fmt = user_specified
else:
fmt = "{a}"
- return fmt.format(a=1,b=2)
+ return fmt.format(a=1,b=2) # $ Alert[py/str-format/surplus-named-argument]
def possibly_unknown_format_string3(x):
@@ -22,4 +22,4 @@ def possibly_unknown_format_string3(x):
fmt = input()
else:
fmt = "{a}"
- return fmt.format(a=1,b=2)
+ return fmt.format(a=1,b=2) # $ Alert[py/str-format/surplus-named-argument]
diff --git a/python/ql/test/query-tests/Expressions/Regex/BackspaceEscape.qlref b/python/ql/test/query-tests/Expressions/Regex/BackspaceEscape.qlref
index 2bf85f8a45aa..25a46ec7b29b 100644
--- a/python/ql/test/query-tests/Expressions/Regex/BackspaceEscape.qlref
+++ b/python/ql/test/query-tests/Expressions/Regex/BackspaceEscape.qlref
@@ -1 +1,2 @@
-Expressions/Regex/BackspaceEscape.ql
+query: Expressions/Regex/BackspaceEscape.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/Regex/DuplicateCharacterInSet.qlref b/python/ql/test/query-tests/Expressions/Regex/DuplicateCharacterInSet.qlref
index f0fc83c214eb..358d546ce8ad 100644
--- a/python/ql/test/query-tests/Expressions/Regex/DuplicateCharacterInSet.qlref
+++ b/python/ql/test/query-tests/Expressions/Regex/DuplicateCharacterInSet.qlref
@@ -1 +1,2 @@
-Expressions/Regex/DuplicateCharacterInSet.ql
+query: Expressions/Regex/DuplicateCharacterInSet.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/Regex/MissingPartSpecialGroup.qlref b/python/ql/test/query-tests/Expressions/Regex/MissingPartSpecialGroup.qlref
index faf8f31ad4d6..215e7874972d 100644
--- a/python/ql/test/query-tests/Expressions/Regex/MissingPartSpecialGroup.qlref
+++ b/python/ql/test/query-tests/Expressions/Regex/MissingPartSpecialGroup.qlref
@@ -1 +1,2 @@
-Expressions/Regex/MissingPartSpecialGroup.ql
+query: Expressions/Regex/MissingPartSpecialGroup.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/Regex/UnmatchableCaret.qlref b/python/ql/test/query-tests/Expressions/Regex/UnmatchableCaret.qlref
index 161fd59f7f28..218dcb021982 100644
--- a/python/ql/test/query-tests/Expressions/Regex/UnmatchableCaret.qlref
+++ b/python/ql/test/query-tests/Expressions/Regex/UnmatchableCaret.qlref
@@ -1 +1,2 @@
-Expressions/Regex/UnmatchableCaret.ql
+query: Expressions/Regex/UnmatchableCaret.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/Regex/UnmatchableDollar.qlref b/python/ql/test/query-tests/Expressions/Regex/UnmatchableDollar.qlref
index b162342922c5..cabb436241ce 100644
--- a/python/ql/test/query-tests/Expressions/Regex/UnmatchableDollar.qlref
+++ b/python/ql/test/query-tests/Expressions/Regex/UnmatchableDollar.qlref
@@ -1 +1,2 @@
-Expressions/Regex/UnmatchableDollar.ql
+query: Expressions/Regex/UnmatchableDollar.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/Regex/test.py b/python/ql/test/query-tests/Expressions/Regex/test.py
index 717663e335c5..ebc1ae1368b0 100644
--- a/python/ql/test/query-tests/Expressions/Regex/test.py
+++ b/python/ql/test/query-tests/Expressions/Regex/test.py
@@ -1,9 +1,9 @@
import re
#Unmatchable caret
-re.compile(b' ^abc')
-re.compile(b"(?s) ^abc")
-re.compile(b"\[^123]")
+re.compile(b' ^abc') # $ Alert[py/regex/unmatchable-caret]
+re.compile(b"(?s) ^abc") # $ Alert[py/regex/unmatchable-caret]
+re.compile(b"\[^123]") # $ Alert[py/regex/unmatchable-caret]
#Likely false positives for unmatchable caret
re.compile(b"[^123]")
@@ -14,21 +14,21 @@
re.compile(b"^diff (?:-r [0-9a-f]+ ){1,2}(.*)$")
#Backspace escape
-re.compile(br"[\b\t ]") # Should warn
+re.compile(br"[\b\t ]") # $ Alert[py/regex/backspace-escape] # Should warn
re.compile(br"E\d+\b.*") # Fine
-re.compile(br"E\d+\b[ \b\t]") #Both
+re.compile(br"E\d+\b[ \b\t]") # $ Alert[py/regex/backspace-escape] #Both
#Missing part in named group
-re.compile(br'(P[\w]+)')
-re.compile(br'(_(P[\w]+)|)')
+re.compile(br'(P[\w]+)') # $ Alert[py/regex/incomplete-special-group]
+re.compile(br'(_(P[\w]+)|)') # $ Alert[py/regex/incomplete-special-group]
#This is OK...
re.compile(br'(?P\w+)')
#Unmatchable dollar
-re.compile(b"abc$ ")
-re.compile(b"abc$ (?s)")
-re.compile(b"\[$] ")
+re.compile(b"abc$ ") # $ Alert[py/regex/unmatchable-dollar]
+re.compile(b"abc$ (?s)") # $ Alert[py/regex/unmatchable-dollar]
+re.compile(b"\[$] ") # $ Alert[py/regex/unmatchable-dollar]
#Not unmatchable dollar
re.match(b"[$] ", b"$ ")
@@ -43,9 +43,9 @@
re.match(b"(a){00}b", b"b")
#Duplicate character in set
-re.compile(b"[AA]")
-re.compile(b"[000]")
-re.compile(b"[-0-9-]")
+re.compile(b"[AA]") # $ Alert[py/regex/duplicate-in-character-class]
+re.compile(b"[000]") # $ Alert[py/regex/duplicate-in-character-class]
+re.compile(b"[-0-9-]") # $ Alert[py/regex/duplicate-in-character-class]
#Possible false positives
re.compile(b"[S\S]")
@@ -76,8 +76,8 @@
#Not OK
-re.compile(br'(?<=foo)^\w+')
-re.compile(br'\w+$(?=foo)')
+re.compile(br'(?<=foo)^\w+') # $ Alert[py/regex/unmatchable-caret]
+re.compile(br'\w+$(?=foo)') # $ Alert[py/regex/unmatchable-dollar]
#OK -- ODASA-ODASA-3968
@@ -134,7 +134,7 @@
\[ # [
(?P[^]]+) # very permissive!
\] # ]
- """
+ """ # $ Alert[py/regex/duplicate-in-character-class]
# Compiled regular expression marking it as verbose
ODASA_6786 = re.compile(VERBOSE_REGEX, re.VERBOSE)
diff --git a/python/ql/test/query-tests/Expressions/comparisons/UselessComparisonTest.qlref b/python/ql/test/query-tests/Expressions/comparisons/UselessComparisonTest.qlref
index fb7f75f9f615..e022932acda4 100644
--- a/python/ql/test/query-tests/Expressions/comparisons/UselessComparisonTest.qlref
+++ b/python/ql/test/query-tests/Expressions/comparisons/UselessComparisonTest.qlref
@@ -1 +1,2 @@
-Expressions/Comparisons/UselessComparisonTest.ql
\ No newline at end of file
+query: Expressions/Comparisons/UselessComparisonTest.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/comparisons/test.py b/python/ql/test/query-tests/Expressions/comparisons/test.py
index aac73f4932eb..172667144934 100644
--- a/python/ql/test/query-tests/Expressions/comparisons/test.py
+++ b/python/ql/test/query-tests/Expressions/comparisons/test.py
@@ -3,16 +3,16 @@
def f(w, x, y, z):
if x < 0 or z < 0:
raise Exception()
- if x >= 0: # Useless test due to x < 0 being false
+ if x >= 0: # $ Alert # Useless test due to x < 0 being false
y += 1
- if z >= 0: # Useless test due to z < 0 being false
+ if z >= 0: # $ Alert # Useless test due to z < 0 being false
y += 1
while w >= 0:
if y < 10:
z += 1
- if y == 15: # Useless test due to y < 10 being true
+ if y == 15: # $ Alert # Useless test due to y < 10 being true
z += 1
- elif y > 7: # Useless test
+ elif y > 7: # $ Alert # Useless test
y -= 1
if y < 10:
y += 1
@@ -24,10 +24,10 @@ def f(w, x, y, z):
def g(w, x, y, z):
if w < x or y < z+2:
raise Exception()
- if w >= x: # Useless test due to w < x being false
+ if w >= x: # $ Alert # Useless test due to w < x being false
pass
if cond:
- if z > y-2: # Useless test due to y < z+2 being false
+ if z > y-2: # $ Alert # Useless test due to y < z+2 being false
y += 1
else:
if z >= y-2: # Not a useless test.
@@ -46,7 +46,7 @@ def validate_series(start, end):
def medium1(x, y):
if x + 1000000000000000 > y + 1000000000000000:
return
- if x > y: # Redundant
+ if x > y: # $ Alert # Redundant
pass
def medium2(x, y):
@@ -70,19 +70,19 @@ def big2(x, y):
def odasa6782_v1(protocol):
if protocol < 0:
protocol = HIGHEST_PROTOCOL
- elif not 0 <= protocol:
+ elif not 0 <= protocol: # $ Alert
raise ValueError()
def odasa6782_v2(protocol):
if protocol < 0:
protocol = HIGHEST_PROTOCOL
- elif not 0 <= protocol <= HIGHEST_PROTOCOL:
+ elif not 0 <= protocol <= HIGHEST_PROTOCOL: # $ Alert
raise ValueError()
def odasa6782_v3(protocol):
if protocol < 0:
protocol = HIGHEST_PROTOCOL
- elif 0 <= protocol <= HIGHEST_PROTOCOL:
+ elif 0 <= protocol <= HIGHEST_PROTOCOL: # $ Alert
pass
else:
raise ValueError()
diff --git a/python/ql/test/query-tests/Expressions/eq/IncorrectComparisonUsingIs.qlref b/python/ql/test/query-tests/Expressions/eq/IncorrectComparisonUsingIs.qlref
index 73123cf76281..df847ee2b1bb 100644
--- a/python/ql/test/query-tests/Expressions/eq/IncorrectComparisonUsingIs.qlref
+++ b/python/ql/test/query-tests/Expressions/eq/IncorrectComparisonUsingIs.qlref
@@ -1 +1,2 @@
-Expressions/IncorrectComparisonUsingIs.ql
+query: Expressions/IncorrectComparisonUsingIs.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/eq/expressions_test.py b/python/ql/test/query-tests/Expressions/eq/expressions_test.py
index 3489bf3a1a94..7c02b1fbc489 100644
--- a/python/ql/test/query-tests/Expressions/eq/expressions_test.py
+++ b/python/ql/test/query-tests/Expressions/eq/expressions_test.py
@@ -43,7 +43,7 @@ def meth(self):
#Using 'is' when should be using '=='
s = "Hello " + "World"
-if "Hello World" is s:
+if "Hello World" is s: # $ Alert[py/comparison-using-is]
print ("OK")
#This is OK in CPython, but may not be portable
diff --git a/python/ql/test/query-tests/Expressions/general/CompareConstants.qlref b/python/ql/test/query-tests/Expressions/general/CompareConstants.qlref
index 0e2ab115eeec..5b5160d860d5 100644
--- a/python/ql/test/query-tests/Expressions/general/CompareConstants.qlref
+++ b/python/ql/test/query-tests/Expressions/general/CompareConstants.qlref
@@ -1 +1,2 @@
-Expressions/CompareConstants.ql
+query: Expressions/CompareConstants.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/general/CompareIdenticalValues.qlref b/python/ql/test/query-tests/Expressions/general/CompareIdenticalValues.qlref
index 4bc0ec69fc04..ad4cbb7600e8 100644
--- a/python/ql/test/query-tests/Expressions/general/CompareIdenticalValues.qlref
+++ b/python/ql/test/query-tests/Expressions/general/CompareIdenticalValues.qlref
@@ -1 +1,2 @@
-Expressions/CompareIdenticalValues.ql
+query: Expressions/CompareIdenticalValues.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/general/CompareIdenticalValuesMissingSelf.qlref b/python/ql/test/query-tests/Expressions/general/CompareIdenticalValuesMissingSelf.qlref
index f19a0dee4364..48f4d302afba 100644
--- a/python/ql/test/query-tests/Expressions/general/CompareIdenticalValuesMissingSelf.qlref
+++ b/python/ql/test/query-tests/Expressions/general/CompareIdenticalValuesMissingSelf.qlref
@@ -1 +1,2 @@
-Expressions/CompareIdenticalValuesMissingSelf.ql
\ No newline at end of file
+query: Expressions/CompareIdenticalValuesMissingSelf.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/general/DuplicateKeyInDictionaryLiteral.qlref b/python/ql/test/query-tests/Expressions/general/DuplicateKeyInDictionaryLiteral.qlref
index a1bb71098829..23123f187490 100644
--- a/python/ql/test/query-tests/Expressions/general/DuplicateKeyInDictionaryLiteral.qlref
+++ b/python/ql/test/query-tests/Expressions/general/DuplicateKeyInDictionaryLiteral.qlref
@@ -1 +1,2 @@
-Expressions/DuplicateKeyInDictionaryLiteral.ql
\ No newline at end of file
+query: Expressions/DuplicateKeyInDictionaryLiteral.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/general/EqualsNone.qlref b/python/ql/test/query-tests/Expressions/general/EqualsNone.qlref
index 8d9699258e25..026a3f5bbc2f 100644
--- a/python/ql/test/query-tests/Expressions/general/EqualsNone.qlref
+++ b/python/ql/test/query-tests/Expressions/general/EqualsNone.qlref
@@ -1 +1,2 @@
-Expressions/EqualsNone.ql
\ No newline at end of file
+query: Expressions/EqualsNone.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/general/ExplicitCallToDel.qlref b/python/ql/test/query-tests/Expressions/general/ExplicitCallToDel.qlref
index 932f1a3d366d..451bd74eee0e 100644
--- a/python/ql/test/query-tests/Expressions/general/ExplicitCallToDel.qlref
+++ b/python/ql/test/query-tests/Expressions/general/ExplicitCallToDel.qlref
@@ -1 +1,2 @@
-Expressions/ExplicitCallToDel.ql
\ No newline at end of file
+query: Expressions/ExplicitCallToDel.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/general/UnsupportedFormatCharacter.qlref b/python/ql/test/query-tests/Expressions/general/UnsupportedFormatCharacter.qlref
index 3cb459229e4a..8e50b947401e 100644
--- a/python/ql/test/query-tests/Expressions/general/UnsupportedFormatCharacter.qlref
+++ b/python/ql/test/query-tests/Expressions/general/UnsupportedFormatCharacter.qlref
@@ -1 +1,2 @@
-Expressions/UnsupportedFormatCharacter.ql
\ No newline at end of file
+query: Expressions/UnsupportedFormatCharacter.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/general/compare.py b/python/ql/test/query-tests/Expressions/general/compare.py
index 141b5e6a0286..c48e06f4b1ca 100644
--- a/python/ql/test/query-tests/Expressions/general/compare.py
+++ b/python/ql/test/query-tests/Expressions/general/compare.py
@@ -5,12 +5,12 @@
a.x == b.x
#Same variables
-a == a
-a.x == a.x
+a == a # $ Alert[py/comparison-of-identical-expressions]
+a.x == a.x # $ Alert[py/comparison-of-identical-expressions]
#Compare constants
-1 == 1
-1 == 2
+1 == 1 # $ Alert[py/comparison-of-constants]
+1 == 2 # $ Alert[py/comparison-of-constants]
#Maybe missing self
class X(object):
@@ -19,7 +19,7 @@ def __init__(self, x):
self.x = x
def missing_self(self, x):
- if x == x:
+ if x == x: # $ Alert[py/comparison-missing-self]
print ("Yes")
#Compare constants in assert -- ok
diff --git a/python/ql/test/query-tests/Expressions/general/expressions_test.py b/python/ql/test/query-tests/Expressions/general/expressions_test.py
index 5e07b58e2041..7be69bb7f986 100644
--- a/python/ql/test/query-tests/Expressions/general/expressions_test.py
+++ b/python/ql/test/query-tests/Expressions/general/expressions_test.py
@@ -1,8 +1,8 @@
#encoding: utf-8
def dup_key():
- return { 1: -1,
+ return { 1: -1, # $ Alert[py/duplicate-key-dict-literal]
1: -2,
- u'a' : u'A',
+ u'a' : u'A', # $ Alert[py/duplicate-key-dict-literal]
u'a' : u'B'
}
@@ -34,7 +34,7 @@ def call_non_callable(arg):
dont_know() # Not a violation
#Explicit call to __del__
-x.__del__()
+x.__del__() # $ Alert[py/explicit-call-to-delete]
#Unhashable object
def func():
@@ -112,7 +112,7 @@ def is_container():
#Equals none
def x(arg):
- return arg == None
+ return arg == None # $ Alert[py/test-equals-none]
class NotMyDict(object):
@@ -130,7 +130,7 @@ def __del__(self):
# This is permitted and required.
Test.__del__(self)
# This is a violation.
- self.__del__()
+ self.__del__() # $ Alert[py/explicit-call-to-delete]
# This is an alternate syntax for the super() call, and hence OK.
super(SubTest, self).__del__()
# This is the Python 3 spelling of the same.
diff --git a/python/ql/test/query-tests/Expressions/general/str_fmt_test.py b/python/ql/test/query-tests/Expressions/general/str_fmt_test.py
index e941b842c319..2bccc2253ccb 100644
--- a/python/ql/test/query-tests/Expressions/general/str_fmt_test.py
+++ b/python/ql/test/query-tests/Expressions/general/str_fmt_test.py
@@ -5,7 +5,7 @@ def expected_mapping_for_fmt_string():
print (u"%(name)s" % x)
def unsupported_format_char(arg):
- print (u"%Z" % arg)
+ print (u"%Z" % arg) # $ Alert[py/percent-format/unsupported-character]
def wrong_arg_count_format(arg):
print(u"%s %s" % (arg, arg, 0))
diff --git a/python/ql/test/query-tests/Expressions/strings/UnintentionalImplicitStringConcatenation.qlref b/python/ql/test/query-tests/Expressions/strings/UnintentionalImplicitStringConcatenation.qlref
index c305fd129f8b..7159e5c79721 100644
--- a/python/ql/test/query-tests/Expressions/strings/UnintentionalImplicitStringConcatenation.qlref
+++ b/python/ql/test/query-tests/Expressions/strings/UnintentionalImplicitStringConcatenation.qlref
@@ -1 +1,2 @@
-Expressions/UnintentionalImplicitStringConcatenation.ql
\ No newline at end of file
+query: Expressions/UnintentionalImplicitStringConcatenation.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/strings/test.py b/python/ql/test/query-tests/Expressions/strings/test.py
index 15b3c9216e33..1767a2d109be 100644
--- a/python/ql/test/query-tests/Expressions/strings/test.py
+++ b/python/ql/test/query-tests/Expressions/strings/test.py
@@ -15,13 +15,13 @@ def test():
error1 = [
"foo",
"/usr/local"
- "/usr/bin"
+ "/usr/bin" # $ Alert
]
error2 = [
"foo" +
"bar",
"/usr/local"
- "/usr/bin"
+ "/usr/bin" # $ Alert
]
#Examples from documentation
@@ -31,9 +31,9 @@ def unclear():
return [
"first part of long string"
- " and the second part",
+ " and the second part", # $ Alert
"/usr/local"
- "/usr/bin"
+ "/usr/bin" # $ Alert
]
def clarified():
diff --git a/python/ql/test/query-tests/Expressions/super/CallToSuperWrongClass.qlref b/python/ql/test/query-tests/Expressions/super/CallToSuperWrongClass.qlref
index c3beeaede04b..e1ed0c122bea 100644
--- a/python/ql/test/query-tests/Expressions/super/CallToSuperWrongClass.qlref
+++ b/python/ql/test/query-tests/Expressions/super/CallToSuperWrongClass.qlref
@@ -1 +1,2 @@
-Expressions/CallToSuperWrongClass.ql
\ No newline at end of file
+query: Expressions/CallToSuperWrongClass.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Expressions/super/test.py b/python/ql/test/query-tests/Expressions/super/test.py
index e2e667cd25d7..947bc3814b2a 100644
--- a/python/ql/test/query-tests/Expressions/super/test.py
+++ b/python/ql/test/query-tests/Expressions/super/test.py
@@ -7,7 +7,7 @@ class MyDict(dict):
class NotMyDict(object):
def f(self):
- super(MyDict, self).f()
+ super(MyDict, self).f() # $ Alert
#Splitting
PY2 = sys.version_info[0] == 2
diff --git a/python/ql/test/query-tests/Functions/ModificationOfParameterWithDefault/ModificationOfParameterWithDefault.qlref b/python/ql/test/query-tests/Functions/ModificationOfParameterWithDefault/ModificationOfParameterWithDefault.qlref
index 8c4044e8feeb..3871382349a4 100644
--- a/python/ql/test/query-tests/Functions/ModificationOfParameterWithDefault/ModificationOfParameterWithDefault.qlref
+++ b/python/ql/test/query-tests/Functions/ModificationOfParameterWithDefault/ModificationOfParameterWithDefault.qlref
@@ -1 +1,2 @@
-Functions/ModificationOfParameterWithDefault.ql
+query: Functions/ModificationOfParameterWithDefault.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Functions/ModificationOfParameterWithDefault/test.py b/python/ql/test/query-tests/Functions/ModificationOfParameterWithDefault/test.py
index b047f4ddc64f..d1e5b8d810ff 100644
--- a/python/ql/test/query-tests/Functions/ModificationOfParameterWithDefault/test.py
+++ b/python/ql/test/query-tests/Functions/ModificationOfParameterWithDefault/test.py
@@ -1,31 +1,31 @@
# Not OK
-def simple(l = [0]):
- l[0] = 1 # $ modification=l
+def simple(l = [0]): # $ Source
+ l[0] = 1 # $ Alert modification=l
return l
# Not OK
-def slice(l = [0]):
- l[0:1] = 1 # $ modification=l
+def slice(l = [0]): # $ Source
+ l[0:1] = 1 # $ Alert modification=l
return l
# Not OK
-def list_del(l = [0]):
- del l[0] # $ modification=l
+def list_del(l = [0]): # $ Source
+ del l[0] # $ Alert modification=l
return l
# Not OK
-def append_op(l = []):
- l += [1, 2, 3] # $ modification=l
+def append_op(l = []): # $ Source
+ l += [1, 2, 3] # $ Alert modification=l
return l
# Not OK
-def repeat_op(l = [0]):
- l *= 3 # $ modification=l
+def repeat_op(l = [0]): # $ Source
+ l *= 3 # $ Alert modification=l
return l
# Not OK
-def append(l = []):
- l.append(1) # $ modification=l
+def append(l = []): # $ Source
+ l.append(1) # $ Alert modification=l
return l
# OK
@@ -36,64 +36,64 @@ def includes(l = []):
return x
def extends(l):
- l.extend([1]) # $ modification=l
+ l.extend([1]) # $ Alert modification=l
return l
# Not OK
-def deferred(l = []):
+def deferred(l = []): # $ Source
extends(l)
return l
# Not OK
-def nonempty(l = [5]):
- l.append(1) # $ modification=l
+def nonempty(l = [5]): # $ Source
+ l.append(1) # $ Alert modification=l
return l
# Not OK
-def dict(d = {}):
- d['a'] = 1 # $ modification=d
+def dict(d = {}): # $ Source
+ d['a'] = 1 # $ Alert modification=d
return d
# Not OK
-def dict_nonempty(d = {'a': 1}):
- d['a'] = 2 # $ modification=d
+def dict_nonempty(d = {'a': 1}): # $ Source
+ d['a'] = 2 # $ Alert modification=d
return d
# OK
-def dict_nonempty_nochange(d = {'a': 1}):
- d['a'] = 1 # $ SPURIOUS: modification=d
+def dict_nonempty_nochange(d = {'a': 1}): # $ Source
+ d['a'] = 1 # $ SPURIOUS: Alert modification=d
return d
def modifies(d):
- d['a'] = 1 # $ modification=d
+ d['a'] = 1 # $ Alert modification=d
return d
# Not OK
-def dict_deferred(d = {}):
+def dict_deferred(d = {}): # $ Source
modifies(d)
return d
# Not OK
-def dict_method(d = {}):
- d.update({'a': 1}) # $ modification=d
+def dict_method(d = {}): # $ Source
+ d.update({'a': 1}) # $ Alert modification=d
return d
# Not OK
-def dict_method_nonempty(d = {'a': 1}):
- d.update({'a': 2}) # $ modification=d
+def dict_method_nonempty(d = {'a': 1}): # $ Source
+ d.update({'a': 2}) # $ Alert modification=d
return d
# OK
-def dict_method_nonempty_nochange(d = {'a': 1}):
- d.update({'a': 1}) # $ SPURIOUS:modification=d
+def dict_method_nonempty_nochange(d = {'a': 1}): # $ Source
+ d.update({'a': 1}) # $ SPURIOUS: Alert modification=d
return d
def modifies_method(d):
- d.update({'a': 1}) # $ modification=d
+ d.update({'a': 1}) # $ Alert modification=d
return d
# Not OK
-def dict_deferred_method(d = {}):
+def dict_deferred_method(d = {}): # $ Source
modifies_method(d)
return d
@@ -105,58 +105,58 @@ def dict_includes(d = {}):
return x
# Not OK
-def dict_del(d = {'a': 1}):
- del d['a'] # $ modification=d
+def dict_del(d = {'a': 1}): # $ Source
+ del d['a'] # $ Alert modification=d
return d
# Not OK
-def dict_update_op(d = {}):
+def dict_update_op(d = {}): # $ Source
x = {'a': 1}
- d |= x # $ modification=d
+ d |= x # $ Alert modification=d
return d
# OK
-def dict_update_op_nochange(d = {}):
+def dict_update_op_nochange(d = {}): # $ Source
x = {}
- d |= x # $ SPURIOUS: modification=d
+ d |= x # $ SPURIOUS: Alert modification=d
return d
-def sanitizer(l = []):
+def sanitizer(l = []): # $ Source
if l:
l.append(1)
else:
- l.append(1) # $ modification=l
+ l.append(1) # $ Alert modification=l
return l
-def sanitizer_negated(l = [1]):
+def sanitizer_negated(l = [1]): # $ Source
if not l:
l.append(1)
else:
- l.append(1) # $ modification=l
+ l.append(1) # $ Alert modification=l
return l
-def sanitizer(l = []):
+def sanitizer(l = []): # $ Source
if not l:
- l.append(1) # $ modification=l
+ l.append(1) # $ Alert modification=l
else:
l.append(1)
return l
-def sanitizer_negated(l = [1]):
+def sanitizer_negated(l = [1]): # $ Source
if l:
- l.append(1) # $ modification=l
+ l.append(1) # $ Alert modification=l
else:
l.append(1)
return l
# indirect modification of parameter with default
def aug_assign_argument(x):
- x += ['x'] # $ modification=x
+ x += ['x'] # $ Alert modification=x
def mutate_argument(x):
- x.append('x') # $ modification=x
+ x.append('x') # $ Alert modification=x
-def indirect_modification(y = []):
+def indirect_modification(y = []): # $ Source
aug_assign_argument(y)
mutate_argument(y)
@@ -182,19 +182,19 @@ def do_stuff_based_on_type(x):
if isinstance(x, str):
x = x.split()
elif isinstance(x, dict):
- x.setdefault('foo', 'bar') # $ modification=x
+ x.setdefault('foo', 'bar') # $ Alert modification=x
elif isinstance(x, list):
- x.append(5) # $ modification=x
+ x.append(5) # $ Alert modification=x
elif isinstance(x, tuple):
x = x.unknown_method()
def str_default(x="hello world"):
do_stuff_based_on_type(x)
-def dict_default(x={'baz':'quux'}):
+def dict_default(x={'baz':'quux'}): # $ Source
do_stuff_based_on_type(x)
-def list_default(x=[1,2,3,4]):
+def list_default(x=[1,2,3,4]): # $ Source
do_stuff_based_on_type(x)
def tuple_default(x=(1,2)):
diff --git a/python/ql/test/query-tests/Functions/general/DeprecatedSliceMethod.qlref b/python/ql/test/query-tests/Functions/general/DeprecatedSliceMethod.qlref
index c38b8d1f7619..3043411c1ce4 100644
--- a/python/ql/test/query-tests/Functions/general/DeprecatedSliceMethod.qlref
+++ b/python/ql/test/query-tests/Functions/general/DeprecatedSliceMethod.qlref
@@ -1 +1,2 @@
-Functions/DeprecatedSliceMethod.ql
\ No newline at end of file
+query: Functions/DeprecatedSliceMethod.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Functions/general/InitIsGenerator.qlref b/python/ql/test/query-tests/Functions/general/InitIsGenerator.qlref
index a3df140ff1e6..2662a7ca03a3 100644
--- a/python/ql/test/query-tests/Functions/general/InitIsGenerator.qlref
+++ b/python/ql/test/query-tests/Functions/general/InitIsGenerator.qlref
@@ -1 +1,2 @@
-Functions/InitIsGenerator.ql
\ No newline at end of file
+query: Functions/InitIsGenerator.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Functions/general/SignatureOverriddenMethod.qlref b/python/ql/test/query-tests/Functions/general/SignatureOverriddenMethod.qlref
index a306477b3b48..5470a05e0e41 100644
--- a/python/ql/test/query-tests/Functions/general/SignatureOverriddenMethod.qlref
+++ b/python/ql/test/query-tests/Functions/general/SignatureOverriddenMethod.qlref
@@ -1 +1,2 @@
-Functions/SignatureOverriddenMethod.ql
+query: Functions/SignatureOverriddenMethod.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Functions/general/SignatureSpecialMethods.qlref b/python/ql/test/query-tests/Functions/general/SignatureSpecialMethods.qlref
index bc1b29b6c0d0..ab188ef5bc28 100644
--- a/python/ql/test/query-tests/Functions/general/SignatureSpecialMethods.qlref
+++ b/python/ql/test/query-tests/Functions/general/SignatureSpecialMethods.qlref
@@ -1 +1,2 @@
-Functions/SignatureSpecialMethods.ql
\ No newline at end of file
+query: Functions/SignatureSpecialMethods.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Functions/general/explicit_return_in_init.py b/python/ql/test/query-tests/Functions/general/explicit_return_in_init.py
index 47a2933ad6ef..1c26e5f31e54 100644
--- a/python/ql/test/query-tests/Functions/general/explicit_return_in_init.py
+++ b/python/ql/test/query-tests/Functions/general/explicit_return_in_init.py
@@ -29,7 +29,7 @@ def __init__(self):
class InitIsGenerator(object):
- def __init__(self):
+ def __init__(self): # $ Alert[py/init-method-is-generator]
yield self
# OK as it returns result of a call to super().__init__()
diff --git a/python/ql/test/query-tests/Functions/general/functions_test.py b/python/ql/test/query-tests/Functions/general/functions_test.py
index 741599abd5b0..a306ef8ccc82 100644
--- a/python/ql/test/query-tests/Functions/general/functions_test.py
+++ b/python/ql/test/query-tests/Functions/general/functions_test.py
@@ -92,13 +92,13 @@ def ok_to_ignore():
class DeprecatedSliceMethods(object):
- def __getslice__(self, start, stop):
+ def __getslice__(self, start, stop): # $ Alert[py/deprecated-slice-method]
pass
- def __setslice__(self, start, stop, value):
+ def __setslice__(self, start, stop, value): # $ Alert[py/deprecated-slice-method]
pass
- def __delslice__(self, start, stop):
+ def __delslice__(self, start, stop): # $ Alert[py/deprecated-slice-method]
pass
diff --git a/python/ql/test/query-tests/Functions/general/om_test.py b/python/ql/test/query-tests/Functions/general/om_test.py
index 959ed6bfe348..edaa81bd0628 100644
--- a/python/ql/test/query-tests/Functions/general/om_test.py
+++ b/python/ql/test/query-tests/Functions/general/om_test.py
@@ -29,10 +29,10 @@ def ok1(self, arg1, arg2 = 2):
def ok2(self, arg1, arg2 = 2, arg3 = 3):
return arg1, arg2, arg3
- def grossly_wrong1(self, arg1):
+ def grossly_wrong1(self, arg1): # $ Alert[py/inheritance/signature-mismatch]
return arg1
- def grossly_wrong2(self, arg1, arg2, arg3):
+ def grossly_wrong2(self, arg1, arg2, arg3): # $ Alert[py/inheritance/signature-mismatch]
return arg1, arg2, arg3
def strictly_wrong1(self, arg1):
@@ -56,19 +56,19 @@ def __str__(self):
class WrongSpecials(object):
- def __div__(self, x, y):
+ def __div__(self, x, y): # $ Alert[py/special-method-wrong-signature]
return self, x, y
- def __mul__(self):
+ def __mul__(self): # $ Alert[py/special-method-wrong-signature]
return self
- def __neg__(self, other):
+ def __neg__(self, other): # $ Alert[py/special-method-wrong-signature]
return self, other
- def __exit__(self, arg0, arg1):
+ def __exit__(self, arg0, arg1): # $ Alert[py/special-method-wrong-signature]
return arg0 == arg1
- def __repr__():
+ def __repr__(): # $ Alert[py/special-method-wrong-signature]
return ""
def __add__(self, other="Unused default"):
@@ -80,7 +80,7 @@ def __abs__():
class OKSpecials(object):
- def __del__():
+ def __del__(): # $ Alert[py/special-method-wrong-signature]
state = some_state()
def __del__(self):
diff --git a/python/ql/test/query-tests/Functions/iterators/IterReturnsNonSelf.qlref b/python/ql/test/query-tests/Functions/iterators/IterReturnsNonSelf.qlref
index b806215d26c8..828fca864dae 100644
--- a/python/ql/test/query-tests/Functions/iterators/IterReturnsNonSelf.qlref
+++ b/python/ql/test/query-tests/Functions/iterators/IterReturnsNonSelf.qlref
@@ -1 +1,2 @@
-Functions/IterReturnsNonSelf.ql
\ No newline at end of file
+query: Functions/IterReturnsNonSelf.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Functions/iterators/test.py b/python/ql/test/query-tests/Functions/iterators/test.py
index ced389967e41..860d199dae8a 100644
--- a/python/ql/test/query-tests/Functions/iterators/test.py
+++ b/python/ql/test/query-tests/Functions/iterators/test.py
@@ -2,7 +2,7 @@ class Bad1:
def __next__(self):
return 0
- def __iter__(self): # BAD: Iter does not return self
+ def __iter__(self): # $ Alert # BAD: Iter does not return self
yield 0
class Good1:
@@ -48,6 +48,6 @@ def __next__(self):
self._it = iter(self)
return next(self._it)
- def __iter__(self): # SPURIOUS, GOOD: implementation of next ensures the iterator is equivalent to the one returned by iter, but this is not detected.
+ def __iter__(self): # $ Alert # SPURIOUS, GOOD: implementation of next ensures the iterator is equivalent to the one returned by iter, but this is not detected.
yield 0
- yield 0
\ No newline at end of file
+ yield 0
diff --git a/python/ql/test/query-tests/Functions/return_values/ReturnConsistentTupleSizes.qlref b/python/ql/test/query-tests/Functions/return_values/ReturnConsistentTupleSizes.qlref
index c91661b33cf4..c7eaa3205b2e 100644
--- a/python/ql/test/query-tests/Functions/return_values/ReturnConsistentTupleSizes.qlref
+++ b/python/ql/test/query-tests/Functions/return_values/ReturnConsistentTupleSizes.qlref
@@ -1 +1,2 @@
-Functions/ReturnConsistentTupleSizes.ql
+query: Functions/ReturnConsistentTupleSizes.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Functions/return_values/functions_test.py b/python/ql/test/query-tests/Functions/return_values/functions_test.py
index 9f72a7fec600..fdd892757615 100644
--- a/python/ql/test/query-tests/Functions/return_values/functions_test.py
+++ b/python/ql/test/query-tests/Functions/return_values/functions_test.py
@@ -303,7 +303,7 @@ def foo(x):
# Returning tuples with different sizes
-def returning_different_tuple_sizes(x):
+def returning_different_tuple_sizes(x): # $ Alert[py/mixed-tuple-returns]
if x:
return 1,2
else:
@@ -326,7 +326,7 @@ def indirectly_returning_different_tuple_sizes(x): # OK, since we only look at l
return function_returning_2_tuple()
else:
return function_returning_3_tuple()
-
+
def mismatched_multi_assign(x):
a,b = returning_different_tuple_sizes(x)
diff --git a/python/ql/test/query-tests/Imports/PyCheckerTests/ImportandImportFrom.qlref b/python/ql/test/query-tests/Imports/PyCheckerTests/ImportandImportFrom.qlref
index 3d50843db7eb..ed5a37e9d476 100644
--- a/python/ql/test/query-tests/Imports/PyCheckerTests/ImportandImportFrom.qlref
+++ b/python/ql/test/query-tests/Imports/PyCheckerTests/ImportandImportFrom.qlref
@@ -1 +1,2 @@
-Imports/ImportandImportFrom.ql
+query: Imports/ImportandImportFrom.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Imports/PyCheckerTests/imports_test.py b/python/ql/test/query-tests/Imports/PyCheckerTests/imports_test.py
index 6224c788c5eb..f8a4a4b139ea 100644
--- a/python/ql/test/query-tests/Imports/PyCheckerTests/imports_test.py
+++ b/python/ql/test/query-tests/Imports/PyCheckerTests/imports_test.py
@@ -1,7 +1,7 @@
#Import and import from
-import test_module2
+import test_module2 # $ Alert[py/import-and-import-from]
from test_module2 import func
#Module imports itself
diff --git a/python/ql/test/query-tests/Imports/PyCheckerTests/pkg_notok/__init__.py b/python/ql/test/query-tests/Imports/PyCheckerTests/pkg_notok/__init__.py
index b0e269d67a5c..3c7abf44e5e1 100644
--- a/python/ql/test/query-tests/Imports/PyCheckerTests/pkg_notok/__init__.py
+++ b/python/ql/test/query-tests/Imports/PyCheckerTests/pkg_notok/__init__.py
@@ -1,7 +1,7 @@
class Foo(object):
pass
-import pkg_notok
+import pkg_notok # $ Alert[py/import-and-import-from]
# This import is a bit tricky. It will make `bar` available in as `pkg_notok.bar` as a
# side effect (see https://docs.python.org/3/reference/import.html#submodules), but the
diff --git a/python/ql/test/query-tests/Imports/deprecated/DeprecatedModule.qlref b/python/ql/test/query-tests/Imports/deprecated/DeprecatedModule.qlref
index 9f87b11d807c..93ed1e7b4be7 100644
--- a/python/ql/test/query-tests/Imports/deprecated/DeprecatedModule.qlref
+++ b/python/ql/test/query-tests/Imports/deprecated/DeprecatedModule.qlref
@@ -1 +1,2 @@
-Imports/DeprecatedModule.ql
+query: Imports/DeprecatedModule.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Imports/deprecated/test.py b/python/ql/test/query-tests/Imports/deprecated/test.py
index ce70d29794eb..6cf11feb7824 100644
--- a/python/ql/test/query-tests/Imports/deprecated/test.py
+++ b/python/ql/test/query-tests/Imports/deprecated/test.py
@@ -1,11 +1,11 @@
# Some deprecated modules
-import rfc822
-import posixfile
+import rfc822 # $ Alert
+import posixfile # $ Alert
# We should only report a bad import once
class Foo(object):
def foo(self):
- import md5
+ import md5 # $ Alert
# Backwards compatible code, should not report
try:
diff --git a/python/ql/test/query-tests/Imports/general/ImportShadowedByLoopVar.qlref b/python/ql/test/query-tests/Imports/general/ImportShadowedByLoopVar.qlref
index 3844f21922fb..d5b4aaa16938 100644
--- a/python/ql/test/query-tests/Imports/general/ImportShadowedByLoopVar.qlref
+++ b/python/ql/test/query-tests/Imports/general/ImportShadowedByLoopVar.qlref
@@ -1 +1,2 @@
-Imports/ImportShadowedByLoopVar.ql
\ No newline at end of file
+query: Imports/ImportShadowedByLoopVar.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Imports/general/ImportStarUsed.qlref b/python/ql/test/query-tests/Imports/general/ImportStarUsed.qlref
index 35f8bff3e5fc..099627be88cd 100644
--- a/python/ql/test/query-tests/Imports/general/ImportStarUsed.qlref
+++ b/python/ql/test/query-tests/Imports/general/ImportStarUsed.qlref
@@ -1 +1,2 @@
-Imports/ImportStarUsed.ql
\ No newline at end of file
+query: Imports/ImportStarUsed.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Imports/general/Imports.qlref b/python/ql/test/query-tests/Imports/general/Imports.qlref
index 6bcdb2d9b5fd..926c62f0a410 100644
--- a/python/ql/test/query-tests/Imports/general/Imports.qlref
+++ b/python/ql/test/query-tests/Imports/general/Imports.qlref
@@ -1 +1,2 @@
-Imports/Imports.ql
+query: Imports/Imports.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Imports/general/MultipleImport.qlref b/python/ql/test/query-tests/Imports/general/MultipleImport.qlref
index a4d2195b6886..7826fb7e33c9 100644
--- a/python/ql/test/query-tests/Imports/general/MultipleImport.qlref
+++ b/python/ql/test/query-tests/Imports/general/MultipleImport.qlref
@@ -1 +1,2 @@
-Imports/MultipleImports.ql
+query: Imports/MultipleImports.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Imports/general/imports_test.py b/python/ql/test/query-tests/Imports/general/imports_test.py
index 4b51f8254fc4..f0f881ffb53d 100644
--- a/python/ql/test/query-tests/Imports/general/imports_test.py
+++ b/python/ql/test/query-tests/Imports/general/imports_test.py
@@ -1,5 +1,5 @@
#Multiple imports on a single line
-import module1, module2
+import module1, module2 # $ Alert[py/multiple-imports-on-line]
#Cyclic import
@@ -13,13 +13,13 @@
import module
-for module in range(10):
+for module in range(10): # $ Alert[py/import-shadowed-loop-variable]
print(module)
#Import * used
-from module import *
-from module_without_all import *
+from module import * # $ Alert[py/import-star-used]
+from module_without_all import * # $ Alert[py/import-star-used]
#Unused import
@@ -30,8 +30,8 @@
func1
#Duplicate import
-import module1
-import module2
+import module1 # $ Alert[py/repeated-import]
+import module2 # $ Alert[py/repeated-import]
#OK -- Import used in epytext documentation.
import used_in_docs
@@ -62,4 +62,4 @@ def __init__(self):
different
# FP reported in https://github.com/github/codeql/issues/4003
-from module_that_does_not_exist import *
+from module_that_does_not_exist import * # $ Alert[py/import-star-used]
diff --git a/python/ql/test/query-tests/Lexical/ToDoComment/ToDoComment.qlref b/python/ql/test/query-tests/Lexical/ToDoComment/ToDoComment.qlref
index 4568a99f3882..2915fa8c3668 100644
--- a/python/ql/test/query-tests/Lexical/ToDoComment/ToDoComment.qlref
+++ b/python/ql/test/query-tests/Lexical/ToDoComment/ToDoComment.qlref
@@ -1 +1 @@
-Lexical/ToDoComment.ql
\ No newline at end of file
+Lexical/ToDoComment.ql
diff --git a/python/ql/test/query-tests/Lexical/commented_out_code/test.py b/python/ql/test/query-tests/Lexical/commented_out_code/test.py
index 067855b67447..2502799cca73 100644
--- a/python/ql/test/query-tests/Lexical/commented_out_code/test.py
+++ b/python/ql/test/query-tests/Lexical/commented_out_code/test.py
@@ -14,56 +14,56 @@ def f(x):
do_something()
#else:
# do_something_else()
-
-# Some non-code comments.
+
+# Some non-code comments.
# Space immediately after scope start and between functions.
-#
+#
#class CommentedOut:
-#
+#
# def __init__(self):
# pass
-#
+#
# def method(self):
#
# pass
-#
+#
#def g(y):
-# assert y
+# assert y
# with y:
# # Commented out comment
# if y:
# do_something()
# else:
# do_something_else()
-#
+#
#def h(z):
# '''Doc string
# '''
# # Commented out comment
-#
+#
# followed_by_space()
-#
+#
# more_code()
-
+
#def j():
# """ Doc string """
# pass
-
+
#def k():
#
# """ Doc string """
# pass
-
+
#def l():
#
-# """
-# Doc string
+# """
+# Doc string
# """
#
# pass
-
+
#
#
#
@@ -72,7 +72,7 @@ def f(x):
# pass
#
#
-#
+#
some_code_to_break_up_comments()
#with x:
@@ -88,7 +88,7 @@ def a_function_to_break_up_comments():
pass
# An example explaining
-# something which contains
+# something which contains
# the following code:
#
# def f():
@@ -96,5 +96,3 @@ def a_function_to_break_up_comments():
# x.y = z
# return x
#
-
-
\ No newline at end of file
diff --git a/python/ql/test/query-tests/Security/CWE-020-CookieInjection/CookieInjection.expected b/python/ql/test/query-tests/Security/CWE-020-CookieInjection/CookieInjection.expected
index cf3a06ac7c8f..6e9c8ff47dc8 100644
--- a/python/ql/test/query-tests/Security/CWE-020-CookieInjection/CookieInjection.expected
+++ b/python/ql/test/query-tests/Security/CWE-020-CookieInjection/CookieInjection.expected
@@ -1,3 +1,7 @@
+#select
+| django_tests.py:6:21:6:43 | ControlFlowNode for Attribute() | django_tests.py:4:25:4:31 | ControlFlowNode for request | django_tests.py:6:21:6:43 | ControlFlowNode for Attribute() | Cookie is constructed from a $@. | django_tests.py:4:25:4:31 | ControlFlowNode for request | user-supplied input |
+| django_tests.py:7:21:7:44 | ControlFlowNode for Attribute() | django_tests.py:4:25:4:31 | ControlFlowNode for request | django_tests.py:7:21:7:44 | ControlFlowNode for Attribute() | Cookie is constructed from a $@. | django_tests.py:4:25:4:31 | ControlFlowNode for request | user-supplied input |
+| django_tests.py:13:30:13:100 | ControlFlowNode for Fstring | django_tests.py:11:26:11:32 | ControlFlowNode for request | django_tests.py:13:30:13:100 | ControlFlowNode for Fstring | Cookie is constructed from a $@. | django_tests.py:11:26:11:32 | ControlFlowNode for request | user-supplied input |
edges
| django_tests.py:4:25:4:31 | ControlFlowNode for request | django_tests.py:6:21:6:31 | ControlFlowNode for Attribute | provenance | AdditionalTaintStep |
| django_tests.py:4:25:4:31 | ControlFlowNode for request | django_tests.py:7:21:7:31 | ControlFlowNode for Attribute | provenance | AdditionalTaintStep |
@@ -22,7 +26,3 @@ nodes
| django_tests.py:13:59:13:69 | ControlFlowNode for Attribute | semmle.label | ControlFlowNode for Attribute |
| django_tests.py:13:59:13:82 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
subpaths
-#select
-| django_tests.py:6:21:6:43 | ControlFlowNode for Attribute() | django_tests.py:4:25:4:31 | ControlFlowNode for request | django_tests.py:6:21:6:43 | ControlFlowNode for Attribute() | Cookie is constructed from a $@. | django_tests.py:4:25:4:31 | ControlFlowNode for request | user-supplied input |
-| django_tests.py:7:21:7:44 | ControlFlowNode for Attribute() | django_tests.py:4:25:4:31 | ControlFlowNode for request | django_tests.py:7:21:7:44 | ControlFlowNode for Attribute() | Cookie is constructed from a $@. | django_tests.py:4:25:4:31 | ControlFlowNode for request | user-supplied input |
-| django_tests.py:13:30:13:100 | ControlFlowNode for Fstring | django_tests.py:11:26:11:32 | ControlFlowNode for request | django_tests.py:13:30:13:100 | ControlFlowNode for Fstring | Cookie is constructed from a $@. | django_tests.py:11:26:11:32 | ControlFlowNode for request | user-supplied input |
diff --git a/python/ql/test/query-tests/Security/CWE-020-CookieInjection/CookieInjection.qlref b/python/ql/test/query-tests/Security/CWE-020-CookieInjection/CookieInjection.qlref
index a405c564b1bf..788c1b424ff5 100644
--- a/python/ql/test/query-tests/Security/CWE-020-CookieInjection/CookieInjection.qlref
+++ b/python/ql/test/query-tests/Security/CWE-020-CookieInjection/CookieInjection.qlref
@@ -1 +1,2 @@
-Security/CWE-020/CookieInjection.ql
\ No newline at end of file
+query: Security/CWE-020/CookieInjection.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-020-CookieInjection/django_tests.py b/python/ql/test/query-tests/Security/CWE-020-CookieInjection/django_tests.py
index e070f5cab82b..f77e8f20ea21 100644
--- a/python/ql/test/query-tests/Security/CWE-020-CookieInjection/django_tests.py
+++ b/python/ql/test/query-tests/Security/CWE-020-CookieInjection/django_tests.py
@@ -1,20 +1,20 @@
import django.http
from django.urls import path
-def django_response_bad(request):
+def django_response_bad(request): # $ Source
resp = django.http.HttpResponse()
- resp.set_cookie(request.GET.get("name"), # BAD: Cookie is constructed from user input
- request.GET.get("value"))
+ resp.set_cookie(request.GET.get("name"), # $ Alert # BAD: Cookie is constructed from user input
+ request.GET.get("value")) # $ Alert
return resp
-def django_response_bad2(request):
+def django_response_bad2(request): # $ Source
response = django.http.HttpResponse()
- response['Set-Cookie'] = f"{request.GET.get('name')}={request.GET.get('value')}; SameSite=None;" # BAD: Cookie header is constructed from user input.
+ response['Set-Cookie'] = f"{request.GET.get('name')}={request.GET.get('value')}; SameSite=None;" # $ Alert # BAD: Cookie header is constructed from user input.
return response
# fake setup, you can't actually run this
urlpatterns = [
path("response_bad", django_response_bad),
path("response_bd2", django_response_bad2)
-]
\ No newline at end of file
+]
diff --git a/python/ql/test/query-tests/Security/CWE-020-ExternalAPIs/UntrustedDataToExternalAPI.qlref b/python/ql/test/query-tests/Security/CWE-020-ExternalAPIs/UntrustedDataToExternalAPI.qlref
index 03c06feeec88..fbacbf2a07a0 100644
--- a/python/ql/test/query-tests/Security/CWE-020-ExternalAPIs/UntrustedDataToExternalAPI.qlref
+++ b/python/ql/test/query-tests/Security/CWE-020-ExternalAPIs/UntrustedDataToExternalAPI.qlref
@@ -1 +1,2 @@
-Security/CWE-020-ExternalAPIs/UntrustedDataToExternalAPI.ql
+query: Security/CWE-020-ExternalAPIs/UntrustedDataToExternalAPI.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-020-ExternalAPIs/test.py b/python/ql/test/query-tests/Security/CWE-020-ExternalAPIs/test.py
index 18b46298d8af..f2857914c03b 100644
--- a/python/ql/test/query-tests/Security/CWE-020-ExternalAPIs/test.py
+++ b/python/ql/test/query-tests/Security/CWE-020-ExternalAPIs/test.py
@@ -2,7 +2,7 @@
import hmac
import base64
-from flask import Flask, request, make_response
+from flask import Flask, request, make_response # $ Source
app = Flask(__name__)
SECRET_KEY = b"SECRET_KEY"
@@ -12,7 +12,7 @@
def hmac_example():
data_raw = request.args.get("data").encode('utf-8')
data = base64.decodebytes(data_raw)
- my_hmac = hmac.new(SECRET_KEY, data, hashlib.sha256)
+ my_hmac = hmac.new(SECRET_KEY, data, hashlib.sha256) # $ Alert
digest = my_hmac.digest()
print(digest)
return "ok"
@@ -22,7 +22,7 @@ def hmac_example():
def hmac_example2():
data_raw = request.args.get("data").encode('utf-8')
data = base64.decodebytes(data_raw)
- my_hmac = hmac.new(key=SECRET_KEY, msg=data, digestmod=hashlib.sha256)
+ my_hmac = hmac.new(key=SECRET_KEY, msg=data, digestmod=hashlib.sha256) # $ Alert
digest = my_hmac.digest()
print(digest)
return "ok"
@@ -32,16 +32,16 @@ def hmac_example2():
def unknown_lib_1():
from unknown.lib import func
data = request.args.get("data")
- func(data)
- func(kw=data)
+ func(data) # $ Alert
+ func(kw=data) # $ Alert
@app.route("/unknown-lib-2")
def unknown_lib_2():
import unknown.lib
data = request.args.get("data")
- unknown.lib.func(data)
- unknown.lib.func(kw=data)
+ unknown.lib.func(data) # $ Alert
+ unknown.lib.func(kw=data) # $ Alert
def handle_this(arg, application = None):
diff --git a/python/ql/test/query-tests/Security/CWE-020-IncompleteHostnameRegExp/IncompleteHostnameRegExp.qlref b/python/ql/test/query-tests/Security/CWE-020-IncompleteHostnameRegExp/IncompleteHostnameRegExp.qlref
index e818d9472521..d1afa3858252 100644
--- a/python/ql/test/query-tests/Security/CWE-020-IncompleteHostnameRegExp/IncompleteHostnameRegExp.qlref
+++ b/python/ql/test/query-tests/Security/CWE-020-IncompleteHostnameRegExp/IncompleteHostnameRegExp.qlref
@@ -1 +1,2 @@
-Security/CWE-020/IncompleteHostnameRegExp.ql
\ No newline at end of file
+query: Security/CWE-020/IncompleteHostnameRegExp.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-020-IncompleteHostnameRegExp/hosttest.py b/python/ql/test/query-tests/Security/CWE-020-IncompleteHostnameRegExp/hosttest.py
index ca7f7094a8c9..e2e90e651424 100644
--- a/python/ql/test/query-tests/Security/CWE-020-IncompleteHostnameRegExp/hosttest.py
+++ b/python/ql/test/query-tests/Security/CWE-020-IncompleteHostnameRegExp/hosttest.py
@@ -3,7 +3,7 @@
app = Flask(__name__)
-UNSAFE_REGEX = re.compile("(www|beta).example.com/")
+UNSAFE_REGEX = re.compile("(www|beta).example.com/") # $ Alert
SAFE_REGEX = re.compile(r"(www|beta)\.example\.com/")
@app.route('/some/path/bad')
diff --git a/python/ql/test/query-tests/Security/CWE-020-IncompleteUrlSubstringSanitization/IncompleteUrlSubstringSanitization.qlref b/python/ql/test/query-tests/Security/CWE-020-IncompleteUrlSubstringSanitization/IncompleteUrlSubstringSanitization.qlref
index 3fa6794419d7..1c4c23821534 100644
--- a/python/ql/test/query-tests/Security/CWE-020-IncompleteUrlSubstringSanitization/IncompleteUrlSubstringSanitization.qlref
+++ b/python/ql/test/query-tests/Security/CWE-020-IncompleteUrlSubstringSanitization/IncompleteUrlSubstringSanitization.qlref
@@ -1 +1,2 @@
-Security/CWE-020/IncompleteUrlSubstringSanitization.ql
\ No newline at end of file
+query: Security/CWE-020/IncompleteUrlSubstringSanitization.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-020-IncompleteUrlSubstringSanitization/urltest.py b/python/ql/test/query-tests/Security/CWE-020-IncompleteUrlSubstringSanitization/urltest.py
index 308b946603b8..bc59d83819ac 100644
--- a/python/ql/test/query-tests/Security/CWE-020-IncompleteUrlSubstringSanitization/urltest.py
+++ b/python/ql/test/query-tests/Security/CWE-020-IncompleteUrlSubstringSanitization/urltest.py
@@ -6,13 +6,13 @@
@app.route('/some/path/bad1')
def unsafe1(request):
target = request.args.get('target', '')
- if "example.com" in target:
+ if "example.com" in target: # $ Alert
return redirect(target)
@app.route('/some/path/bad2')
def unsafe2(request):
target = request.args.get('target', '')
- if target.endswith("example.com"):
+ if target.endswith("example.com"): # $ Alert
return redirect(target)
diff --git a/python/ql/test/query-tests/Security/CWE-020-SuspiciousRegexpRange/OverlyLargeRangeQuery.qlref b/python/ql/test/query-tests/Security/CWE-020-SuspiciousRegexpRange/OverlyLargeRangeQuery.qlref
index 77b5c92707f9..c42315c4550e 100644
--- a/python/ql/test/query-tests/Security/CWE-020-SuspiciousRegexpRange/OverlyLargeRangeQuery.qlref
+++ b/python/ql/test/query-tests/Security/CWE-020-SuspiciousRegexpRange/OverlyLargeRangeQuery.qlref
@@ -1 +1,2 @@
-Security/CWE-020/OverlyLargeRange.ql
+query: Security/CWE-020/OverlyLargeRange.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-020-SuspiciousRegexpRange/test.py b/python/ql/test/query-tests/Security/CWE-020-SuspiciousRegexpRange/test.py
index 43380ccef0db..ca3cfd991909 100644
--- a/python/ql/test/query-tests/Security/CWE-020-SuspiciousRegexpRange/test.py
+++ b/python/ql/test/query-tests/Security/CWE-020-SuspiciousRegexpRange/test.py
@@ -1,10 +1,10 @@
import re
-overlap1 = re.compile(r'^[0-93-5]$') # NOT OK
+overlap1 = re.compile(r'^[0-93-5]$') # $ Alert # NOT OK
-overlap2 = re.compile(r'[A-ZA-z]') # NOT OK
+overlap2 = re.compile(r'[A-ZA-z]') # $ Alert # NOT OK
-isEmpty = re.compile(r'^[z-a]$') # NOT OK
+isEmpty = re.compile(r'^[z-a]$') # $ Alert # NOT OK
isAscii = re.compile(r'^[\x00-\x7F]*$') # OK
@@ -14,18 +14,18 @@
NON_ALPHANUMERIC_REGEXP = re.compile(r'([^\#-~| |!])') # OK
-smallOverlap = re.compile(r'[0-9a-fA-f]') # NOT OK
+smallOverlap = re.compile(r'[0-9a-fA-f]') # $ Alert # NOT OK
-weirdRange = re.compile(r'[$-`]') # NOT OK
+weirdRange = re.compile(r'[$-`]') # $ Alert # NOT OK
-keywordOperator = re.compile(r'[!\~\*\/%+-<>\^|=&]') # NOT OK
+keywordOperator = re.compile(r'[!\~\*\/%+-<>\^|=&]') # $ Alert # NOT OK
-notYoutube = re.compile(r'youtu\.be\/[a-z1-9.-_]+') # NOT OK
+notYoutube = re.compile(r'youtu\.be\/[a-z1-9.-_]+') # $ Alert # NOT OK
-numberToLetter = re.compile(r'[7-F]') # NOT OK
+numberToLetter = re.compile(r'[7-F]') # $ Alert # NOT OK
-overlapsWithClass1 = re.compile(r'[0-9\d]') # NOT OK
+overlapsWithClass1 = re.compile(r'[0-9\d]') # $ Alert # NOT OK
-overlapsWithClass2 = re.compile(r'[\w,.-?:*+]') # NOT OK
+overlapsWithClass2 = re.compile(r'[\w,.-?:*+]') # $ Alert # NOT OK
-unicodeStuff = re.compile('[\U0001D173-\U0001D17A\U000E0020-\U000E007F\U000e0001]') # NOT OK
\ No newline at end of file
+unicodeStuff = re.compile('[\U0001D173-\U0001D17A\U000E0020-\U000E007F\U000e0001]') # $ Alert # NOT OK
diff --git a/python/ql/test/query-tests/Security/CWE-022-TarSlip/TarSlip.expected b/python/ql/test/query-tests/Security/CWE-022-TarSlip/TarSlip.expected
index 6f98ea1aae2b..abdccddd631b 100644
--- a/python/ql/test/query-tests/Security/CWE-022-TarSlip/TarSlip.expected
+++ b/python/ql/test/query-tests/Security/CWE-022-TarSlip/TarSlip.expected
@@ -1,3 +1,13 @@
+#select
+| tarslip.py:15:1:15:3 | ControlFlowNode for tar | tarslip.py:14:7:14:39 | ControlFlowNode for Attribute() | tarslip.py:15:1:15:3 | ControlFlowNode for tar | This file extraction depends on a $@. | tarslip.py:14:7:14:39 | ControlFlowNode for Attribute() | potentially untrusted source |
+| tarslip.py:20:17:20:21 | ControlFlowNode for entry | tarslip.py:18:7:18:39 | ControlFlowNode for Attribute() | tarslip.py:20:17:20:21 | ControlFlowNode for entry | This file extraction depends on a $@. | tarslip.py:18:7:18:39 | ControlFlowNode for Attribute() | potentially untrusted source |
+| tarslip.py:39:17:39:21 | ControlFlowNode for entry | tarslip.py:35:7:35:39 | ControlFlowNode for Attribute() | tarslip.py:39:17:39:21 | ControlFlowNode for entry | This file extraction depends on a $@. | tarslip.py:35:7:35:39 | ControlFlowNode for Attribute() | potentially untrusted source |
+| tarslip.py:43:24:43:26 | ControlFlowNode for tar | tarslip.py:42:7:42:39 | ControlFlowNode for Attribute() | tarslip.py:43:24:43:26 | ControlFlowNode for tar | This file extraction depends on a $@. | tarslip.py:42:7:42:39 | ControlFlowNode for Attribute() | potentially untrusted source |
+| tarslip.py:61:21:61:25 | ControlFlowNode for entry | tarslip.py:58:7:58:39 | ControlFlowNode for Attribute() | tarslip.py:61:21:61:25 | ControlFlowNode for entry | This file extraction depends on a $@. | tarslip.py:58:7:58:39 | ControlFlowNode for Attribute() | potentially untrusted source |
+| tarslip.py:91:1:91:3 | ControlFlowNode for tar | tarslip.py:90:7:90:39 | ControlFlowNode for Attribute() | tarslip.py:91:1:91:3 | ControlFlowNode for tar | This file extraction depends on a $@. | tarslip.py:90:7:90:39 | ControlFlowNode for Attribute() | potentially untrusted source |
+| tarslip.py:96:17:96:21 | ControlFlowNode for entry | tarslip.py:94:7:94:39 | ControlFlowNode for Attribute() | tarslip.py:96:17:96:21 | ControlFlowNode for entry | This file extraction depends on a $@. | tarslip.py:94:7:94:39 | ControlFlowNode for Attribute() | potentially untrusted source |
+| tarslip.py:110:1:110:3 | ControlFlowNode for tar | tarslip.py:109:7:109:39 | ControlFlowNode for Attribute() | tarslip.py:110:1:110:3 | ControlFlowNode for tar | This file extraction depends on a $@. | tarslip.py:109:7:109:39 | ControlFlowNode for Attribute() | potentially untrusted source |
+| tarslip.py:113:24:113:26 | ControlFlowNode for tar | tarslip.py:112:7:112:39 | ControlFlowNode for Attribute() | tarslip.py:113:24:113:26 | ControlFlowNode for tar | This file extraction depends on a $@. | tarslip.py:112:7:112:39 | ControlFlowNode for Attribute() | potentially untrusted source |
edges
| tarslip.py:14:1:14:3 | ControlFlowNode for tar | tarslip.py:15:1:15:3 | ControlFlowNode for tar | provenance | |
| tarslip.py:14:7:14:39 | ControlFlowNode for Attribute() | tarslip.py:14:1:14:3 | ControlFlowNode for tar | provenance | |
@@ -54,13 +64,3 @@ nodes
| tarslip.py:112:7:112:39 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
| tarslip.py:113:24:113:26 | ControlFlowNode for tar | semmle.label | ControlFlowNode for tar |
subpaths
-#select
-| tarslip.py:15:1:15:3 | ControlFlowNode for tar | tarslip.py:14:7:14:39 | ControlFlowNode for Attribute() | tarslip.py:15:1:15:3 | ControlFlowNode for tar | This file extraction depends on a $@. | tarslip.py:14:7:14:39 | ControlFlowNode for Attribute() | potentially untrusted source |
-| tarslip.py:20:17:20:21 | ControlFlowNode for entry | tarslip.py:18:7:18:39 | ControlFlowNode for Attribute() | tarslip.py:20:17:20:21 | ControlFlowNode for entry | This file extraction depends on a $@. | tarslip.py:18:7:18:39 | ControlFlowNode for Attribute() | potentially untrusted source |
-| tarslip.py:39:17:39:21 | ControlFlowNode for entry | tarslip.py:35:7:35:39 | ControlFlowNode for Attribute() | tarslip.py:39:17:39:21 | ControlFlowNode for entry | This file extraction depends on a $@. | tarslip.py:35:7:35:39 | ControlFlowNode for Attribute() | potentially untrusted source |
-| tarslip.py:43:24:43:26 | ControlFlowNode for tar | tarslip.py:42:7:42:39 | ControlFlowNode for Attribute() | tarslip.py:43:24:43:26 | ControlFlowNode for tar | This file extraction depends on a $@. | tarslip.py:42:7:42:39 | ControlFlowNode for Attribute() | potentially untrusted source |
-| tarslip.py:61:21:61:25 | ControlFlowNode for entry | tarslip.py:58:7:58:39 | ControlFlowNode for Attribute() | tarslip.py:61:21:61:25 | ControlFlowNode for entry | This file extraction depends on a $@. | tarslip.py:58:7:58:39 | ControlFlowNode for Attribute() | potentially untrusted source |
-| tarslip.py:91:1:91:3 | ControlFlowNode for tar | tarslip.py:90:7:90:39 | ControlFlowNode for Attribute() | tarslip.py:91:1:91:3 | ControlFlowNode for tar | This file extraction depends on a $@. | tarslip.py:90:7:90:39 | ControlFlowNode for Attribute() | potentially untrusted source |
-| tarslip.py:96:17:96:21 | ControlFlowNode for entry | tarslip.py:94:7:94:39 | ControlFlowNode for Attribute() | tarslip.py:96:17:96:21 | ControlFlowNode for entry | This file extraction depends on a $@. | tarslip.py:94:7:94:39 | ControlFlowNode for Attribute() | potentially untrusted source |
-| tarslip.py:110:1:110:3 | ControlFlowNode for tar | tarslip.py:109:7:109:39 | ControlFlowNode for Attribute() | tarslip.py:110:1:110:3 | ControlFlowNode for tar | This file extraction depends on a $@. | tarslip.py:109:7:109:39 | ControlFlowNode for Attribute() | potentially untrusted source |
-| tarslip.py:113:24:113:26 | ControlFlowNode for tar | tarslip.py:112:7:112:39 | ControlFlowNode for Attribute() | tarslip.py:113:24:113:26 | ControlFlowNode for tar | This file extraction depends on a $@. | tarslip.py:112:7:112:39 | ControlFlowNode for Attribute() | potentially untrusted source |
diff --git a/python/ql/test/query-tests/Security/CWE-022-TarSlip/TarSlip.qlref b/python/ql/test/query-tests/Security/CWE-022-TarSlip/TarSlip.qlref
index cfede0c92b21..c9b6b9f4f069 100644
--- a/python/ql/test/query-tests/Security/CWE-022-TarSlip/TarSlip.qlref
+++ b/python/ql/test/query-tests/Security/CWE-022-TarSlip/TarSlip.qlref
@@ -1 +1,2 @@
-Security/CWE-022/TarSlip.ql
+query: Security/CWE-022/TarSlip.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-022-TarSlip/tarslip.py b/python/ql/test/query-tests/Security/CWE-022-TarSlip/tarslip.py
index 2c06d01adfd5..b2614b8a6d11 100644
--- a/python/ql/test/query-tests/Security/CWE-022-TarSlip/tarslip.py
+++ b/python/ql/test/query-tests/Security/CWE-022-TarSlip/tarslip.py
@@ -11,13 +11,13 @@
for entry in tar:
tar.extract(entry)
-tar = tarfile.open(unsafe_filename_tar)
-tar.extractall()
+tar = tarfile.open(unsafe_filename_tar) # $ Source
+tar.extractall() # $ Alert
tar.close()
-tar = tarfile.open(unsafe_filename_tar)
+tar = tarfile.open(unsafe_filename_tar) # $ Source
for entry in tar:
- tar.extract(entry)
+ tar.extract(entry) # $ Alert
tar = tarfile.open(safe_filename_tar)
tar.extractall()
@@ -32,15 +32,15 @@
tar.extract(entry, "/tmp/unpack/")
#Part Sanitized
-tar = tarfile.open(unsafe_filename_tar)
+tar = tarfile.open(unsafe_filename_tar) # $ Source
for entry in tar:
if ".." in entry.name:
raise ValueError("Illegal tar archive entry")
- tar.extract(entry, "/tmp/unpack/")
+ tar.extract(entry, "/tmp/unpack/") # $ Alert
#Unsanitized members
-tar = tarfile.open(unsafe_filename_tar)
-tar.extractall(members=tar)
+tar = tarfile.open(unsafe_filename_tar) # $ Source
+tar.extractall(members=tar) # $ Alert
#Sanitize members
@@ -55,10 +55,10 @@ def safemembers(members):
# Wrong sanitizer (is missing not)
-tar = tarfile.open(unsafe_filename_tar)
+tar = tarfile.open(unsafe_filename_tar) # $ Source
for entry in tar:
if os.path.isabs(entry.name) or ".." in entry.name:
- tar.extract(entry, "/tmp/unpack/")
+ tar.extract(entry, "/tmp/unpack/") # $ Alert
# OK Sanitized using not
@@ -87,13 +87,13 @@ def safemembers(members):
extraction_filter = "fully_trusted"
-tar = tarfile.open(unsafe_filename_tar)
-tar.extractall(filter=extraction_filter) # unsafe
+tar = tarfile.open(unsafe_filename_tar) # $ Source
+tar.extractall(filter=extraction_filter) # $ Alert # unsafe
tar.close()
-tar = tarfile.open(unsafe_filename_tar)
+tar = tarfile.open(unsafe_filename_tar) # $ Source
for entry in tar:
- tar.extract(entry, filter=extraction_filter) # unsafe
+ tar.extract(entry, filter=extraction_filter) # $ Alert # unsafe
extraction_filter = "data"
@@ -106,11 +106,11 @@ def safemembers(members):
tar.extract(entry, filter=extraction_filter) # safe
extraction_filter = None
-tar = tarfile.open(unsafe_filename_tar)
-tar.extractall(filter=extraction_filter) # unsafe
+tar = tarfile.open(unsafe_filename_tar) # $ Source
+tar.extractall(filter=extraction_filter) # $ Alert # unsafe
-tar = tarfile.open(unsafe_filename_tar)
-tar.extractall(members=tar, filter=extraction_filter) # unsafe
+tar = tarfile.open(unsafe_filename_tar) # $ Source
+tar.extractall(members=tar, filter=extraction_filter) # $ Alert # unsafe
tar = tarfile.open(unsafe_filename_tar)
tar.extractall(members=safemembers(tar), filter=extraction_filter) # safe -- we assume `safemembers` makes up for the unsafe filter
diff --git a/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/JinjaSsti.py b/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/JinjaSsti.py
index f1fe834e4936..432286eeb6d3 100644
--- a/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/JinjaSsti.py
+++ b/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/JinjaSsti.py
@@ -4,21 +4,21 @@
from jinja2 import Environment, DictLoader, escape
-def a(request):
+def a(request): # $ Source
# Load the template
template = request.GET['template']
- t = Template(template) # BAD: Template constructed from user input
+ t = Template(template) # $ Alert # BAD: Template constructed from user input
name = request.GET['name']
# Render the template with the context data
html = t.render(name=escape(name))
return HttpResponse(html)
-def b(request):
+def b(request): # $ Source
import jinja2
# Load the template
template = request.GET['template']
env = Environment()
- t = env.from_string(template) # BAD: Template constructed from user input
+ t = env.from_string(template) # $ Alert # BAD: Template constructed from user input
name = request.GET['name']
# Render the template with the context data
html = t.render(name=escape(name))
diff --git a/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/TemplateInjection.expected b/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/TemplateInjection.expected
index f92107728395..a4bf57e174c1 100644
--- a/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/TemplateInjection.expected
+++ b/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/TemplateInjection.expected
@@ -1,3 +1,6 @@
+#select
+| JinjaSsti.py:10:18:10:25 | ControlFlowNode for template | JinjaSsti.py:7:7:7:13 | ControlFlowNode for request | JinjaSsti.py:10:18:10:25 | ControlFlowNode for template | This template construction depends on a $@. | JinjaSsti.py:7:7:7:13 | ControlFlowNode for request | user-provided value |
+| JinjaSsti.py:21:25:21:32 | ControlFlowNode for template | JinjaSsti.py:16:7:16:13 | ControlFlowNode for request | JinjaSsti.py:21:25:21:32 | ControlFlowNode for template | This template construction depends on a $@. | JinjaSsti.py:16:7:16:13 | ControlFlowNode for request | user-provided value |
edges
| JinjaSsti.py:7:7:7:13 | ControlFlowNode for request | JinjaSsti.py:9:5:9:12 | ControlFlowNode for template | provenance | AdditionalTaintStep |
| JinjaSsti.py:9:5:9:12 | ControlFlowNode for template | JinjaSsti.py:10:18:10:25 | ControlFlowNode for template | provenance | |
@@ -11,6 +14,3 @@ nodes
| JinjaSsti.py:19:5:19:12 | ControlFlowNode for template | semmle.label | ControlFlowNode for template |
| JinjaSsti.py:21:25:21:32 | ControlFlowNode for template | semmle.label | ControlFlowNode for template |
subpaths
-#select
-| JinjaSsti.py:10:18:10:25 | ControlFlowNode for template | JinjaSsti.py:7:7:7:13 | ControlFlowNode for request | JinjaSsti.py:10:18:10:25 | ControlFlowNode for template | This template construction depends on a $@. | JinjaSsti.py:7:7:7:13 | ControlFlowNode for request | user-provided value |
-| JinjaSsti.py:21:25:21:32 | ControlFlowNode for template | JinjaSsti.py:16:7:16:13 | ControlFlowNode for request | JinjaSsti.py:21:25:21:32 | ControlFlowNode for template | This template construction depends on a $@. | JinjaSsti.py:16:7:16:13 | ControlFlowNode for request | user-provided value |
diff --git a/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/TemplateInjection.qlref b/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/TemplateInjection.qlref
index ead6bb469c6a..818407e3eb80 100644
--- a/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/TemplateInjection.qlref
+++ b/python/ql/test/query-tests/Security/CWE-074-TemplateInjection/TemplateInjection.qlref
@@ -1 +1,2 @@
-Security/CWE-074/TemplateInjection.ql
\ No newline at end of file
+query: Security/CWE-074/TemplateInjection.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-078-CommandInjection-py2/CommandInjection.qlref b/python/ql/test/query-tests/Security/CWE-078-CommandInjection-py2/CommandInjection.qlref
index e38b88f29197..8d677af35712 100644
--- a/python/ql/test/query-tests/Security/CWE-078-CommandInjection-py2/CommandInjection.qlref
+++ b/python/ql/test/query-tests/Security/CWE-078-CommandInjection-py2/CommandInjection.qlref
@@ -1 +1,2 @@
-Security/CWE-078/CommandInjection.ql
+query: Security/CWE-078/CommandInjection.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-078-CommandInjection-py2/command_injection.py b/python/ql/test/query-tests/Security/CWE-078-CommandInjection-py2/command_injection.py
index 09dd2bf97168..676215f29d1b 100644
--- a/python/ql/test/query-tests/Security/CWE-078-CommandInjection-py2/command_injection.py
+++ b/python/ql/test/query-tests/Security/CWE-078-CommandInjection-py2/command_injection.py
@@ -2,7 +2,7 @@
import platform
import popen2
-from flask import Flask, request
+from flask import Flask, request # $ Source
app = Flask(__name__)
@@ -16,14 +16,14 @@ def python2_specific():
"""
files = request.args.get("files", "")
- os.popen2("ls " + files)
- os.popen3("ls " + files)
- os.popen4("ls " + files)
+ os.popen2("ls " + files) # $ Alert
+ os.popen3("ls " + files) # $ Alert
+ os.popen4("ls " + files) # $ Alert
- platform.popen("ls " + files)
+ platform.popen("ls " + files) # $ Alert
- popen2.popen2("ls " + files)
- popen2.popen3("ls " + files)
- popen2.popen4("ls " + files)
- popen2.Popen3("ls " + files)
- popen2.Popen4("ls " + files)
+ popen2.popen2("ls " + files) # $ Alert
+ popen2.popen3("ls " + files) # $ Alert
+ popen2.popen4("ls " + files) # $ Alert
+ popen2.Popen3("ls " + files) # $ Alert
+ popen2.Popen4("ls " + files) # $ Alert
diff --git a/python/ql/test/query-tests/Security/CWE-078-CommandInjection/CommandInjection.qlref b/python/ql/test/query-tests/Security/CWE-078-CommandInjection/CommandInjection.qlref
index e38b88f29197..8d677af35712 100644
--- a/python/ql/test/query-tests/Security/CWE-078-CommandInjection/CommandInjection.qlref
+++ b/python/ql/test/query-tests/Security/CWE-078-CommandInjection/CommandInjection.qlref
@@ -1 +1,2 @@
-Security/CWE-078/CommandInjection.ql
+query: Security/CWE-078/CommandInjection.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-078-CommandInjection/command_injection.py b/python/ql/test/query-tests/Security/CWE-078-CommandInjection/command_injection.py
index 3ba50c254806..fb4f09c1c2a8 100644
--- a/python/ql/test/query-tests/Security/CWE-078-CommandInjection/command_injection.py
+++ b/python/ql/test/query-tests/Security/CWE-078-CommandInjection/command_injection.py
@@ -2,7 +2,7 @@
import os
import subprocess
-from flask import Flask, request
+from flask import Flask, request # $ Source
app = Flask(__name__)
@@ -10,27 +10,27 @@
def command_injection1():
files = request.args.get('files', '')
# Don't let files be `; rm -rf /`
- os.system("ls " + files) # $ result=BAD
+ os.system("ls " + files) # $ Alert result=BAD
@app.route("/command2")
def command_injection2():
files = request.args.get('files', '')
# Don't let files be `; rm -rf /`
- subprocess.Popen("ls " + files, shell=True) # $ result=BAD
+ subprocess.Popen("ls " + files, shell=True) # $ Alert result=BAD
@app.route("/command3")
def first_arg_injection():
cmd = request.args.get('cmd', '')
- subprocess.Popen([cmd, "param1"]) # $ result=BAD
+ subprocess.Popen([cmd, "param1"]) # $ Alert result=BAD
@app.route("/other_cases")
def others():
files = request.args.get('files', '')
# Don't let files be `; rm -rf /`
- os.popen("ls " + files) # $ result=BAD
+ os.popen("ls " + files) # $ Alert result=BAD
@app.route("/multiple")
@@ -38,8 +38,8 @@ def multiple():
command = request.args.get('command', '')
# We should mark flow to both calls here, which conflicts with removing flow out of
# a sink due to use-use flow.
- os.system(command) # $ result=BAD
- os.system(command) # $ result=BAD
+ os.system(command) # $ Alert result=BAD
+ os.system(command) # $ Alert result=BAD
@app.route("/not-into-sink-impl")
@@ -52,11 +52,11 @@ def not_into_sink_impl():
subprocess.call implementation: https://github.com/python/cpython/blob/fa7ce080175f65d678a7d5756c94f82887fc9803/Lib/subprocess.py#L341
"""
command = request.args.get('command', '')
- os.system(command) # $ result=BAD
- os.popen(command) # $ result=BAD
- subprocess.call(command) # $ result=BAD
- subprocess.check_call(command) # $ result=BAD
- subprocess.run(command) # $ result=BAD
+ os.system(command) # $ Alert result=BAD
+ os.popen(command) # $ Alert result=BAD
+ subprocess.call(command) # $ Alert result=BAD
+ subprocess.check_call(command) # $ Alert result=BAD
+ subprocess.run(command) # $ Alert result=BAD
@app.route("/path-exists-not-sanitizer")
@@ -70,11 +70,11 @@ def path_exists_not_sanitizer():
"""
path = request.args.get('path', '')
if os.path.exists(path):
- os.system("ls " + path) # $ result=BAD
+ os.system("ls " + path) # $ Alert result=BAD
@app.route("/restricted-characters")
def restricted_characters():
path = request.args.get('path', '')
if re.match(r'^[a-zA-Z0-9_-]+$', path):
- os.system("ls " + path) # $ SPURIOUS: result=BAD
+ os.system("ls " + path) # $ Alert SPURIOUS: result=BAD
diff --git a/python/ql/test/query-tests/Security/CWE-078-UnsafeShellCommandConstruction/UnsafeShellCommandConstruction.qlref b/python/ql/test/query-tests/Security/CWE-078-UnsafeShellCommandConstruction/UnsafeShellCommandConstruction.qlref
index fdc01b9ecbf7..26c43ff16ca6 100644
--- a/python/ql/test/query-tests/Security/CWE-078-UnsafeShellCommandConstruction/UnsafeShellCommandConstruction.qlref
+++ b/python/ql/test/query-tests/Security/CWE-078-UnsafeShellCommandConstruction/UnsafeShellCommandConstruction.qlref
@@ -1 +1,2 @@
-Security/CWE-078/UnsafeShellCommandConstruction.ql
+query: Security/CWE-078/UnsafeShellCommandConstruction.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-078-UnsafeShellCommandConstruction/src/unsafe_shell_test.py b/python/ql/test/query-tests/Security/CWE-078-UnsafeShellCommandConstruction/src/unsafe_shell_test.py
index 95d05bbfaf0a..22c7513f02d7 100644
--- a/python/ql/test/query-tests/Security/CWE-078-UnsafeShellCommandConstruction/src/unsafe_shell_test.py
+++ b/python/ql/test/query-tests/Security/CWE-078-UnsafeShellCommandConstruction/src/unsafe_shell_test.py
@@ -1,45 +1,45 @@
import os
import subprocess
-def unsafe_shell_one(name):
- os.system("ping " + name) # $ result=BAD
+def unsafe_shell_one(name): # $ Source
+ os.system("ping " + name) # $ Alert result=BAD
# f-strings
- os.system(f"ping {name}") # $ result=BAD
+ os.system(f"ping {name}") # $ Alert result=BAD
# array.join
- os.system("ping " + " ".join(name)) # $ result=BAD
+ os.system("ping " + " ".join(name)) # $ Alert result=BAD
# array.join, with a list
- os.system("ping " + " ".join([name])) # $ result=BAD
+ os.system("ping " + " ".join([name])) # $ Alert result=BAD
# format, using .format
- os.system("ping {}".format(name)) # $ result=BAD
+ os.system("ping {}".format(name)) # $ Alert result=BAD
# format, using %
- os.system("ping %s" % name) # $ result=BAD
+ os.system("ping %s" % name) # $ Alert result=BAD
os.system(name) # OK - seems intentional.
import fabric
-def facbric_stuff (name):
+def facbric_stuff (name): # $ Source
fabric.api.run("ping " + name, shell=False) # OK
- fabric.api.run("ping " + name, shell=True) # $ result=BAD
+ fabric.api.run("ping " + name, shell=True) # $ Alert result=BAD
def indirect(flag):
fabric.api.run("ping " + name, shell=flag) # OK
indirect(False)
-def subprocess_flag (name):
+def subprocess_flag (name): # $ Source
subprocess.run("ping " + name, shell=False) # OK - and nonsensical
- subprocess.run("ping " + name, shell=True) # $ result=BAD
+ subprocess.run("ping " + name, shell=True) # $ Alert result=BAD
def indirect(flag, x):
- subprocess.run("ping " + x, shell=flag) # $ result=BAD
+ subprocess.run("ping " + x, shell=flag) # $ Alert result=BAD
indirect(True, name)
diff --git a/python/ql/test/query-tests/Security/CWE-079-Jinja2WithoutEscaping/Jinja2WithoutEscaping.qlref b/python/ql/test/query-tests/Security/CWE-079-Jinja2WithoutEscaping/Jinja2WithoutEscaping.qlref
index 9fefcf4a030d..d63a6068dc22 100644
--- a/python/ql/test/query-tests/Security/CWE-079-Jinja2WithoutEscaping/Jinja2WithoutEscaping.qlref
+++ b/python/ql/test/query-tests/Security/CWE-079-Jinja2WithoutEscaping/Jinja2WithoutEscaping.qlref
@@ -1 +1,2 @@
-Security/CWE-079/Jinja2WithoutEscaping.ql
+query: Security/CWE-079/Jinja2WithoutEscaping.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-079-Jinja2WithoutEscaping/jinja2_escaping.py b/python/ql/test/query-tests/Security/CWE-079-Jinja2WithoutEscaping/jinja2_escaping.py
index aed840ce8863..f3d1150df9ae 100644
--- a/python/ql/test/query-tests/Security/CWE-079-Jinja2WithoutEscaping/jinja2_escaping.py
+++ b/python/ql/test/query-tests/Security/CWE-079-Jinja2WithoutEscaping/jinja2_escaping.py
@@ -6,7 +6,7 @@
app = Flask(__name__)
loader = FileSystemLoader( searchpath="templates/" )
-unsafe_env = Environment(loader=loader)
+unsafe_env = Environment(loader=loader) # $ Alert
safe1_env = Environment(loader=loader, autoescape=True)
safe2_env = Environment(loader=loader, autoescape=select_autoescape())
@@ -38,18 +38,18 @@ def safe2():
auto = select_autoescape
e = Environment(autoescape=auto) # GOOD
z = 0
-e = Environment(autoescape=z) # BAD
+e = Environment(autoescape=z) # $ Alert # BAD
E = Environment
-E() # BAD
-E(autoescape=z) # BAD
+E() # $ Alert # BAD
+E(autoescape=z) # $ Alert # BAD
E(autoescape=auto) # GOOD
E(autoescape=0+1) # GOOD
def checked(cond=False):
if cond:
- e = Environment(autoescape=cond) # GOOD
+ e = Environment(autoescape=cond) # $ Alert # GOOD
-unsafe_tmpl = Template('Hello {{ name }}!')
+unsafe_tmpl = Template('Hello {{ name }}!') # $ Alert
safe1_tmpl = Template('Hello {{ name }}!', autoescape=True)
safe2_tmpl = Template('Hello {{ name }}!', autoescape=select_autoescape())
diff --git a/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/ReflectedXss.expected b/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/ReflectedXss.expected
index d332231e0c99..bf4f584c8157 100644
--- a/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/ReflectedXss.expected
+++ b/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/ReflectedXss.expected
@@ -1,3 +1,7 @@
+#select
+| reflected_xss.py:10:26:10:53 | ControlFlowNode for BinaryExpr | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | reflected_xss.py:10:26:10:53 | ControlFlowNode for BinaryExpr | Cross-site scripting vulnerability due to a $@. | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | user-provided value |
+| reflected_xss.py:22:26:22:41 | ControlFlowNode for Attribute() | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | reflected_xss.py:22:26:22:41 | ControlFlowNode for Attribute() | Cross-site scripting vulnerability due to a $@. | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | user-provided value |
+| reflected_xss.py:28:26:28:41 | ControlFlowNode for Attribute() | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | reflected_xss.py:28:26:28:41 | ControlFlowNode for Attribute() | Cross-site scripting vulnerability due to a $@. | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | user-provided value |
edges
| reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | reflected_xss.py:2:26:2:32 | ControlFlowNode for request | provenance | |
| reflected_xss.py:2:26:2:32 | ControlFlowNode for request | reflected_xss.py:9:18:9:24 | ControlFlowNode for request | provenance | |
@@ -28,7 +32,3 @@ nodes
| reflected_xss.py:27:23:27:29 | ControlFlowNode for request | semmle.label | ControlFlowNode for request |
| reflected_xss.py:28:26:28:41 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
subpaths
-#select
-| reflected_xss.py:10:26:10:53 | ControlFlowNode for BinaryExpr | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | reflected_xss.py:10:26:10:53 | ControlFlowNode for BinaryExpr | Cross-site scripting vulnerability due to a $@. | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | user-provided value |
-| reflected_xss.py:22:26:22:41 | ControlFlowNode for Attribute() | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | reflected_xss.py:22:26:22:41 | ControlFlowNode for Attribute() | Cross-site scripting vulnerability due to a $@. | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | user-provided value |
-| reflected_xss.py:28:26:28:41 | ControlFlowNode for Attribute() | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | reflected_xss.py:28:26:28:41 | ControlFlowNode for Attribute() | Cross-site scripting vulnerability due to a $@. | reflected_xss.py:2:26:2:32 | ControlFlowNode for ImportMember | user-provided value |
diff --git a/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/ReflectedXss.qlref b/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/ReflectedXss.qlref
index e0efe1024162..9cd0122e556e 100644
--- a/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/ReflectedXss.qlref
+++ b/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/ReflectedXss.qlref
@@ -1 +1,2 @@
-Security/CWE-079/ReflectedXss.ql
+query: Security/CWE-079/ReflectedXss.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/reflected_xss.py b/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/reflected_xss.py
index 98682f04f3cb..67fcf0bf9ffe 100644
--- a/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/reflected_xss.py
+++ b/python/ql/test/query-tests/Security/CWE-079-ReflectedXss/reflected_xss.py
@@ -1,5 +1,5 @@
import json
-from flask import Flask, request, make_response, escape, jsonify
+from flask import Flask, request, make_response, escape, jsonify # $ Source
app = Flask(__name__)
@@ -7,7 +7,7 @@
@app.route("/unsafe")
def unsafe():
first_name = request.args.get("name", "")
- return make_response("Your name is " + first_name) # NOT OK
+ return make_response("Your name is " + first_name) # $ Alert # NOT OK
@app.route("/safe")
@@ -19,13 +19,13 @@ def safe():
@app.route("/unsafe/json")
def unsafe_json():
data = json.loads(request.data)
- return make_response(json.dumps(data)) # NOT OK
+ return make_response(json.dumps(data)) # $ Alert # NOT OK
@app.route("/safe/json")
def safe_json():
data = json.loads(request.data)
- return make_response(json.dumps(data), 200, {'Content-Type': 'application/json'}) # OK, FP
+ return make_response(json.dumps(data), 200, {'Content-Type': 'application/json'}) # $ SPURIOUS: Alert # OK, FP
@app.route("/jsonify")
diff --git a/python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model/SqlInjection.qlref b/python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model/SqlInjection.qlref
index b6916bd2cd46..e19181577447 100644
--- a/python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model/SqlInjection.qlref
+++ b/python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model/SqlInjection.qlref
@@ -1,2 +1,4 @@
query: Security/CWE-089/SqlInjection.ql
-postprocess: utils/test/PrettyPrintModels.ql
+postprocess:
+ - utils/test/PrettyPrintModels.ql
+ - utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model/test.py b/python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model/test.py
index 97bfa393cedf..70959d0bff03 100644
--- a/python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model/test.py
+++ b/python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model/test.py
@@ -3,4 +3,4 @@
import psycopg
conn = psycopg.connect(...)
-conn.execute(sys.argv[1])
+conn.execute(sys.argv[1]) # $ Alert
diff --git a/python/ql/test/query-tests/Security/CWE-090-LdapInjection/LdapInjection.qlref b/python/ql/test/query-tests/Security/CWE-090-LdapInjection/LdapInjection.qlref
index 19112f987ada..87db0e58f847 100644
--- a/python/ql/test/query-tests/Security/CWE-090-LdapInjection/LdapInjection.qlref
+++ b/python/ql/test/query-tests/Security/CWE-090-LdapInjection/LdapInjection.qlref
@@ -1 +1,2 @@
-Security/CWE-090/LdapInjection.ql
+query: Security/CWE-090/LdapInjection.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-090-LdapInjection/ldap3_bad.py b/python/ql/test/query-tests/Security/CWE-090-LdapInjection/ldap3_bad.py
index 2edb986fccfc..a69aef9ad3d8 100644
--- a/python/ql/test/query-tests/Security/CWE-090-LdapInjection/ldap3_bad.py
+++ b/python/ql/test/query-tests/Security/CWE-090-LdapInjection/ldap3_bad.py
@@ -1,4 +1,4 @@
-from flask import request, Flask
+from flask import request, Flask # $ Source
import ldap3
app = Flask(__name__)
@@ -18,7 +18,7 @@ def normal():
srv = ldap3.Server('ldap://127.0.0.1')
conn = ldap3.Connection(srv, user=dn, auto_bind=True)
- conn.search(dn, search_filter)
+ conn.search(dn, search_filter) # $ Alert
@app.route("/direct")
@@ -35,7 +35,7 @@ def direct():
srv = ldap3.Server('ldap://127.0.0.1')
conn = ldap3.Connection(srv, user=dn, auto_bind=True).search(
- dn, search_filter)
+ dn, search_filter) # $ Alert
# if __name__ == "__main__":
# app.run(debug=True)
diff --git a/python/ql/test/query-tests/Security/CWE-090-LdapInjection/ldap_bad.py b/python/ql/test/query-tests/Security/CWE-090-LdapInjection/ldap_bad.py
index 133b0baaf9c0..8fd38f52f577 100644
--- a/python/ql/test/query-tests/Security/CWE-090-LdapInjection/ldap_bad.py
+++ b/python/ql/test/query-tests/Security/CWE-090-LdapInjection/ldap_bad.py
@@ -1,4 +1,4 @@
-from flask import request, Flask
+from flask import request, Flask # $ Source
import ldap
app = Flask(__name__)
@@ -18,7 +18,7 @@ def normal():
ldap_connection = ldap.initialize("ldap://127.0.0.1")
user = ldap_connection.search_s(
- dn, ldap.SCOPE_SUBTREE, search_filter)
+ dn, ldap.SCOPE_SUBTREE, search_filter) # $ Alert
@app.route("/direct")
@@ -34,7 +34,7 @@ def direct():
search_filter = "(user={})".format(unsafe_filter)
user = ldap.initialize("ldap://127.0.0.1").search_s(
- dn, ldap.SCOPE_SUBTREE, search_filter)
+ dn, ldap.SCOPE_SUBTREE, search_filter) # $ Alert
@app.route("/normal_argbyname")
@@ -52,7 +52,7 @@ def normal_argbyname():
ldap_connection = ldap.initialize("ldap://127.0.0.1")
user = ldap_connection.search_s(
- dn, ldap.SCOPE_SUBTREE, filterstr=search_filter)
+ dn, ldap.SCOPE_SUBTREE, filterstr=search_filter) # $ Alert
# if __name__ == "__main__":
diff --git a/python/ql/test/query-tests/Security/CWE-113-HeaderInjection/Tests2-with-wsgi-validator/HeaderInjection.qlref b/python/ql/test/query-tests/Security/CWE-113-HeaderInjection/Tests2-with-wsgi-validator/HeaderInjection.qlref
index 7dbe28e4b591..4379f3d416b4 100644
--- a/python/ql/test/query-tests/Security/CWE-113-HeaderInjection/Tests2-with-wsgi-validator/HeaderInjection.qlref
+++ b/python/ql/test/query-tests/Security/CWE-113-HeaderInjection/Tests2-with-wsgi-validator/HeaderInjection.qlref
@@ -1 +1,2 @@
-Security/CWE-113/HeaderInjection.ql
\ No newline at end of file
+query: Security/CWE-113/HeaderInjection.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-116-BadTagFilter/BadTagFilter.qlref b/python/ql/test/query-tests/Security/CWE-116-BadTagFilter/BadTagFilter.qlref
index e5fc84fd48a9..443c007de0cb 100644
--- a/python/ql/test/query-tests/Security/CWE-116-BadTagFilter/BadTagFilter.qlref
+++ b/python/ql/test/query-tests/Security/CWE-116-BadTagFilter/BadTagFilter.qlref
@@ -1 +1,2 @@
-Security/CWE-116/BadTagFilter.ql
+query: Security/CWE-116/BadTagFilter.ql
+postprocess: utils/test/InlineExpectationsTestQuery.ql
diff --git a/python/ql/test/query-tests/Security/CWE-116-BadTagFilter/tst.py b/python/ql/test/query-tests/Security/CWE-116-BadTagFilter/tst.py
index 2c3ec0667e39..04b81be29e6c 100644
--- a/python/ql/test/query-tests/Security/CWE-116-BadTagFilter/tst.py
+++ b/python/ql/test/query-tests/Security/CWE-116-BadTagFilter/tst.py
@@ -1,28 +1,28 @@
import re
filters = [
- re.compile(r""".*?<\/script>""", re.IGNORECASE), # NOT OK - doesn't match newlines or ``
- re.compile(r""".*?<\/script>""", re.IGNORECASE | re.DOTALL), # NOT OK - doesn't match ``
+ re.compile(r""".*?<\/script>""", re.IGNORECASE), # $ Alert # NOT OK - doesn't match newlines or ``
+ re.compile(r""".*?<\/script>""", re.IGNORECASE | re.DOTALL), # $ Alert # NOT OK - doesn't match ``
re.compile(r""".*?<\/script[^>]*>""", re.IGNORECASE | re.DOTALL), # OK
re.compile(r"""""", re.IGNORECASE | re.DOTALL), # OK - we don't care regexps that only match comments
re.compile(r""")|([^\/\s>]+)[\S\s]*?>"""), #// NOT OK - doesn't match comments with the right capture groups
- re.compile(r"""<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\/\s>]+)((?:\s+[\w\-:.]+(?:\s*=\s*?(?:(?:"[^"]*")|(?:'[^']*')|[^\s"'\/>]+))?)*)[\S\s]*?(\/?)>))"""), # NOT OK - capture groups
- re.compile(r"""(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|)""", re.IGNORECASE), # NOT OK - capture groups
- re.compile(r"""<(?:(?:!--([\w\W]*?)-->)|(?:!\[CDATA\[([\w\W]*?)\]\]>)|(?:!DOCTYPE([\w\W]*?)>)|(?:\?([^\s\/<>]+) ?([\w\W]*?)[?/]>)|(?:\/([A-Za-z][A-Za-z0-9\-_\:\.]*)>)|(?:([A-Za-z][A-Za-z0-9\-_\:\.]*)((?:\s+[^"'>]+(?:(?:"[^"]*")|(?:'[^']*')|[^>]*))*|\/|\s+)>))"""), # NOT OK - capture groups
+ re.compile(r"""