fix: monitor-agent.py parse board-config.sh safely

Replace exec() on shell scripts with regex line parsing to avoid
shell injection and only extract PORT from board-config.sh
This commit is contained in:
2026-05-29 20:17:20 -07:00
parent 14781b8c07
commit ece874a8ed
+13 -2
View File
@@ -8,11 +8,22 @@ import time
import threading import threading
import serial import serial
import select import select
import re
BOARD = sys.argv[1] if len(sys.argv) > 1 else "esp32-32e-4" BOARD = sys.argv[1] if len(sys.argv) > 1 else "esp32-32e-4"
# Load board config # Load board config - parse shell script format
exec(open(f"./boards/{BOARD}/board-config.sh").read().replace("export ", "")) board_config_path = f"./boards/{BOARD}/board-config.sh"
PORT = "/dev/ttyACM0" # Default
try:
with open(board_config_path, 'r') as f:
for line in f:
line = line.strip()
if line.startswith('PORT='):
PORT = line.split('=', 1)[1].strip()
break
except FileNotFoundError:
print(f"Warning: Board config not found: {board_config_path}")
SERIAL_PORT = os.environ.get("PORT", PORT) SERIAL_PORT = os.environ.get("PORT", PORT)
LOGFILE = f"/tmp/doorbell-{BOARD}.jsonl" LOGFILE = f"/tmp/doorbell-{BOARD}.jsonl"