mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
Python: Restore rest of experimental files
This commit is contained in:
19
python/ql/src/experimental/Security/CWE-074/JinjaBad.py
Normal file
19
python/ql/src/experimental/Security/CWE-074/JinjaBad.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from django.urls import path
|
||||
from django.http import HttpResponse
|
||||
from jinja2 import Template as Jinja2_Template
|
||||
from jinja2 import Environment, DictLoader, escape
|
||||
|
||||
|
||||
def a(request):
|
||||
# Load the template
|
||||
template = request.GET['template']
|
||||
t = Jinja2_Template(template)
|
||||
name = request.GET['name']
|
||||
# Render the template with the context data
|
||||
html = t.render(name=escape(name))
|
||||
return HttpResponse(html)
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('a', a),
|
||||
]
|
||||
20
python/ql/src/experimental/Security/CWE-074/JinjaGood.py
Normal file
20
python/ql/src/experimental/Security/CWE-074/JinjaGood.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from django.urls import path
|
||||
from django.http import HttpResponse
|
||||
from jinja2 import Template as Jinja2_Template
|
||||
from jinja2 import Environment, DictLoader, escape
|
||||
|
||||
|
||||
def a(request):
|
||||
# Load the template
|
||||
template = request.GET['template']
|
||||
env = SandboxedEnvironment(undefined=StrictUndefined)
|
||||
t = env.from_string(template)
|
||||
name = request.GET['name']
|
||||
# Render the template with the context data
|
||||
html = t.render(name=escape(name))
|
||||
return HttpResponse(html)
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('a', a),
|
||||
]
|
||||
Reference in New Issue
Block a user