High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: make attach indicator port interpolation safe
Luigi Agosti4242e4c9faef
diff --git a/internal/bridge/attach_indicator.go b/internal/bridge/attach_indicator.goindex c8756557..c0053452 100644--- a/internal/bridge/attach_indicator.go+++ b/internal/bridge/attach_indicator.go@@ -2,7 +2,6 @@ package bridgeimport ("context"- "encoding/json""fmt""log/slog""strconv"@@ -26,7 +25,7 @@ func attachIndicatorScript(port string) (string, error) {if err != nil || value < 1 || value > 65535 {return "", fmt.Errorf("invalid bridge port %q", port)}- portJSON, _ := json.Marshal(value)+ portLiteral := strconv.Itoa(value)return fmt.Sprintf(`(() => {const key = "__pinchtabAttachIndicators";const port = %s;@@ -51,7 +50,7 @@ func attachIndicatorScript(port string) (string, error) {if (document.head) state.observer.observe(document.head, {subtree:true, childList:true, characterData:true});};if (document.head) state.start(); else document.addEventListener("DOMContentLoaded", state.start, {once:true});-})()`, portJSON), nil+})()`, portLiteral), nil}func clearAttachIndicatorScript(port string) (string, error) {@@ -59,7 +58,7 @@ func clearAttachIndicatorScript(port string) (string, error) {if err != nil || value < 1 || value > 65535 {return "", fmt.Errorf("invalid bridge port %q", port)}- portJSON, _ := json.Marshal(value)+ portLiteral := strconv.Itoa(value)return fmt.Sprintf(`(() => {const key = "__pinchtabAttachIndicators";const port = %s;@@ -81,7 +80,7 @@ func clearAttachIndicatorScript(port string) (string, error) {return;}document.title = "[PinchTab " + ports.map(p => ":" + p).join(",") + "] " + clean;-})()`, portJSON), nil+})()`, portLiteral), nil}func (b *Bridge) installAttachIndicator(ctx context.Context, tabID string) error {diff --git a/internal/bridge/attach_indicator_test.go b/internal/bridge/attach_indicator_test.goindex 78633f0f..9d7083e0 100644--- a/internal/bridge/attach_indicator_test.go+++ b/internal/bridge/attach_indicator_test.go@@ -107,10 +107,13 @@ func TestAttachIndicatorNamesPortPersistsAndClears(t *testing.T) {}func TestAttachIndicatorRejectsInvalidPort(t *testing.T) {- for _, port := range []string{"", "0", "65536", "not-a-port"} {+ for _, port := range []string{"", "0", "65536", "not-a-port", `9867\"; alert(1)`} {if _, err := attachIndicatorScript(port); err == nil {t.Fatalf("port %q accepted", port)}+ if _, err := clearAttachIndicatorScript(port); err == nil {+ t.Fatalf("cleanup port %q accepted", port)+ }}script, err := attachIndicatorScript(" 9867 ")if err != nil || !strings.Contains(script, `const port = 9867`) {