Skip to content

Commit ef74d61

Browse files
committed
resolved comments: relaxed checks on filename to make it more realistic
1 parent b8f8658 commit ef74d61

File tree

1 file changed

+2
-4
lines changed
  • services/workshop/crapi/mechanic

1 file changed

+2
-4
lines changed

services/workshop/crapi/mechanic/views.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,13 @@ def get(self, request, format=None):
390390
)
391391
#Checks for directory traversal in plain as well as single URL-encoded form
392392
#Since Django automatically decodes URL-encoded parameters once
393-
if '..' in filename_from_user or '/' in filename_from_user:
393+
if '../' in filename_from_user:
394394
return Response(
395395
{"message": "Forbidden input."},
396396
status=status.HTTP_400_BAD_REQUEST
397397
)
398398
filename_from_user = unquote(filename_from_user)
399-
filename_from_user = filename_from_user.replace("../", "")
400-
401-
#VULNERABLE: Double URL-encoded nested path can be used for exploit
399+
#VULNERABLE: Double URL-encoded path can be used for exploit
402400
full_path = os.path.abspath(os.path.join(settings.BASE_DIR, "reports", filename_from_user))
403401
print(f"Attempting to serve file from: {full_path}")
404402
logger.info(f"Attempting to serve file from: {full_path}")

0 commit comments

Comments
 (0)