Files
knowledge-governance/internal/governance/http_origin.go
T
姚章浩 1db21fb899 feat(settings): 服务配置四项化并保存时真校验
- 生产/测试 WeKnora 地址、租户 ID、知识库 ID 由静态 env 收敛为版本化 UI 设置,保留修订号与操作人审计
- 新增 serviceverify:保存前真调目标端点探测,端点无效才拒绝;网络抖动或无凭据仅告警
- 迁移 000042(生产 WeKnora 端点)/000043(服务目标);补齐设置候选与校验契约用例
2026-09-30 10:54:07 +08:00

24 lines
832 B
Go

package governance
import (
"net/url"
"strings"
)
// ValidHTTPOrigin reports whether value is a bare http(s) origin: scheme, host
// and an optional path, with no credentials, query string or fragment. It is
// the single rule for every operator-supplied endpoint — the env-configured
// probe address and the web-configured one — so an endpoint can never smuggle
// a secret (https://user:pass@host, ?token=...) or an injection payload.
func ValidHTTPOrigin(value string) bool {
trimmed := strings.TrimSpace(value)
if trimmed == "" || trimmed != value || len(trimmed) > 300 {
return false
}
parsed, err := url.Parse(trimmed)
if err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") || parsed.Host == "" {
return false
}
return parsed.User == nil && parsed.RawQuery == "" && parsed.Fragment == ""
}