@@ -287,7 +287,7 @@ def go(dirname, filename):
287
287
resp .close ()
288
288
289
289
here = os .path .dirname (__file__ )
290
- filename = os . path . join ( here , 'data.unknown_mime_type' )
290
+ filename = 'data.unknown_mime_type'
291
291
self .loop .run_until_complete (go (here , filename ))
292
292
293
293
def test_static_file_with_content_type (self ):
@@ -319,7 +319,7 @@ def go(dirname, filename):
319
319
resp .close ()
320
320
321
321
here = os .path .dirname (__file__ )
322
- filename = os . path . join ( here , 'software_development_in_picture.jpg' )
322
+ filename = 'software_development_in_picture.jpg'
323
323
self .loop .run_until_complete (go (here , filename ))
324
324
325
325
def test_static_file_with_content_encoding (self ):
@@ -342,9 +342,46 @@ def go(dirname, filename):
342
342
resp .close ()
343
343
344
344
here = os .path .dirname (__file__ )
345
- filename = os . path . join ( here , 'hello.txt.gz' )
345
+ filename = 'hello.txt.gz'
346
346
self .loop .run_until_complete (go (here , filename ))
347
347
348
+ def test_static_file_directory_traversal_attack (self ):
349
+
350
+ @asyncio .coroutine
351
+ def go (dirname , relpath ):
352
+ self .assertTrue (os .path .isfile (os .path .join (dirname , relpath )))
353
+
354
+ app , _ , url = yield from self .create_server ('GET' , '/static/' )
355
+ app .router .add_static ('/static' , dirname )
356
+
357
+ url_relpath = url + relpath
358
+ resp = yield from request ('GET' , url_relpath , loop = self .loop )
359
+ self .assertEqual (404 , resp .status )
360
+ resp .close ()
361
+
362
+ url_relpath2 = url + 'dir/../' + filename
363
+ resp = yield from request ('GET' , url_relpath2 , loop = self .loop )
364
+ self .assertEqual (404 , resp .status )
365
+ resp .close ()
366
+
367
+ url_abspath = \
368
+ url + os .path .abspath (os .path .join (dirname , filename ))
369
+ resp = yield from request ('GET' , url_abspath , loop = self .loop )
370
+ self .assertEqual (404 , resp .status )
371
+ resp .close ()
372
+
373
+ here = os .path .dirname (__file__ )
374
+ filename = '../README.rst'
375
+ self .loop .run_until_complete (go (here , filename ))
376
+
377
+ def test_static_route_path_existence_check (self ):
378
+ directory = os .path .dirname (__file__ )
379
+ web .StaticRoute (None , "/" , directory )
380
+
381
+ nodirectory = os .path .join (directory , "nonexistent-uPNiOEAg5d" )
382
+ with self .assertRaises (ValueError ):
383
+ web .StaticRoute (None , "/" , nodirectory )
384
+
348
385
def test_post_form_with_duplicate_keys (self ):
349
386
350
387
@asyncio .coroutine
0 commit comments