File tree Expand file tree Collapse file tree 4 files changed +22
-0
lines changed Expand file tree Collapse file tree 4 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,15 @@ def cache_request(request, response):
131
131
# XXX TODO: Support JSON and xml
132
132
"text/html" in response ["Content-Type" ]
133
133
):
134
+ # When you have url patterns like `/foo/(?P<oid>.*)` you can get requests
135
+ # that match but if the URL is something like
136
+ # "/foo/myslug%0Anextline" which translates to `/foo/myslug\nnextline`.
137
+ # The Django view will match just fine but the request.path will have a
138
+ # `\s` character in it.
139
+ # If that's the case we don't want to cache this request.
140
+ if "\n " in request .path or "\t " in request .path :
141
+ return False
142
+
134
143
# let's iterate through some exceptions
135
144
not_starts = (
136
145
"/plog/edit/" ,
Original file line number Diff line number Diff line change @@ -50,3 +50,8 @@ def test_cache_request():
50
50
request ._fscache_disable = True
51
51
response = http .HttpResponse ()
52
52
assert not fscache .cache_request (request , response )
53
+
54
+ request = RequestFactory ().get ("/\n something" )
55
+ request .user = AnonymousUser ()
56
+ response = http .HttpResponse ()
57
+ assert not fscache .cache_request (request , response )
Original file line number Diff line number Diff line change @@ -188,3 +188,9 @@ def test_blog_post_ping(self):
188
188
189
189
hit , = BlogItemHit .objects .all ()
190
190
assert hit .blogitem == blog
191
+
192
+ def test_blog_post_with_newline_request_path (self ):
193
+ url = reverse ("blog_post" , args = ["myoid" ])
194
+ url += "\n Otherstuff"
195
+ response = self .client .get (url )
196
+ assert response .status_code == 302
Original file line number Diff line number Diff line change @@ -134,6 +134,8 @@ def _blog_post_key_prefixer(request):
134
134
@cache_control (public = True , max_age = settings .DEBUG and ONE_HOUR or ONE_WEEK )
135
135
@cache_page (settings .DEBUG and ONE_HOUR or ONE_WEEK , _blog_post_key_prefixer )
136
136
def blog_post (request , oid ):
137
+ if '\n ' in request .path :
138
+ return redirect (reverse ('blog_post' , args = [oid ]))
137
139
if request .path .endswith ("/ping" ):
138
140
# Sometimes this can happen when the URL parsing by Django
139
141
# isn't working out.
You can’t perform that action at this time.
0 commit comments