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
+8 -3
View File
@@ -1,6 +1,7 @@
package dto
import (
"context"
"time"
"github.com/Tencent/WeKnora/internal/types"
@@ -53,7 +54,7 @@ type ModelParametersDTO struct {
//
// Builtin models are shared across tenants — strip BaseURL (which can leak
// the tenant's private endpoint) and any non-shared parameters.
func NewModelResponse(m *types.Model) *ModelResponse {
func NewModelResponse(ctx context.Context, m *types.Model) *ModelResponse {
if m == nil {
return nil
}
@@ -68,6 +69,10 @@ func NewModelResponse(m *types.Model) *ModelResponse {
SupportsVision: m.Parameters.SupportsVision,
AppID: m.Parameters.AppID,
}
if !CanViewIntegrationSecrets(ctx) {
params.ExtraConfig = nil
params.CustomHeaders = nil
}
if m.IsBuiltin {
// Builtin: strip everything that could reveal per-tenant config.
// EmbeddingParameters and ParameterSize / Provider / InterfaceType /
@@ -104,10 +109,10 @@ func NewModelResponse(m *types.Model) *ModelResponse {
}
// NewModelResponses is the slice convenience wrapper.
func NewModelResponses(models []*types.Model) []*ModelResponse {
func NewModelResponses(ctx context.Context, models []*types.Model) []*ModelResponse {
out := make([]*ModelResponse, 0, len(models))
for _, m := range models {
out = append(out, NewModelResponse(m))
out = append(out, NewModelResponse(ctx, m))
}
return out
}