Skip to content

Commit 551ac54

Browse files
fix: batch G — security hardening (pipe spoof warning, jsonEscaped error, log sanitize)
1 parent ee4ba36 commit 551ac54

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

internal/client/browser.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ func isDebuggerError(err error) bool {
260260
// in JavaScript string literals (e.g., inside Runtime.evaluate expressions).
261261
// Unlike Go's %q, json.Marshal uses the same escaping rules as JavaScript.
262262
func jsonEscaped(s string) string {
263-
b, _ := json.Marshal(s)
263+
b, err := json.Marshal(s)
264+
if err != nil {
265+
return `""`
266+
}
264267
return string(b)
265268
}
266269

internal/client/client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ func Connect(pipeName string, logger *log.Logger) (*Client, error) {
5252
" 4. The extension has connected to Codex Desktop (open a Codex chat once to trigger initialization)")
5353
}
5454

55+
// The pipe prefix namespace is flat: any local process can create pipes with
56+
// the "codex-browser-use-" prefix. When multiple pipes exist, an attacker
57+
// could register a fake pipe before the legitimate Codex Desktop starts.
58+
if len(pipes) > 1 && logger != nil {
59+
logger.Printf("Warning: multiple codex-browser-use pipes found (%d). This may indicate stale or unauthorized pipes.", len(pipes))
60+
}
61+
5562
// Try each pipe until one connects AND passes health check
5663
var lastErr error
5764
for _, p := range pipes {

internal/protocol/protocol.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8+
"strings"
89
)
910

1011
// JSON-RPC 2.0 message types (Codex uses JSON-RPC without the "jsonrpc":"2.0" field on responses)
@@ -32,7 +33,9 @@ type ErrorObject struct {
3233
}
3334

3435
func (e *ErrorObject) Error() string {
35-
return fmt.Sprintf("json-rpc error %d: %s", e.Code, e.Message)
36+
msg := strings.ReplaceAll(e.Message, "\n", "\\n")
37+
msg = strings.ReplaceAll(msg, "\r", "\\r")
38+
return fmt.Sprintf("json-rpc error %d: %s", e.Code, msg)
3639
}
3740

3841
// SessionParams are injected into every request's params

0 commit comments

Comments
 (0)