mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-03 18:43:38 +01:00
Keep rejected agent URLs out of startup diagnostics (#3916)
Rejected primary and observer destinations could echo credentials, query values and malformed URL contents through configuration errors. Keep destination selection and correction hints without copying the URL or wrapping parser errors. Preserve existing transport admission and normalized successful destinations; cover rejection privacy and accepted/refused policy controls. Contract-Neutral: Redacts only agent configuration diagnostics for already-rejected URLs; successful normalization, transport/TLS policy, configuration format, wire responses and authority are unchanged. --- Fleet candidate `20261104T203501Z-core-runtime` from the `core-runtime` lane. Reviewed tip `95dd0fc927905cbc3c043393ef5d4eefcf1b12dc` on `main`. [How Pulse handles triage](https://github.com/rcourtman/Pulse/blob/main/docs/AI_TRANSPARENCY.md)
This commit is contained in:
@@ -18,6 +18,24 @@
|
||||
|
||||
## Purpose
|
||||
|
||||
### Agent destination validation keeps rejected URLs out of diagnostics
|
||||
|
||||
Agent primary/observer URL normalization still delegates admission to the shared
|
||||
transport validator, including the observer's separate plaintext opt-in. When
|
||||
it refuses a destination, startup/configuration errors give a static correction
|
||||
hint, never the rejected URL, its host/path, userinfo, query, fragment or nested
|
||||
parser error. The configuration wrapper retains the primary/observer index so
|
||||
an operator can select the right setting without copying credentials into logs.
|
||||
Successful URLs, TLS/plaintext policy, config files and wire data are unchanged.
|
||||
|
||||
`TestNormalizePulseURLDoesNotDiscloseRejectedInput`,
|
||||
`TestLoadObserversDoesNotDiscloseRejectedURL` and
|
||||
`TestNormalizePulseURLPreservesDestinationPolicy` exercise the actual normalizer
|
||||
and owner-private configuration loader with synthetic rejected credentials,
|
||||
malformed URLs and accepted HTTPS/loopback/explicit-HTTP controls. They run in
|
||||
the ordinary `internal/agenttarget` suite; this is source proof, not an installed
|
||||
agent result or a claim about past exposure.
|
||||
|
||||
### Requested metric history retains its admitted reader
|
||||
|
||||
The existing `/api/metrics-store/history` chart read and canonical agent
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
@@ -180,7 +181,7 @@ func NormalizePulseURL(raw string, authoritative bool, allowPlaintext bool) (str
|
||||
parsed, err := url.Parse(strings.TrimSpace(raw))
|
||||
if err == nil && parsed.Hostname() != "" && strings.EqualFold(parsed.Scheme, "http") &&
|
||||
!securityutil.IsLoopbackHost(parsed.Hostname()) {
|
||||
return "", fmt.Errorf("Pulse URL %q must use https unless the observer explicitly allows plaintext HTTP", raw)
|
||||
return "", errors.New("Pulse URL must use https unless the observer explicitly allows plaintext HTTP")
|
||||
}
|
||||
}
|
||||
parsed, err := securityutil.NormalizePulseHTTPBaseURLWithOptions(raw, securityutil.PulseURLValidationOptions{
|
||||
@@ -188,11 +189,54 @@ func NormalizePulseURL(raw string, authoritative bool, allowPlaintext bool) (str
|
||||
AllowOperatorPlaintextHTTP: allowPlaintext,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", pulseURLDiagnostic(raw, authoritative)
|
||||
}
|
||||
return strings.TrimRight(parsed.String(), "/"), nil
|
||||
}
|
||||
|
||||
// The shared normalizer's refusal remains authoritative. Its errors can
|
||||
// contain the entire rejected URL (including credentials and query values), so
|
||||
// agent startup/configuration diagnostics must not wrap or print those errors.
|
||||
// Classify a failure only to retain useful, content-free correction guidance.
|
||||
func pulseURLDiagnostic(raw string, authoritative bool) error {
|
||||
if strings.TrimSpace(raw) == "" {
|
||||
return errors.New("Pulse URL is required")
|
||||
}
|
||||
parsed, err := url.Parse(strings.TrimSpace(raw))
|
||||
if err != nil {
|
||||
return errors.New("Pulse URL is invalid; check the host, port and URL escaping")
|
||||
}
|
||||
if parsed.Scheme == "" {
|
||||
return errors.New("Pulse URL must include scheme (https:// or permitted http://)")
|
||||
}
|
||||
if parsed.Host == "" || parsed.Hostname() == "" {
|
||||
return errors.New("Pulse URL must include host")
|
||||
}
|
||||
if parsed.User != nil {
|
||||
return errors.New("Pulse URL must not include user credentials")
|
||||
}
|
||||
if parsed.RawQuery != "" || parsed.Fragment != "" {
|
||||
return errors.New("Pulse URL must not include query or fragment")
|
||||
}
|
||||
if port := parsed.Port(); port != "" {
|
||||
value, err := strconv.Atoi(port)
|
||||
if err != nil || value < 1 || value > 65535 {
|
||||
return errors.New("Pulse URL has invalid port: must be between 1 and 65535")
|
||||
}
|
||||
}
|
||||
switch strings.ToLower(parsed.Scheme) {
|
||||
case "http":
|
||||
if authoritative {
|
||||
return errors.New("Pulse URL must use https unless host is loopback or local/private")
|
||||
}
|
||||
return errors.New("Pulse URL must use https unless the observer explicitly allows plaintext HTTP")
|
||||
case "https":
|
||||
return errors.New("Pulse URL is invalid")
|
||||
default:
|
||||
return errors.New("Pulse URL has unsupported scheme; use https:// or permitted http://")
|
||||
}
|
||||
}
|
||||
|
||||
func validateName(name string) error {
|
||||
if name == "" {
|
||||
return errors.New("name is required")
|
||||
|
||||
126
internal/agenttarget/url_error_privacy_test.go
Normal file
126
internal/agenttarget/url_error_privacy_test.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package agenttarget
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// These are declared synthetic markers, not captured credentials or customer URLs.
|
||||
func TestNormalizePulseURLDoesNotDiscloseRejectedInput(t *testing.T) {
|
||||
for _, mode := range []struct {
|
||||
name string
|
||||
authoritative bool
|
||||
plaintext bool
|
||||
}{{"primary", true, false}, {"observer", false, false}, {"observer-explicit-http", false, true}} {
|
||||
t.Run(mode.name, func(t *testing.T) {
|
||||
for _, test := range []struct{ name, raw string }{
|
||||
{"userinfo", "https://synthetic-user:synthetic-password@pulse.invalid"},
|
||||
{"query", "https://pulse.invalid/?token=synthetic-query-secret"},
|
||||
{"fragment", "https://pulse.invalid/#synthetic-fragment-secret"},
|
||||
{"port", "https://pulse.invalid:synthetic-port-secret"},
|
||||
{"escape", "https://pulse.invalid/%synthetic-escape-secret"},
|
||||
{"missing-host", "https:///synthetic-path-secret"},
|
||||
{"scheme", "synthetic-scheme-secret://pulse.invalid/"},
|
||||
{"controls", "https://pulse.invalid/\nsynthetic-control-secret"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := NormalizePulseURL(test.raw, mode.authoritative, mode.plaintext)
|
||||
if err == nil || got != "" {
|
||||
t.Fatal("invalid destination was admitted")
|
||||
}
|
||||
if strings.Contains(err.Error(), "synthetic-") || strings.Contains(err.Error(), "pulse.invalid") {
|
||||
t.Fatal("validation diagnostic disclosed the rejected URL")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(err.Error()), "url") {
|
||||
t.Fatal("validation diagnostic lost its actionable URL context")
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
// This observer-only policy check runs before the shared normalizer, so
|
||||
// it must not reflect even a malformed/userinfo/query-bearing HTTP URL.
|
||||
for _, raw := range []string{
|
||||
"http://203.0.113.10/synthetic-path-secret",
|
||||
"http://synthetic-user:synthetic-password@203.0.113.10/?token=synthetic-query-secret",
|
||||
} {
|
||||
if _, err := NormalizePulseURL(raw, false, false); err == nil || strings.Contains(err.Error(), "synthetic-") || strings.Contains(err.Error(), "203.0.113.10") || !strings.Contains(strings.ToLower(err.Error()), "https") {
|
||||
t.Fatal("observer plaintext refusal disclosed its input or lost HTTPS guidance")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadObserversDoesNotDiscloseRejectedURL(t *testing.T) {
|
||||
for _, primary := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "observer", true: "primary"}[primary], func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
configPath := filepath.Join(dir, "observers.json")
|
||||
tokenPath := filepath.Join(dir, "observer.token")
|
||||
writePrivateFile(t, tokenPath, "synthetic-file-token")
|
||||
primaryURL, observerURL := "https://primary.invalid", "https://observer.invalid"
|
||||
bad := "https://synthetic-user:synthetic-password@private-fixture.invalid/?token=synthetic-query-secret"
|
||||
if primary {
|
||||
primaryURL = bad
|
||||
} else {
|
||||
observerURL = bad
|
||||
}
|
||||
data, err := json.Marshal(map[string]any{"version": 1, "observers": []map[string]any{{"name": "report-only", "url": observerURL, "tokenFile": tokenPath}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writePrivateFile(t, configPath, string(data))
|
||||
observers, err := LoadObservers(configPath, primaryURL)
|
||||
if err == nil || len(observers) != 0 {
|
||||
t.Fatal("invalid configuration produced an observer")
|
||||
}
|
||||
for _, marker := range []string{"synthetic-", "private-fixture.invalid", tokenPath} {
|
||||
if strings.Contains(err.Error(), marker) {
|
||||
t.Fatal("configuration error disclosed a rejected URL or credential")
|
||||
}
|
||||
}
|
||||
if primary && !strings.Contains(err.Error(), "primary Pulse URL") || !primary && !strings.Contains(err.Error(), "observer 1") {
|
||||
t.Fatal("configuration error lost destination selection guidance")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizePulseURLPreservesDestinationPolicy(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name, raw, want string
|
||||
authoritative bool
|
||||
plaintext bool
|
||||
wantError string
|
||||
}{
|
||||
{"primary-https", " HTTPS://Pulse.Invalid:7655/base/ ", "https://pulse.invalid:7655/base", true, false, ""},
|
||||
{"observer-https", " HTTPS://Pulse.Invalid:7655/base/ ", "https://pulse.invalid:7655/base", false, false, ""},
|
||||
{"observer-loopback", "http://127.0.0.1:7655/", "http://127.0.0.1:7655", false, false, ""},
|
||||
{"primary-private-http", "http://192.168.50.10:7655/", "http://192.168.50.10:7655", true, false, ""},
|
||||
{"observer-private-http", "http://192.168.50.10:7655/", "", false, false, "explicitly allows plaintext HTTP"},
|
||||
{"observer-explicit-http", "http://203.0.113.10:7655/", "http://203.0.113.10:7655", false, true, ""},
|
||||
{"primary-public-http", "http://203.0.113.10:7655/", "", true, false, "must use https"},
|
||||
{"primary-explicit-http", "http://203.0.113.10:7655/", "http://203.0.113.10:7655", true, true, ""},
|
||||
{"empty", " ", "", true, false, "is required"},
|
||||
{"scheme-missing", "pulse.invalid/base", "", true, false, "must include scheme"},
|
||||
{"host-missing", "https:///base", "", true, false, "must include host"},
|
||||
{"port-low", "https://pulse.invalid:0", "", true, false, "invalid port"},
|
||||
{"port-high", "https://pulse.invalid:65536", "", true, false, "invalid port"},
|
||||
{"scheme-unsupported", "ftp://pulse.invalid", "", true, false, "unsupported scheme"},
|
||||
{"userinfo", "https://user:password@pulse.invalid", "", true, false, "must not include user credentials"},
|
||||
{"query", "https://pulse.invalid/?token=value", "", true, false, "must not include query or fragment"},
|
||||
{"fragment", "https://pulse.invalid/#value", "", true, false, "must not include query or fragment"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := NormalizePulseURL(test.raw, test.authoritative, test.plaintext)
|
||||
if test.wantError == "" {
|
||||
if err != nil || got != test.want {
|
||||
t.Fatalf("normalization = %q, %v; want %q", got, err, test.want)
|
||||
}
|
||||
} else if err == nil || got != "" || !strings.Contains(err.Error(), test.wantError) {
|
||||
t.Fatalf("refusal = %q, %v; want %q", got, err, test.wantError)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user