Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

test: the platform/matrix vocabulary census hardcodes the platform side, so a fourth platform drifts silently and the refusal names the internal key (PIN-156)

Luigi Agostie166f67b351b
diff --git a/internal/handlers/stealth.go b/internal/handlers/stealth.go
index af72e191..efd22c20 100644
--- a/internal/handlers/stealth.go
+++ b/internal/handlers/stealth.go
@@ -306,6 +306,18 @@ func resolveRandomFingerprintOS(matrix map[string]map[string]fingerprint, browse
return picked, true
}
+// fingerprintOSSubject names the os a refusal is about the way the caller can act on
+// it: the spelling they sent, or — when they named none and the host's own key was
+// used — that key, said as the host's. Reporting the resolved key to a caller who
+// sent "macOS" hands back a word they have never seen, and reporting an empty string
+// to a caller who named nothing hands back no word at all.
+func fingerprintOSSubject(requested, resolved string) string {
+ if trimmed := strings.TrimSpace(requested); trimmed != "" {
+ return fmt.Sprintf("os %q", trimmed)
+ }
+ return fmt.Sprintf("the host os %q", resolved)
+}
+
// generateFingerprint refuses an os/browser pair the matrix does not hold instead
// of returning the zero identity. An empty userAgent delivered as a success is
// worse than a refusal: the endpoint exists to hand back an identity to apply, and
@@ -354,8 +366,8 @@ func (h *Handlers) generateFingerprint(req fingerprintRequest) (fingerprint, err
// request was honoured.
browserConfig, ok := osConfigs[os][browser]
if !ok {
- return fingerprint{}, fmt.Errorf("no fingerprint for os %q with browser %q; available pairs: %s",
- os, browser, strings.Join(availableFingerprintPairs(osConfigs), ", "))
+ return fingerprint{}, fmt.Errorf("no fingerprint for %s with browser %q; available pairs: %s",
+ fingerprintOSSubject(req.OS, os), browser, strings.Join(availableFingerprintPairs(osConfigs), ", "))
}
fp.UserAgent = browserConfig.UserAgent
fp.Platform = browserConfig.Platform
diff --git a/internal/handlers/stealth_test.go b/internal/handlers/stealth_test.go
index d5658bc9..9dbb5b86 100644
--- a/internal/handlers/stealth_test.go
+++ b/internal/handlers/stealth_test.go
@@ -929,6 +929,37 @@ func TestAnUnknownOSStillRefusesRatherThanFallingBackToTheHost(t *testing.T) {
}
}
+// The refusal is only actionable if it names the os in the words the caller used.
+// Resolving translates the spelling before the pair lookup, so a miss reported after
+// the translation quotes an internal key the caller never sent — and a caller who
+// named no os at all would be quoted an empty string.
+func TestTheRefusalNamesTheOSTheCallerSent(t *testing.T) {
+ h := Handlers{Config: &config.RuntimeConfig{BrowserVersion: "144.0.7559.133"}}
+
+ for _, spelling := range []string{stealth.PlatformMacOS, stealth.FingerprintOSMac} {
+ t.Run(spelling, func(t *testing.T) {
+ _, err := h.generateFingerprint(fingerprintRequest{OS: spelling, Browser: "edge"})
+ if err == nil {
+ t.Fatalf("os=%q browser=edge was accepted", spelling)
+ }
+ if !strings.Contains(err.Error(), `os "`+spelling+`"`) {
+ t.Errorf("error %q does not name the os the caller sent (%q)", err, spelling)
+ }
+ })
+ }
+
+ _, err := h.generateFingerprint(fingerprintRequest{Browser: "firefox"})
+ if err == nil {
+ t.Fatal("browser=firefox was accepted with no os")
+ }
+ if strings.Contains(err.Error(), `os ""`) {
+ t.Errorf("error %q quotes an empty os to a caller who named none", err)
+ }
+ if !strings.Contains(err.Error(), `the host os "`+stealth.HostFingerprintOS()+`"`) {
+ t.Errorf("error %q does not say the host os was used, nor name it", err)
+ }
+}
+
// The two vocabularies must stay in step: every platform internal/stealth knows maps
// to a key the matrix holds, and every os key the matrix holds is one internal/stealth
// owns. Derived from both sides, so adding a row to either without the other reds.
@@ -936,8 +967,13 @@ func TestThePlatformAndMatrixVocabulariesAgree(t *testing.T) {
h := Handlers{Config: &config.RuntimeConfig{BrowserVersion: "144.0.7559.133"}}
matrix := h.fingerprintMatrix()
+ platforms := stealth.FingerprintPlatforms()
+ if len(platforms) < len(matrix) {
+ t.Fatalf("FingerprintPlatforms() returned %d platforms for a matrix of %d rows; the census cannot cover the vocabulary", len(platforms), len(matrix))
+ }
+
owned := map[string]bool{}
- for _, platform := range []string{stealth.PlatformWindows, stealth.PlatformMacOS, stealth.PlatformLinux} {
+ for _, platform := range platforms {
key, ok := stealth.FingerprintOSKey(platform)
if !ok {
t.Fatalf("internal/stealth knows platform %q but maps it to no fingerprint os key", platform)
diff --git a/internal/stealth/ua.go b/internal/stealth/ua.go
index c6df60d8..aa2beb97 100644
--- a/internal/stealth/ua.go
+++ b/internal/stealth/ua.go
@@ -2,6 +2,7 @@ package stealth
import (
goruntime "runtime"
+ "sort"
"strings"
"sync"
@@ -121,6 +122,18 @@ func FingerprintOSKey(platform string) (string, bool) {
return key, ok
}
+// FingerprintPlatforms is every persona platform the endpoint's os keys are derived
+// from, sorted. A census over the vocabulary reads this rather than restating the
+// platforms, so a row added to fingerprintOSKeys is visited without an edit.
+func FingerprintPlatforms() []string {
+ platforms := make([]string, 0, len(fingerprintOSKeys))
+ for platform := range fingerprintOSKeys {
+ platforms = append(platforms, platform)
+ }
+ sort.Strings(platforms)
+ return platforms
+}
+
// HostFingerprintOS is the endpoint's os key for the machine this process runs on,
// which is what a fingerprint request naming no os means: the caller delegated the
// choice, and the honest answer is this host. A Linux host does advertise a rarer