Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func (enc *Encoder) Encode(ec eventOrComment) error {
return fmt.Errorf("eventsource encode: %v", err)
}
default:
return fmt.Errorf("unexpected parameter to Encode: %v", ec)
// %T, not %v: an unexpected value must not have its contents -- which
// could include an event payload -- rendered into an error string that
// flows to WriteError consumers and logs.

@kinyoklion kinyoklion Aug 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// flows to WriteError consumers and logs.
// logs the type (%T) and not the content, which may contain sensitive data.

return fmt.Errorf("unexpected parameter to Encode: %T", ec)
}
if enc.compressed {
return enc.w.(*gzip.Writer).Flush()
Expand Down
10 changes: 10 additions & 0 deletions encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ func TestEncoderComment(t *testing.T) {
assert.Equal(t, ":hello\n", string(buf.Bytes()))
}

func TestEncoderRejectsUnknownTypeWithoutRenderingValue(t *testing.T) {
buf := bytes.NewBuffer(nil)
err := NewEncoder(buf, false).Encode("do-not-disclose")
assert.Error(t, err)
// The error names the type only: its contents could be a payload, and the
// error flows to WriteError consumers and logs.
assert.NotContains(t, err.Error(), "do-not-disclose")
assert.Contains(t, err.Error(), "string")
}

func TestEncoderGzipCompression(t *testing.T) {
uncompressedBuf, compressedBuf, expectedCompressedBuf := bytes.NewBuffer(nil), bytes.NewBuffer(nil), bytes.NewBuffer(nil)

Expand Down
4 changes: 3 additions & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ type Event interface {
Id() string
// The name of the event. Return empty string if not required.
Event() string
// The payload of the event.
// The payload of the event. Repeated calls must return the same value:
// the server may read it more than once, for example when accounting for
// payload sizes in addition to encoding.
Data() string
}

Expand Down
Loading
Loading