mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-26 01:52:16 +08:00
Add env ALLOW_ANY_HOST to skip host check (#16351)
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -53,6 +54,12 @@ func AssertHostIsSafe(host string) (string, error) {
|
||||
if host == "" {
|
||||
return "", errors.New("Host must not be empty.")
|
||||
}
|
||||
if allowAnyHost() {
|
||||
zap.L().Warn("SSRF guard bypass enabled via ALLOW_ANY_HOST; allowing host without validation",
|
||||
zap.String("host", host),
|
||||
)
|
||||
return host, nil
|
||||
}
|
||||
|
||||
ips, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
@@ -95,6 +102,15 @@ func AssertHostIsSafe(host string) (string, error) {
|
||||
return resolvedIP, nil
|
||||
}
|
||||
|
||||
func allowAnyHost() bool {
|
||||
switch strings.ToLower(strings.TrimSpace(os.Getenv("ALLOW_ANY_HOST"))) {
|
||||
case "1", "true", "yes", "on":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isPublicAddr(addr netip.Addr) bool {
|
||||
addr = addr.Unmap()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user