fix(security): redact IM list credentials and harden MinerU SSRF
Stop returning bot credentials from Viewer-accessible IM channel list endpoints and validate self-hosted MinerU URLs at config save and fetch time.
This commit is contained in:
@@ -131,13 +131,12 @@ func (h *IMHandler) ListIMChannels(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"data": channels})
|
||||
c.JSON(http.StatusOK, gin.H{"data": im.SummarizeIMChannels(channels)})
|
||||
}
|
||||
|
||||
// ListAllIMChannels lists every IM channel in the current tenant, across
|
||||
// agents, for the cross-agent overview page. Credentials are intentionally
|
||||
// NOT included in the response — callers that need credentials must use the
|
||||
// per-agent endpoint (GET /agents/:id/im-channels).
|
||||
// NOT included in the response.
|
||||
func (h *IMHandler) ListAllIMChannels(c *gin.Context) {
|
||||
tenantID, ok := c.Request.Context().Value(types.TenantIDContextKey).(uint64)
|
||||
if !ok {
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -1168,6 +1169,10 @@ func (h *TenantHandler) updateTenantParserEngineConfigInternal(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
merged := types.MergeParserEngineConfigForUpdate(&cfg, tenant.ParserEngineConfig)
|
||||
if err := validateParserEngineOutboundURLs(merged); err != nil {
|
||||
c.Error(errors.NewValidationError(err.Error()))
|
||||
return
|
||||
}
|
||||
tenant.ParserEngineConfig = merged
|
||||
updatedTenant, err := h.service.UpdateTenant(ctx, tenant)
|
||||
if err != nil {
|
||||
@@ -1465,3 +1470,20 @@ func (h *TenantHandler) updateTenantRetrievalConfigInternal(c *gin.Context) {
|
||||
"message": "Retrieval configuration updated successfully",
|
||||
})
|
||||
}
|
||||
|
||||
func validateParserEngineOutboundURLs(cfg *types.ParserEngineConfig) error {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
if endpoint := strings.TrimSpace(cfg.MinerUEndpoint); endpoint != "" {
|
||||
if err := secutils.ValidateURLForSSRF(endpoint); err != nil {
|
||||
return fmt.Errorf("mineru_endpoint failed SSRF validation: %v", err)
|
||||
}
|
||||
}
|
||||
if vlmURL := strings.TrimSpace(cfg.MinerUVLMServerURL); vlmURL != "" {
|
||||
if err := secutils.ValidateURLForSSRF(vlmURL); err != nil {
|
||||
return fmt.Errorf("mineru_vlm_server_url failed SSRF validation: %v", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestValidateParserEngineOutboundURLs_RejectsPrivateMinerUEndpoint(t *testing.T) {
|
||||
err := validateParserEngineOutboundURLs(&types.ParserEngineConfig{
|
||||
MinerUEndpoint: "http://127.0.0.1:8080",
|
||||
})
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "mineru_endpoint")
|
||||
}
|
||||
|
||||
func TestValidateParserEngineOutboundURLs_RejectsPrivateVLMServerURL(t *testing.T) {
|
||||
err := validateParserEngineOutboundURLs(&types.ParserEngineConfig{
|
||||
MinerUVLMServerURL: "http://169.254.169.254",
|
||||
})
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "mineru_vlm_server_url")
|
||||
}
|
||||
Reference in New Issue
Block a user