feat: add SSRF protection for URL fetching

This commit is contained in:
wizardchen
2026-01-21 14:48:43 +08:00
committed by lyingbug
parent e55cbaa057
commit 2a99e2458d
3 changed files with 268 additions and 0 deletions
@@ -381,6 +381,12 @@ func (s *knowledgeService) CreateKnowledgeFromURL(ctx context.Context,
return nil, ErrInvalidURL
}
// SSRF protection: validate URL is safe to fetch
if safe, reason := secutils.IsSSRFSafeURL(url); !safe {
logger.Errorf(ctx, "URL rejected for SSRF protection: %s, reason: %s", url, reason)
return nil, ErrInvalidURL
}
// Check if URL already exists in the knowledge base
tenantID := ctx.Value(types.TenantIDContextKey).(uint64)
logger.Infof(ctx, "Checking if URL exists, tenant ID: %d", tenantID)