mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-14 18:18:37 +00:00
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:
1 parent
0473b9a334
commit
5176716ba1
1 file changed
+12
-3
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user