notification: keep chunk cipher keys out of webhook payloads (#13014)

* filer_pb: scrub cipher keys from both entries of an event

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* notification: keep chunk cipher keys out of webhook payloads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-11-26 08:21:09 -08:00
1 parent 50fd5c0185
commit d2ae75516c
4 files changed
+94 -3

No files matched your search

+1 -1
View File
@@ -50,7 +50,7 @@ func newWebhookMessage(key string, message proto.Message) *webhookMessage {
return &webhookMessage{
Key: key,
EventType: eventType,
Notification: notification,
Notification: filer_pb.ScrubEventCipherKeys(notification),
}
}
@@ -1,6 +1,8 @@
package webhook
import (
"encoding/base64"
"io"
"net/http"
"net/http/httptest"
"strings"
@@ -413,6 +415,50 @@ func TestQueueNoDuplicateWebhooks(t *testing.T) {
}
}
func TestQueueSendsNoCipherKeys(t *testing.T) {
bodies := make(chan string, 1)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
bodies <- string(body)
w.WriteHeader(http.StatusOK)
}))
defer server.Close()
q := newQueueForTest(t, &config{
endpoint: server.URL,
timeoutSeconds: 5,
backoffSeconds: 1,
maxBackoffSeconds: 1,
nWorkers: 1,
bufferSize: 10,
})
defer closeQueueForTest(q)
key := []byte("0123456789abcdef0123456789abcdef")
msg := &filer_pb.EventNotification{
OldEntry: &filer_pb.Entry{Name: "f", Chunks: []*filer_pb.FileChunk{{FileId: "1,aa", CipherKey: key}}},
NewEntry: &filer_pb.Entry{Name: "f", Chunks: []*filer_pb.FileChunk{{FileId: "2,bb", CipherKey: key}}},
}
if err := q.SendMessage("/dir/f", msg); err != nil {
t.Fatalf("SendMessage() error = %v", err)
}
select {
case body := <-bodies:
if !strings.Contains(body, "1,aa") || !strings.Contains(body, "2,bb") {
t.Fatalf("webhook body lacks the chunks: %s", body)
}
if strings.Contains(body, "cipher_key") || strings.Contains(body, base64.StdEncoding.EncodeToString(key)) {
t.Fatalf("webhook body carries a cipher key: %s", body)
}
case <-time.After(5 * time.Second):
t.Fatal("webhook was not delivered")
}
if len(msg.OldEntry.Chunks[0].CipherKey) == 0 || len(msg.NewEntry.Chunks[0].CipherKey) == 0 {
t.Fatal("sending mutated the caller's event")
}
}
func TestQueueSendMessageWithFilter(t *testing.T) {
tests := []struct {
name string
+17 -2
View File
@@ -9,10 +9,25 @@ func ScrubCipherKeys(entry *Entry) *Entry {
return nil
}
clone := proto.Clone(entry).(*Entry)
for _, chunk := range clone.Chunks {
clearCipherKeys(clone)
return clone
}
// ScrubEventCipherKeys is ScrubCipherKeys for both entries of an event.
func ScrubEventCipherKeys(event *EventNotification) *EventNotification {
if event == nil {
return nil
}
clone := proto.Clone(event).(*EventNotification)
clearCipherKeys(clone.OldEntry)
clearCipherKeys(clone.NewEntry)
return clone
}
func clearCipherKeys(entry *Entry) {
for _, chunk := range entry.GetChunks() {
if chunk != nil {
chunk.CipherKey = nil
}
}
return clone
}
+30
View File
@@ -32,3 +32,33 @@ func TestScrubCipherKeys(t *testing.T) {
t.Fatal("nil entry should scrub to nil")
}
}
func TestScrubEventCipherKeys(t *testing.T) {
key := []byte("0123456789abcdef0123456789abcdef")
event := &EventNotification{
OldEntry: &Entry{Name: "a", Chunks: []*FileChunk{{FileId: "1,aaa", CipherKey: key}}},
NewEntry: &Entry{Name: "b", Chunks: []*FileChunk{{FileId: "2,bbb", CipherKey: key}}},
NewParentPath: "/dir",
Signatures: []int32{7},
}
scrubbed := ScrubEventCipherKeys(event)
for _, entry := range []*Entry{scrubbed.OldEntry, scrubbed.NewEntry} {
if len(entry.Chunks[0].CipherKey) != 0 {
t.Fatalf("%s still carries a cipher key", entry.Name)
}
}
if scrubbed.NewParentPath != "/dir" || len(scrubbed.Signatures) != 1 || scrubbed.NewEntry.Chunks[0].FileId != "2,bbb" {
t.Fatalf("scrubbing dropped event fields: %v", scrubbed)
}
if len(event.OldEntry.Chunks[0].CipherKey) != len(key) || len(event.NewEntry.Chunks[0].CipherKey) != len(key) {
t.Fatal("scrubbing mutated the original event")
}
if ScrubEventCipherKeys(nil) != nil {
t.Fatal("nil event should scrub to nil")
}
if got := ScrubEventCipherKeys(&EventNotification{}); got.OldEntry != nil || got.NewEntry != nil {
t.Fatal("event without entries gained entries")
}
}