Skip to content

Commit ed8bbe3

Browse files
author
Rob Myers
committed
Handle penetration testing URLs containing non-ASCII characters.
1 parent 56a4f44 commit ed8bbe3

File tree

1 file changed

+14
-4
lines changed
  • python_env/src/cc.engine/cc/engine

1 file changed

+14
-4
lines changed

python_env/src/cc.engine/cc/engine/app.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def clean_lang(self, request):
3636
if not re.match(r'^[a-z]{2}([-_][a-zA-Z]{2})?$',
3737
request_form['lang']):
3838
del request_form['lang']
39-
39+
4040
def __call__(self, environ, start_response):
4141
request = Request(environ)
4242
path_info = request.path_info
@@ -54,9 +54,19 @@ def __call__(self, environ, start_response):
5454
if request.GET:
5555
new_path_info = '%s?%s' % (
5656
new_path_info, urllib.urlencode(request.GET))
57-
redirect = exc.HTTPFound(location=new_path_info)
58-
return request.get_response(redirect)(environ, start_response)
59-
57+
# If the url contains higher-than-ASCII characters this fails.
58+
# Since such urls are broken, don't redirect. Fall through to
59+
# the 404.
60+
# The reason for handing this is that we're seeing (2017) a lot
61+
# of penetration testing requests of the form
62+
# /licenses/by-nd/2.0/%EF%BB%BF%EF%BB%BFThe
63+
try:
64+
redirect = exc.HTTPFound(location=new_path_info)
65+
return request.get_response(redirect)(environ,
66+
start_response)
67+
except UnicodeEncodeError, e:
68+
# Don't send the Found, fall through to the 404
69+
pass
6070
# Return a 404
6171
response = util.generate_404_response(
6272
request, routing, environ, self.staticdirector)

0 commit comments

Comments
 (0)