7d91343e5f
build / build (push) Successful in 1m45s
在既有 kbbinding(迁移 000081)上补齐任务要求,不另建表、不另起路由: - 测试连接区分 401/403(密钥无效 / 无权限)与不可达、成功四态; - 视图回显密钥尾 4 位(服务端不存、不回读明文); - key_action=clear 作为独立动作,清除后解析失败关闭、不回落文件旧 Key; - 内外库留空 = 取消绑定,回报回退来源(测试侧部署默认库 / 生产侧同 ID 语义); - 生产绑定回报在飞执行的冻结/仍可改指向条数,已冻结目标不被改写; - 新增 WEKNORA_ALLOW_PRIVATE_HTTP:客户端/探活/连接页共用 HTTPAllowed, 只放行 RFC1918/回环/链路本地 http,生产 18093 同网段反代因此可用。
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// secretTransportAllowed is the single rule for typing a secret into the
|
|
// console: a real TLS connection, a loopback request, or a same-origin HTTPS
|
|
// request that a trusted reverse proxy forwarded. The browser's origin scheme
|
|
// must agree, so a plain-HTTP page behind a misconfigured proxy cannot submit
|
|
// a key even if it spoofs X-Forwarded-Proto.
|
|
func secretTransportAllowed(r *http.Request, trustTLSProxy bool) bool {
|
|
if r.TLS != nil {
|
|
return true
|
|
}
|
|
host := r.Host
|
|
if parsedHost, _, err := net.SplitHostPort(host); err == nil {
|
|
host = parsedHost
|
|
}
|
|
if strings.EqualFold(host, "localhost") {
|
|
return true
|
|
}
|
|
if ip := net.ParseIP(host); ip != nil && ip.IsLoopback() {
|
|
return true
|
|
}
|
|
if trustTLSProxy && r.Header.Get("X-Forwarded-Proto") == "https" && r.Header.Get("Sec-Fetch-Site") == "same-origin" {
|
|
origin, err := url.Parse(r.Header.Get("Origin"))
|
|
return err == nil && origin.Scheme == "https"
|
|
}
|
|
return false
|
|
}
|
|
|
|
// secretTransportAllowedForPrivateConsole additionally accepts a same-origin
|
|
// fetch from the operator console itself when it is served over plain http on a
|
|
// private address. That is the only non-TLS shape this deployment needs, and it
|
|
// still requires an exact Origin/Host match.
|
|
func secretTransportAllowedForPrivateConsole(r *http.Request, trustTLSProxy, allowPrivateHTTP bool) bool {
|
|
if secretTransportAllowed(r, trustTLSProxy) {
|
|
return true
|
|
}
|
|
if !allowPrivateHTTP || r.Header.Get("Sec-Fetch-Site") != "same-origin" {
|
|
return false
|
|
}
|
|
origin := strings.TrimSpace(r.Header.Get("Origin"))
|
|
if origin == "" {
|
|
return false
|
|
}
|
|
parsed, err := url.Parse(origin)
|
|
if err != nil || parsed.Host == "" || !strings.EqualFold(parsed.Host, r.Host) {
|
|
return false
|
|
}
|
|
host := parsed.Hostname()
|
|
if ip := net.ParseIP(host); ip != nil {
|
|
return ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()
|
|
}
|
|
return strings.EqualFold(host, "localhost")
|
|
}
|