Skip to content

Commit cea196e

Browse files
Add concepts tests + some fixes
1 parent 1cb01a2 commit cea196e

29 files changed

+133
-8
lines changed

python/ql/lib/semmle/python/frameworks/Flask.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,13 @@ module Flask {
722722
}
723723
}
724724

725-
/** A call to `flask.render_template_string` as a template construction sink. */
725+
/** A call to `flask.render_template_string` or `flask.stream_template_string` as a template construction sink. */
726726
private class FlaskTemplateConstruction extends TemplateConstruction::Range, API::CallNode {
727727
FlaskTemplateConstruction() {
728-
this = API::moduleImport("flask").getMember("render_template_string").getACall()
728+
this =
729+
API::moduleImport("flask")
730+
.getMember(["render_template_string", "stream_template_string"])
731+
.getACall()
729732
}
730733

731734
override DataFlow::Node getSourceArg() { result = this.getArg(0) }

python/ql/lib/semmle/python/frameworks/Genshi.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module Genshi {
2121
API::moduleImport("genshi")
2222
.getMember("template")
2323
.getMember("text")
24-
.getMember(["NewTextTemplate", "OldTextTemplate"])
24+
.getMember(["NewTextTemplate", "OldTextTemplate", "TextTemplate"])
2525
.getACall()
2626
}
2727

python/ql/lib/semmle/python/frameworks/Jinja2.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Jinja2 {
2424
override DataFlow::Node getSourceArg() { result = this.getArg(0) }
2525
}
2626

27+
/** Definitions for modeling jinja `Environment`s. */
2728
module EnvironmentClass {
2829
/** Gets a reference to the `jinja2.Environment` class. */
2930
API::Node classRef() {

python/ql/test/experimental/meta/ConceptsTest.qll

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,20 @@ module CorsMiddlewareTest implements TestSig {
663663
}
664664
}
665665

666+
module TemplateConstructionTest implements TestSig {
667+
string getARelevantTag() { result = "templateConstruction" }
668+
669+
predicate hasActualResult(Location location, string element, string tag, string value) {
670+
exists(location.getFile().getRelativePath()) and
671+
exists(TemplateConstruction tc |
672+
location = tc.getLocation() and
673+
element = tc.toString() and
674+
value = prettyNodeForInlineTest(tc.getSourceArg()) and
675+
tag = "templateConstruction"
676+
)
677+
}
678+
}
679+
666680
import MakeTest<MergeTests5<MergeTests5<SystemCommandExecutionTest, DecodingTest, EncodingTest, LoggingTest,
667681
CodeExecutionTest>,
668682
MergeTests5<SqlConstructionTest, SqlExecutionTest, XPathConstructionTest, XPathExecutionTest,
@@ -673,4 +687,5 @@ import MakeTest<MergeTests5<MergeTests5<SystemCommandExecutionTest, DecodingTest
673687
MergeTests5<FileSystemAccessTest, FileSystemWriteAccessTest, PathNormalizationTest,
674688
SafeAccessCheckTest, PublicKeyGenerationTest>,
675689
MergeTests5<CryptographicOperationTest, HttpClientRequestTest, CsrfProtectionSettingTest,
676-
CsrfLocalProtectionSettingTest, MergeTests<XmlParsingTest, ThreatModelSourceTest>>>>
690+
CsrfLocalProtectionSettingTest,
691+
MergeTests3<XmlParsingTest, ThreatModelSourceTest, TemplateConstructionTest>>>>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import python
2+
import experimental.meta.ConceptsTest
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from genshi.template.text import TextTemplate, NewTextTemplate, OldTextTemplate
2+
from genshi.template.markup import MarkupTemplate
3+
4+
def test():
5+
a = TextTemplate("abc") # $ templateConstruction="abc"
6+
a = OldTextTemplate("abc") # $ templateConstruction="abc"
7+
a = NewTextTemplate("abc") # $ templateConstruction="abc"
8+
a = MarkupTemplate("abc") # $ templateConstruction="abc"
9+
return a
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import python
2+
import experimental.meta.ConceptsTest
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from mako.template import Template
2+
3+
def test():
4+
return Template("abc") # $ templateConstruction="abc"

0 commit comments

Comments
 (0)