Skip to content

Commit 8e85dc7

Browse files
porcupineyhairsRasmusWL
andauthored
Apply suggestions from code review
Co-authored-by: Rasmus Wriedt Larsen <rasmuswriedtlarsen@gmail.com>
1 parent a97f942 commit 8e85dc7

File tree

8 files changed

+16
-21
lines changed

8 files changed

+16
-21
lines changed

python/ql/src/experimental/semmle/python/templates/Cheetah.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ClassValue theCheetahTemplateClass() { result = Value::named("Cheetah.Template.T
1717
* contents = 'Hello World!'
1818
* t3 = Template3("sink")
1919
*
20-
* This should also detect cases of the following type :
20+
* This will also detect cases of the following type :
2121
*
2222
* from Cheetah.Template import Template
2323
* t3 = Template("sink")

python/ql/src/experimental/semmle/python/templates/Jinja.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Value theJinja2FromStringValue() { result = Value::named("jinja2.from_string") }
1717
* template = Template(`sink`)
1818
*/
1919
class Jinja2TemplateSink extends SSTISink {
20-
override string toString() { result = "argument to Jinja2.template()" }
20+
override string toString() { result = "argument to jinja2.Template()" }
2121

2222
Jinja2TemplateSink() {
2323
exists(CallNode call |
@@ -30,13 +30,13 @@ class Jinja2TemplateSink extends SSTISink {
3030
}
3131

3232
/**
33-
* Sink representing the `jinja2.Template` class instantiation argument.
33+
* Sink representing the `jinja2.from_string` function call argument.
3434
*
35-
* from jinja2 import Template
36-
* template = Template(`sink`)
35+
* from jinja2 import from_string
36+
* template = from_string(`sink`)
3737
*/
3838
class Jinja2FromStringSink extends SSTISink {
39-
override string toString() { result = "argument to Jinja2.from_string()" }
39+
override string toString() { result = "argument to jinja2.from_string()" }
4040

4141
Jinja2FromStringSink() {
4242
exists(CallNode call |

python/ql/src/experimental/semmle/python/templates/SSTISink.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import semmle.python.dataflow.TaintTracking
22

33
/**
44
* A generic taint sink that is vulnerable to template inclusions.
5-
* The `temp` in `Jinja2.Template(temp)` and similar.
5+
* The `temp` in `jinja2.Template(temp)` and similar.
66
*/
77
abstract class SSTISink extends TaintSink { }

python/ql/src/semmle/python/templates/Templates.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import python
2-
import semmle.python.dataflow.TaintTracking
32

43
abstract class Template extends Module { }
54

python/ql/test/experimental/CWE-074/AirspeedSsti.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
app = Flask(__name__)
66

77

8-
@app.route("/")
9-
10-
118
@route('/other')
129
def a():
1310
template = request.args.get('template')

python/ql/test/experimental/CWE-074/FlaskTemplate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def home():
1212

1313

1414
@app.route("/a")
15-
def home():
15+
def a():
1616
import flask
1717
return flask.render_template_string(request.args.get('template'))
1818

python/ql/test/experimental/CWE-074/JinjaSsti.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from jinja2 import Environment, DictLoader, escape
55

66

7-
def j(request):
7+
def a(request):
88
# Load the template
99
template = request.GET['template']
1010
t = Jinja2_Template(template)
@@ -13,7 +13,7 @@ def j(request):
1313
html = t.render(name=escape(name))
1414
return HttpResponse(html)
1515

16-
def j2(request):
16+
def b(request):
1717
import jinja2
1818
# Load the template
1919
template = request.GET['template']
@@ -25,6 +25,6 @@ def j2(request):
2525

2626

2727
urlpatterns = [
28-
path('', jinja),
29-
path('', jinja2)
28+
path('a', a),
29+
path('b', b)
3030
]

python/ql/test/experimental/CWE-074/TRender.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
from django.http import HttpResponse
33
from trender import TRender
44

5-
urlpatterns = [
6-
path('', trender)
7-
]
8-
9-
105
def trender(request):
116
template = request.GET['template']
127
compiled = TRender(template)
138
return HttpResponse(compiled)
9+
10+
urlpatterns = [
11+
path('', trender)
12+
]

0 commit comments

Comments
 (0)