Skip to content

AutoFix PR #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion flask_webgoat/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import base64
from pathlib import Path
import subprocess
import re

from flask import Blueprint, request, jsonify, session

Expand All @@ -23,6 +24,9 @@ def log_entry():
if text_param is None:
return jsonify({"error": "text parameter is required"})

# Sanitize filename_param to prevent directory traversal
filename_param = re.sub(r'[^\w\s-]', '', filename_param)

user_id = user_info[0]
user_dir = "data/" + str(user_id)
user_dir_path = Path(user_dir)
Expand All @@ -32,7 +36,6 @@ def log_entry():
filename = filename_param + ".txt"
path = Path(user_dir + "/" + filename)
with path.open("w", encoding="utf-8") as open_file:
# vulnerability: Directory Traversal
open_file.write(text_param)
return jsonify({"success": True})

Expand Down Expand Up @@ -60,3 +63,4 @@ def deserialized_descr():
# vulnerability: Insecure Deserialization
deserialized = pickle.loads(data)
return jsonify({"success": True, "description": str(deserialized)})

Loading