fix(security): harden secret redaction follow-ups for PR #1884
Restore PreserveIfRedacted merge on tenant KV PUT so Admin settings saves no longer overwrite stored secrets with placeholder values. Redact cross- tenant tenant listings, tighten Viewer MCP/model responses, and align init config frontend types with credentials metadata.
This commit is contained in:
@@ -93,6 +93,9 @@ func NewMCPServiceResponse(ctx context.Context, svc *types.MCPService) *MCPServi
|
||||
if !includeDetail {
|
||||
resp.Headers = nil
|
||||
resp.EnvVars = nil
|
||||
resp.URL = nil
|
||||
resp.StdioConfig = nil
|
||||
resp.AdvancedConfig = nil
|
||||
}
|
||||
if svc.AuthConfig != nil {
|
||||
auth := &MCPAuthConfigResponse{
|
||||
|
||||
@@ -74,17 +74,27 @@ func TestMCPServiceResponse_BuiltinStripsTenantConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMCPServiceResponse_ViewerStripsIntegrationDetail(t *testing.T) {
|
||||
url := "https://tenant-private.example.com"
|
||||
svc := &types.MCPService{
|
||||
ID: "svc-2",
|
||||
URL: &url,
|
||||
Headers: types.MCPHeaders{"Authorization": "Bearer secret"},
|
||||
EnvVars: types.MCPEnvVars{"TOKEN": "secret"},
|
||||
StdioConfig: &types.MCPStdioConfig{
|
||||
Command: "npx",
|
||||
Args: []string{"-y", "mcp-server"},
|
||||
},
|
||||
AdvancedConfig: &types.MCPAdvancedConfig{},
|
||||
AuthConfig: &types.MCPAuthConfig{
|
||||
CustomHeaders: map[string]string{"X-Auth": "secret"},
|
||||
},
|
||||
}
|
||||
resp := NewMCPServiceResponse(viewerContext(), svc)
|
||||
assert.Nil(t, resp.URL)
|
||||
assert.Nil(t, resp.Headers)
|
||||
assert.Nil(t, resp.EnvVars)
|
||||
assert.Nil(t, resp.StdioConfig)
|
||||
assert.Nil(t, resp.AdvancedConfig)
|
||||
assert.NotNil(t, resp.AuthConfig)
|
||||
assert.Nil(t, resp.AuthConfig.CustomHeaders)
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ func NewModelResponse(ctx context.Context, m *types.Model) *ModelResponse {
|
||||
if !CanViewIntegrationSecrets(ctx) {
|
||||
params.ExtraConfig = nil
|
||||
params.CustomHeaders = nil
|
||||
params.BaseURL = ""
|
||||
}
|
||||
if m.IsBuiltin {
|
||||
// Builtin: strip everything that could reveal per-tenant config.
|
||||
|
||||
@@ -74,11 +74,13 @@ func TestModelResponse_ViewerStripsIntegrationDetail(t *testing.T) {
|
||||
m := &types.Model{
|
||||
ID: "m-2",
|
||||
Parameters: types.ModelParameters{
|
||||
BaseURL: "https://tenant-private.example.com",
|
||||
CustomHeaders: map[string]string{"Authorization": "Bearer secret"},
|
||||
ExtraConfig: map[string]string{"region": "cn-hangzhou"},
|
||||
ExtraConfig: map[string]string{"region": "cn-hangzhou"},
|
||||
},
|
||||
}
|
||||
resp := NewModelResponse(viewerContext(), m)
|
||||
assert.Empty(t, resp.Parameters.BaseURL)
|
||||
assert.Nil(t, resp.Parameters.CustomHeaders)
|
||||
assert.Nil(t, resp.Parameters.ExtraConfig)
|
||||
}
|
||||
|
||||
@@ -83,3 +83,14 @@ func NewTenantResponses(ctx context.Context, tenants []*types.Tenant) []*TenantR
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// NewTenantResponsesCrossTenant redacts every tenant as Viewer regardless of
|
||||
// the caller's active-tenant role. Used by cross-tenant list/search endpoints
|
||||
// where the caller's home-tenant role must not unlock other tenants' secrets.
|
||||
func NewTenantResponsesCrossTenant(tenants []*types.Tenant) []*TenantResponse {
|
||||
out := make([]*TenantResponse, 0, len(tenants))
|
||||
for _, t := range tenants {
|
||||
out = append(out, NewTenantResponseWithRole(t, types.TenantRoleViewer))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -47,6 +47,15 @@ func TestTenantResponse_AdminGetsRedactedIntegrationConfigs(t *testing.T) {
|
||||
assert.Equal(t, types.RedactedSecretPlaceholder, resp.StorageEngineConfig.MinIO.SecretAccessKey)
|
||||
}
|
||||
|
||||
func TestTenantResponsesCrossTenant_RedactsEvenForOwnerContext(t *testing.T) {
|
||||
tenant := sampleSecretTenant()
|
||||
body, err := json.Marshal(NewTenantResponsesCrossTenant([]*types.Tenant{tenant}))
|
||||
require.NoError(t, err)
|
||||
s := string(body)
|
||||
assert.NotContains(t, s, "tenant-api-key-123")
|
||||
assert.NotContains(t, s, "parser-secret-123")
|
||||
}
|
||||
|
||||
func sampleSecretTenant() *types.Tenant {
|
||||
return &types.Tenant{
|
||||
ID: 42,
|
||||
|
||||
Reference in New Issue
Block a user