Skip to content

Commit ba6baec

Browse files
committed
fix(security): address review findings in build_run and monitor_helper
- build_run.py: subtract 1s tolerance from build_start before comparing mtime to prevent false-positive rejection on filesystems with 1-second mtime granularity when the build completes in under one second - monitor_helper.py: use wmic to verify process CommandLine on Windows instead of unconditionally returning True; use os.path.realpath on both sides of the log-path confinement check to block symlink-based escapes
1 parent 85ec6fd commit ba6baec

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

skills/tuyaopen/debug-helper/scripts/monitor_helper.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ def _is_running(pid):
118118
def _is_monitor_process(pid):
119119
"""Verify PID belongs to a tos.py monitor process to avoid killing unrelated processes."""
120120
if sys.platform == "win32":
121-
return True # tasklist presence check in _is_running is sufficient on Windows
121+
result = subprocess.run(
122+
["wmic", "process", "where", f"ProcessId={pid}", "get", "CommandLine"],
123+
capture_output=True, text=True,
124+
)
125+
cmdline = result.stdout
126+
return "tos.py" in cmdline and "monitor" in cmdline
122127
try:
123128
with open(f"/proc/{pid}/cmdline", "rb") as f:
124129
cmdline = f.read().replace(b"\x00", b" ").decode("utf-8", errors="replace")
@@ -154,8 +159,8 @@ def cmd_start(port, log_file, as_json):
154159
ts = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
155160
log_file = os.path.join(SESSION_DIR, f"{ts}.log")
156161
else:
157-
abs_log = os.path.abspath(log_file)
158-
abs_session = os.path.abspath(SESSION_DIR)
162+
abs_log = os.path.realpath(os.path.abspath(log_file))
163+
abs_session = os.path.realpath(os.path.abspath(SESSION_DIR))
159164
if not abs_log.startswith(abs_session + os.sep):
160165
_out({"ok": False, "error": "Log file must be within .target_logging/ directory"}, as_json)
161166
sys.exit(1)

skills/tuyaopen/dev-loop/scripts/build_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def main():
7070
print("[ERROR] No executable found in dist/ or .build/bin/")
7171
sys.exit(1)
7272

73-
if os.path.getmtime(binary) < build_start:
73+
if os.path.getmtime(binary) < build_start - 1.0:
7474
print(f"[ERROR] Binary '{binary}' predates this build — possible stale or injected file.")
7575
sys.exit(1)
7676

0 commit comments

Comments
 (0)