fix(security): close six open GHSA findings from security triage

Harden share-link listing, password rotation, OIDC callback binding,
org invite search, knowledge batch mutations, and connector redirects.
This commit is contained in:
wizardchen
2026-07-02 14:49:27 +08:00
committed by lyingbug
parent fc64751f4e
commit f23c674bad
12 changed files with 400 additions and 34 deletions
+24
View File
@@ -754,6 +754,24 @@ func DefaultSSRFSafeHTTPClientConfig() SSRFSafeHTTPClientConfig {
// ErrSSRFRedirectBlocked is returned when a redirect target is blocked due to SSRF protection
var ErrSSRFRedirectBlocked = fmt.Errorf("redirect blocked: target URL failed SSRF validation")
// sameHTTPOrigin reports whether two URLs share scheme and host (port-aware).
func sameHTTPOrigin(a, b *url.URL) bool {
if a == nil || b == nil {
return false
}
return strings.EqualFold(a.Scheme, b.Scheme) && strings.EqualFold(a.Host, b.Host)
}
// stripRedirectSensitiveHeaders removes credentials that must not follow a
// cross-host redirect (Go only strips Authorization/Cookie by default).
func stripRedirectSensitiveHeaders(req *http.Request) {
req.Header.Del("Authorization")
req.Header.Del("Cookie")
req.Header.Del("X-Auth-Token")
req.Header.Del("X-Api-Key")
req.Header.Del("Api-Key")
}
// NewSSRFSafeHTTPClient creates an HTTP client that validates redirect targets against SSRF protections.
// This prevents SSRF attacks via HTTP redirects where an attacker's server redirects to internal services.
func NewSSRFSafeHTTPClient(config SSRFSafeHTTPClientConfig) *http.Client {
@@ -773,6 +791,12 @@ func NewSSRFSafeHTTPClient(config SSRFSafeHTTPClientConfig) *http.Client {
return fmt.Errorf("stopped after %d redirects", config.MaxRedirects)
}
// Strip credentials when the redirect crosses hosts so connector
// tokens (e.g. Yuque X-Auth-Token) cannot leak to a third party.
if len(via) > 0 && !sameHTTPOrigin(via[0].URL, req.URL) {
stripRedirectSensitiveHeaders(req)
}
// Validate the redirect target URL for SSRF (whitelist-aware).
// Even whitelisted hosts must use http/https to prevent scheme-based attacks.
redirectScheme := strings.ToLower(req.URL.Scheme)