Implemented better testing and fixed skipepd frames

This commit is contained in:
Martino Ferrari
2026-07-01 16:39:34 +02:00
parent 7a326c5d78
commit 0bea41f866
46 changed files with 4358 additions and 1739 deletions
+52 -3
View File
@@ -17,6 +17,40 @@ import (
"marte2/common/wshub"
)
// ---------------------------------------------------------------------------
// Command safety gate (CR-4)
// ---------------------------------------------------------------------------
// dangerousCommandsEnabled gates commands that mutate the RT application state
// (FORCE, PAUSE, RESUME, STEP, BREAK, MSG). Set via --enable-dangerous-commands.
var dangerousCommandsEnabled = false
// dangerousCommands is the set of MARTe2 commands that can change signal values
// or alter execution flow. Without --enable-dangerous-commands these are blocked
// from the browser WebSocket path.
var dangerousCommands = map[string]bool{
"FORCE": true,
"UNFORCE": true,
"PAUSE": true,
"RESUME": true,
"STEP": true,
"BREAK": true,
"UNBREAK": true,
"MSG": true,
"LOAD": true,
"UNLOAD": true,
}
// isDangerousCommand returns true if the command's first word is in the
// dangerous set (case-insensitive).
func isDangerousCommand(cmd string) bool {
parts := strings.Fields(cmd)
if len(parts) == 0 {
return false
}
return dangerousCommands[strings.ToUpper(parts[0])]
}
// ---------------------------------------------------------------------------
// Signal metadata (populated by DISCOVER)
// ---------------------------------------------------------------------------
@@ -256,10 +290,25 @@ func (m *MarteController) HandleBrowserCommand(msg []byte) {
return
}
cmd, _ := data["cmd"].(string)
if cmd != "" {
m.trackForcedCmd(cmd)
m.SendCommand(cmd)
if cmd == "" {
return
}
// Gate dangerous commands (FORCE/UNFORCE/PAUSE/RESUME/STEP/BREAK/MSG)
// behind an explicit opt-in flag. Without it, only read-only commands
// (DISCOVER, TREE, INFO, LS, VALUE, TRACE, UNTRACE, STEP_STATUS) are
// forwarded to the MARTe2 TCP control connection.
if isDangerousCommand(cmd) {
if !dangerousCommandsEnabled {
broadcastHub(m.hub, map[string]any{
"type": "log", "time": time.Now().Format("15:04:05.000"),
"level": "WARNING",
"message": fmt.Sprintf("Blocked dangerous command (requires --enable-dangerous-commands): %s", cmd),
})
return
}
}
m.trackForcedCmd(cmd)
m.SendCommand(cmd)
}
}