fix(mcp): encrypt headers/env on server update

UpdateServer type-asserted json.RawMessage but json.Decoder into
map[string]interface{} produces map[string]interface{} for nested
objects — so the assertion always failed and encryption was silently
skipped. Marshal any type to []byte before encrypting.
This commit is contained in:
viettranx committed 2026-03-07 15:13:54 +07:00
1 parent 0473b9a334
commit 5176716ba1
1 file changed
+12 -3
+12 -3
View File
@@ -160,11 +160,20 @@ func (s *PGMCPServerStore) UpdateServer(ctx context.Context, id uuid.UUID, updat
updates["api_key"] = encrypted
}
}
// Encrypt env/headers JSONB fields
// Encrypt env/headers JSONB fields.
// json.Decoder into map[string]interface{} produces map[string]interface{}
// for nested objects, not json.RawMessage — so we must marshal any type.
for _, field := range []string{"env", "headers"} {
if v, ok := updates[field]; ok {
if raw, isBytes := v.(json.RawMessage); isBytes {
updates[field] = json.RawMessage(s.encryptJSONB([]byte(raw)))
var raw []byte
switch val := v.(type) {
case json.RawMessage:
raw = []byte(val)
default:
raw, _ = json.Marshal(val)
}
if len(raw) > 0 {
updates[field] = json.RawMessage(s.encryptJSONB(raw))
}
}
}