Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90bbfd3

Browse files
committed
Python: Add library tests for django.
1 parent 46b9ef7 commit 90bbfd3

9 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| test.py:18 | Str | externally controlled string |
2+
| test.py:21 | BinaryExpr | externally controlled string |
3+
| test.py:24 | BinaryExpr | externally controlled string |
4+
| test.py:25 | BinaryExpr | externally controlled string |
5+
| test.py:26 | BinaryExpr | externally controlled string |
6+
| test.py:34 | BinaryExpr | externally controlled string |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
import python
3+
4+
import semmle.python.web.HttpRequest
5+
import semmle.python.web.HttpResponse
6+
import semmle.python.web.django.Db
7+
import semmle.python.web.django.Model
8+
9+
import semmle.python.security.strings.Untrusted
10+
11+
from TaintSink sink, TaintKind kind
12+
where sink.sinks(kind)
13+
select sink.getLocation().toString(), sink.(ControlFlowNode).getNode().toString(), kind
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.py:11 | request | django.request.HttpRequest |
2+
| test.py:31 | request | django.request.HttpRequest |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
import python
3+
4+
import semmle.python.web.HttpRequest
5+
import semmle.python.security.strings.Untrusted
6+
7+
8+
from TaintSource src, TaintKind kind
9+
where src.isSourceOf(kind)
10+
select src.getLocation().toString(), src.(ControlFlowNode).getNode().toString(), kind
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
semmle-extractor-options: --max-import-depth=3 --lang=3 -p ../../../query-tests/Security/lib/
2+
optimize: true
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
from django.conf.urls import patterns, url
3+
from django.db import connection, models
4+
from django.db.models.expressions import RawSQL
5+
from django.http.response import HttpResponse
6+
import base64
7+
8+
class Name(models.Model):
9+
pass
10+
11+
def save_name(request):
12+
13+
if request.method == 'POST':
14+
name = request.POST.get('name')
15+
curs = connection.cursor()
16+
#GOOD -- Using parameters
17+
curs.execute(
18+
"insert into names_file ('name') values ('%s')", name)
19+
#BAD -- Using string formatting
20+
curs.execute(
21+
"insert into names_file ('name') values ('%s')" % name)
22+
23+
#BAD -- other ways of executing raw SQL code with string interpolation
24+
Name.objects.annotate(RawSQL("insert into names_file ('name') values ('%s')" % name))
25+
Name.objects.raw("insert into names_file ('name') values ('%s')" % name)
26+
Name.objects.extra("insert into names_file ('name') values ('%s')" % name)
27+
28+
urlpatterns1 = patterns(url(r'^save_name/$',
29+
save_name, name='save_name'))
30+
31+
def maybe_xss(request):
32+
first_name = request.POST.get('first_name', '')
33+
resp = HttpResponse()
34+
resp.write("first name is " + first_name)
35+
return resp
36+
37+
urlpatterns2 = [
38+
# Route to code_execution
39+
url(r'^maybe_xss$', maybe_xss, name='maybe_xss')
40+
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .response import HttpResponse
2+
from .request import HttpRequest
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class HttpRequest(object):
2+
pass
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class HttpResponse(object):
2+
pass

0 commit comments

Comments
 (0)