Skip to content
Merged
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
17 changes: 13 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,26 @@
log_path = body.get("path", "")
log_format = body.get("format", "auto")

if not os.path.isabs(log_path):
return jsonify({"error": "Path must be absolute"}), 400

real_log_path = os.path.realpath(log_path)
allowed_paths = app.config.get("MONITOR_ALLOWED_PATHS", [])
if not any(log_path.startswith(p) for p in allowed_paths):
allowed_roots = [os.path.realpath(p) for p in allowed_paths]

if not any(
os.path.commonpath([real_log_path, root]) == root
for root in allowed_roots
):
return jsonify({"error": "Path not in allowed monitor paths"}), 403

if not os.path.isfile(log_path):
if not os.path.isfile(real_log_path):

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
return jsonify({"error": "File not found"}), 404

def tail_worker():
parser = LogParser(log_format=log_format)
detector = IPDetector()
with open(log_path, "r", encoding="utf-8", errors="ignore") as fh:
with open(real_log_path, "r", encoding="utf-8", errors="ignore") as fh:
fh.seek(0, 2) # jump to end
while True:
line = fh.readline()
Expand All @@ -283,7 +292,7 @@

t = threading.Thread(target=tail_worker, daemon=True)
t.start()
return jsonify({"status": "monitoring started", "path": log_path})
return jsonify({"status": "monitoring started", "path": real_log_path})


# ---------------------------------------------------------------------------
Expand Down
Loading