fix(security): block SSRF via redirects in knowledge URL import
Use the SSRF-safe HTTP client for file_url downloads and add redirect-aware guards to the docreader Playwright path, closing GHSA-44fp, GHSA-rv6v, and GHSA-c7m6.
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
secutils "github.com/Tencent/WeKnora/internal/utils"
|
||||
)
|
||||
|
||||
// isValidFileType checks if a file type is supported
|
||||
@@ -336,7 +337,10 @@ func IsVideoType(fileType string) bool {
|
||||
// the function resolves the value from Content-Disposition / URL path and writes it back.
|
||||
// It does NOT perform SSRF validation — callers are responsible for that.
|
||||
func downloadFileFromURL(ctx context.Context, fileURL string, payloadFileName, payloadFileType *string) ([]byte, error) {
|
||||
httpClient := &http.Client{Timeout: 60 * time.Second}
|
||||
httpClient := secutils.NewSSRFSafeHTTPClient(secutils.SSRFSafeHTTPClientConfig{
|
||||
Timeout: 60 * time.Second,
|
||||
MaxRedirects: 10,
|
||||
})
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fileURL, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create request for file URL: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user