Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit f6388b3

Browse files
committed
Release the code!
Signed-off-by: David Black <[email protected]>
1 parent 3a66090 commit f6388b3

36 files changed

+1119
-0
lines changed

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright © 2012 - 2013 Atlassian Corporation Pty Ltd.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions
5+
are met:
6+
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This package contains a django template parser that can be used to find templates
2+
that contain variables that will not be escaped. This package currently has
3+
no knowledge of custom filters, custom tags, and python code (e.g. uses of
4+
mark safe). The code has only been tested against django 1.5.
5+
6+
Use:
7+
This package can be used on the command line by running
8+
python -m django_xss_detection.cli

django_xss_detection/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__="0.4.9"

django_xss_detection/cli.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import argparse
2+
import collections
3+
import json
4+
5+
from . import util
6+
7+
8+
def setup_option():
9+
opt = argparse.ArgumentParser(description = \
10+
"Find potential xss bugs in a django app!")
11+
opt.add_argument("-d", "--template-directory", dest="template_dirs",
12+
action="append", help = "Specify a template directory. " +
13+
"This argument can be specified multiple times.", required=True)
14+
opt.add_argument("-j", "--json", dest="json_output",
15+
action="store_true", help = "Print results out as JSON.")
16+
return opt
17+
18+
def main(template_dirs, json_output=False):
19+
util.configure_django(template_dirs)
20+
f_results = util.walk_templates(template_dirs)
21+
if json_output:
22+
_output_results_in_json(f_results)
23+
else:
24+
for template_name, results in f_results.iteritems():
25+
print template_name
26+
for result in results:
27+
print ' ', result
28+
29+
def _output_results_in_json(f_results):
30+
""" Prints out results in JSON in the following format:
31+
{'filename' : [{'result ...}, 'filename_two' : [...] }
32+
"""
33+
out = collections.defaultdict(list)
34+
for filename, results in f_results.iteritems():
35+
for result in results:
36+
result_dict = {'line_number' : result.get_line_number(),
37+
'finding_reason' : result._get_reason(),
38+
'vulnerability_text' :
39+
result.get_vulnerability_text(),
40+
}
41+
out[result.get_filename()].append(result_dict)
42+
print json.dumps(out)
43+
44+
def from_cli():
45+
opt = setup_option()
46+
args = opt.parse_args()
47+
main(args.template_dirs, args.json_output)
48+
49+
if __name__=="__main__":
50+
from_cli()

django_xss_detection/loaders/__init__.py

Whitespace-only changes.

django_xss_detection/loaders/nop.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.template.loader import BaseLoader, get_template_from_string
2+
3+
class Loader(BaseLoader):
4+
""" This loader will always return an 'empty' template and *therefore*
5+
*should* be the last loader in settings.TEMPLATE_LOADERS.
6+
"""
7+
is_usable = True
8+
def load_template(self, template_name, template_dirs=None):
9+
template = get_template_from_string('', None, template_name)
10+
return template, None
11+
12+
def load_template_source(self, template_name, template_dirs=None):
13+
return '', None

0 commit comments

Comments
 (0)