fix: per-caller context on account lookup, stop on non-websocket receive, sanitize CLI output

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vincent BourdonandClaude Opus 5.5 committed 2026-11-20 15:51:38 +01:00
1 parent 45f88378a6
commit 136e431917
8 files changed
+89 -7

No files matched your search

+13 -1
View File
@@ -23,6 +23,7 @@ import (
"strings"
"text/tabwriter"
"time"
"unicode"
"git.siteop.biz/vincentb99/signalbot"
"github.com/mdp/qrterminal/v3"
@@ -213,10 +214,21 @@ func listen(ctx context.Context, c *signalbot.Client, stdout io.Writer) error {
if where == "" {
where = "direct"
}
fmt.Fprintf(stdout, "[%s] %s (%s): %s\n", m.Timestamp.Format("2006-01-02 15:04:05"), m.From, where, m.Text)
fmt.Fprintf(stdout, "[%s] %s (%s): %s\n", m.Timestamp.Format("2006-01-02 15:04:05"), sanitize(m.From), where, sanitize(m.Text))
})
if errors.Is(err, context.Canceled) {
return nil
}
return err
}
// sanitize replaces control characters (except newline and tab) so that
// message text from strangers cannot inject terminal escape sequences.
func sanitize(s string) string {
return strings.Map(func(r rune) rune {
if r == '\n' || r == '\t' || !unicode.IsControl(r) {
return r
}
return '?'
}, s)
}
+10
View File
@@ -166,3 +166,13 @@ func TestRunListen(t *testing.T) {
t.Fatalf("code %d, stderr %q", code, errOut.String())
}
}
func TestSanitizeStripsControlChars(t *testing.T) {
got := sanitize("hi\x1b]0;pwned\x07 there\x1b[2J\nline2\tx")
if strings.ContainsAny(got, "\x1b\x07") {
t.Fatalf("control chars left: %q", got)
}
if !strings.Contains(got, "\nline2\tx") || !strings.HasPrefix(got, "hi") {
t.Fatalf("legit text altered: %q", got)
}
}