fix(security): redact integration secrets from viewer-accessible endpoints

Prevent low-privileged tenant members from reading raw API keys and
infrastructure credentials via tenant profile, KV config, model/MCP/web
search listings, and KB initialization config responses.
This commit is contained in:
wizardchen
2026-07-02 12:31:57 +08:00
committed by lyingbug
parent 8325dac738
commit 0b73080bb8
18 changed files with 649 additions and 61 deletions
@@ -19,7 +19,7 @@ func TestWebSearchProviderResponse_OmitsSecrets(t *testing.T) {
BaseURL: "https://example.com",
},
}
body, err := json.Marshal(NewWebSearchProviderResponse(e))
body, err := json.Marshal(NewWebSearchProviderResponse(adminContext(), e))
assert.NoError(t, err)
s := string(body)
assert.NotContains(t, s, "bing-secret-do-not-leak")
@@ -35,7 +35,20 @@ func TestWebSearchProviderResponse_OmitsSecrets(t *testing.T) {
assert.Contains(t, s, "example.com")
}
func TestWebSearchProviderResponse_NilSafe(t *testing.T) {
assert.Nil(t, NewWebSearchProviderResponse(nil))
assert.Equal(t, []*WebSearchProviderResponse{}, NewWebSearchProviderResponses(nil))
func TestWebSearchProviderResponse_ViewerStripsIntegrationDetail(t *testing.T) {
e := &types.WebSearchProviderEntity{
ID: "wsp-2",
Parameters: types.WebSearchProviderParameters{
ProxyURL: "http://proxy:8080",
ExtraConfig: map[string]string{"token": "secret"},
},
}
resp := NewWebSearchProviderResponse(viewerContext(), e)
assert.Empty(t, resp.Parameters.ProxyURL)
assert.Nil(t, resp.Parameters.ExtraConfig)
}
func TestWebSearchProviderResponse_NilSafe(t *testing.T) {
assert.Nil(t, NewWebSearchProviderResponse(adminContext(), nil))
assert.Equal(t, []*WebSearchProviderResponse{}, NewWebSearchProviderResponses(adminContext(), nil))
}