Skip to content

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

fix: a rotated Windows or Linux persona reports architecture arm on an ARM host, contradicting its own Win64/x86_64 user agent (PIN-199)

Luigi Agosti351fc62f5d88
diff --git a/internal/cli/apiclient/apierror_idpi_test.go b/internal/cli/apiclient/apierror_idpi_test.go
index d3427bac..6095d6f1 100644
--- a/internal/cli/apiclient/apierror_idpi_test.go
+++ b/internal/cli/apiclient/apierror_idpi_test.go
@@ -80,3 +80,8 @@ func (b *driftedTabBridge) GetTabPolicyState(string) (bridge.TabPolicyState, boo
}
func (b *driftedTabBridge) SetTabPolicyState(string, bridge.TabPolicyState) {}
+
+// The read prelude asks every tab whether a JavaScript dialog is blocking it before
+// it touches the page. The embedded BridgeAPI is nil, so the promoted method would
+// panic rather than answer; this tab has no dialog.
+func (b *driftedTabBridge) GetDialogManager() *bridge.DialogManager { return nil }
diff --git a/internal/stealth/ua.go b/internal/stealth/ua.go
index cb337529..62c3f283 100644
--- a/internal/stealth/ua.go
+++ b/internal/stealth/ua.go
@@ -261,13 +261,7 @@ func BuildPersona(userAgent, chromeVersion string) BrowserPersona {
}
platformVersion := PlatformVersionFor(uaDataPlatform)
- architecture := "x86"
- switch {
- case strings.Contains(ua, "arm64"), strings.Contains(ua, "aarch64"), strings.Contains(ua, "ARM"):
- architecture = "arm"
- case goruntime.GOARCH == "arm64":
- architecture = "arm"
- }
+ architecture := architectureFor(ua, uaDataPlatform)
brands := brandList(ua, major, greaseMajorVersion)
fullVersionList := brandList(ua, chromeVersionOrFallback(chromeVersion), greaseFullVersion)
@@ -326,6 +320,35 @@ func PlatformVersionFor(uaDataPlatform string) string {
return defaultPlatformVersions[uaDataPlatform]
}
+// architectureFor derives the UA-CH architecture the persona advertises. The host
+// is consulted under the same gate hostPlatformVersion applies to the OS version:
+// only a persona describing this host may read it. Without that gate a Windows or
+// Linux persona on an Apple Silicon host answered getHighEntropyValues with arm
+// while its own UA said "Win64; x64" — a contradiction a detector reads for free.
+//
+// macOS is the only host arm, and not merely because hostPlatformVersion has two:
+// real Chrome on Apple Silicon ships the "Intel Mac OS X" UA with architecture arm,
+// so there the host value agrees with the UA. The shipped Windows and Linux UAs
+// carry x64 and x86_64 literally, so the host may never override them — those
+// personas always report x86 today, since no matrix UA carries an ARM token.
+// The UA branch below is what a future ARM matrix entry would travel through; it is
+// unreachable rather than dead, and deleting it would remove the only correct way
+// to offer an ARM persona.
+func architectureFor(ua, uaDataPlatform string) string {
+ return architectureForHost(ua, uaDataPlatform, goruntime.GOOS, goruntime.GOARCH)
+}
+
+func architectureForHost(ua, uaDataPlatform, hostOS, hostArch string) string {
+ switch {
+ case strings.Contains(ua, "arm64"), strings.Contains(ua, "aarch64"), strings.Contains(ua, "ARM"):
+ return "arm"
+ case uaDataPlatform == "macOS" && hostOS == "darwin" && hostArch == "arm64":
+ return "arm"
+ default:
+ return "x86"
+ }
+}
+
func hostPlatformVersion(uaDataPlatform string) string {
switch {
case uaDataPlatform == "macOS" && goruntime.GOOS == "darwin":
diff --git a/internal/stealth/ua_test.go b/internal/stealth/ua_test.go
index 8547ccb9..17a63516 100644
--- a/internal/stealth/ua_test.go
+++ b/internal/stealth/ua_test.go
@@ -576,3 +576,111 @@ func TestPersonaBrandVersionsAreMajorInBrandsAndFullInTheVersionList(t *testing.
}
}
}
+
+// The architecture a persona advertises must agree with the architecture its own UA
+// claims. hostArchitecture-style host reads are gated exactly like
+// hostPlatformVersion's: only a persona describing this host may consult it. The
+// pure form takes the host facts as arguments, so both an ARM host and an x86 host
+// are asserted on every runner rather than only the one the suite happens to run on.
+func TestArchitectureIsDerivedFromThePersonaNotTheHost(t *testing.T) {
+ version := ReducedBrowserVersion("144.0.0.0")
+ hosts := []struct {
+ os string
+ arch string
+ }{
+ {"darwin", "arm64"},
+ {"darwin", "amd64"},
+ {"linux", "arm64"},
+ {"linux", "amd64"},
+ {"windows", "amd64"},
+ }
+
+ for _, platform := range []struct {
+ name string
+ uaDataPlatform string
+ want map[string]string
+ }{
+ {
+ name: PlatformWindows,
+ uaDataPlatform: "Windows",
+ want: map[string]string{"darwin/arm64": "x86", "darwin/amd64": "x86", "linux/arm64": "x86", "linux/amd64": "x86", "windows/amd64": "x86"},
+ },
+ {
+ name: PlatformLinux,
+ uaDataPlatform: "Linux",
+ want: map[string]string{"darwin/arm64": "x86", "darwin/amd64": "x86", "linux/arm64": "x86", "linux/amd64": "x86", "windows/amd64": "x86"},
+ },
+ {
+ name: PlatformMacOS,
+ uaDataPlatform: "macOS",
+ want: map[string]string{"darwin/arm64": "arm", "darwin/amd64": "x86", "linux/arm64": "x86", "linux/amd64": "x86", "windows/amd64": "x86"},
+ },
+ } {
+ ua := ChromeUserAgent(platform.name, version)
+ for _, host := range hosts {
+ key := host.os + "/" + host.arch
+ got := architectureForHost(ua, platform.uaDataPlatform, host.os, host.arch)
+ if want := platform.want[key]; got != want {
+ t.Errorf("architecture for the %s persona on a %s host = %q, want %q.\n"+
+ "Its UA is %q — a persona may only read the host architecture when it describes that host, "+
+ "the same gate hostPlatformVersion applies to the OS version.", platform.name, key, got, want, ua)
+ }
+ if edge := architectureForHost(EdgeUserAgent(ua, version), platform.uaDataPlatform, host.os, host.arch); edge != got {
+ t.Errorf("the Edge decoration of the %s persona reports %q where Chrome reports %q on a %s host", platform.name, edge, got, key)
+ }
+ }
+ }
+}
+
+// The ARM branch has no live input: no shipped matrix UA carries an ARM token, so it
+// is exercised with a synthetic UA. It is unreachable, not dead — a future ARM matrix
+// entry is the supported way to offer an ARM persona, and it travels through here.
+func TestAnArmUserAgentStillReportsArmOnAnyHost(t *testing.T) {
+ version := ReducedBrowserVersion("144.0.0.0")
+ for _, platform := range FingerprintPlatforms() {
+ ua := ChromeUserAgent(platform, version)
+ for _, token := range []string{"arm64", "aarch64", "ARM"} {
+ if strings.Contains(ua, token) {
+ t.Fatalf("the shipped %s UA %q now carries %q, so the synthetic UAs below no longer stand in for a real one — assert the matrix entry directly", platform, ua, token)
+ }
+ }
+ }
+
+ for _, ua := range []string{
+ "Mozilla/5.0 (Windows NT 10.0; Win64; arm64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
+ "Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
+ "Mozilla/5.0 (Linux; ARM) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
+ } {
+ for _, hostArch := range []string{"amd64", "arm64"} {
+ if got := architectureForHost(ua, "Windows", "linux", hostArch); got != "arm" {
+ t.Errorf("architecture for %q on a linux/%s host = %q, want arm — a UA that names ARM claims ARM whatever the host is", ua, hostArch, got)
+ }
+ }
+ }
+}
+
+// The struct field is not what a detector reads: getHighEntropyValues answers from the
+// userAgentMetadata handed to CDP, so the assertion follows the value onto the wire.
+// This runs against the real host, which is what makes it the case that would have
+// caught the original defect on an Apple Silicon machine.
+func TestRotatedPersonaMetadataArchitectureAgreesWithItsUserAgent(t *testing.T) {
+ version := "144.0.0.0"
+ hostIsAppleSilicon := goruntime.GOOS == "darwin" && goruntime.GOARCH == "arm64"
+
+ for _, platform := range FingerprintPlatforms() {
+ ua := ChromeUserAgent(platform, ReducedBrowserVersion(version))
+ override := BuildUserAgentOverride(ua, version)
+ if override == nil || override.UserAgentMetadata == nil {
+ t.Fatalf("%s persona carries no UA-CH metadata, so no architecture reaches the browser", platform)
+ }
+
+ want := "x86"
+ if platform == PlatformMacOS && hostIsAppleSilicon {
+ want = "arm"
+ }
+ if got := override.UserAgentMetadata.Architecture; got != want {
+ t.Errorf("getHighEntropyValues would report architecture %q for the %s persona on this %s/%s host, want %q.\n"+
+ "Its UA is %q.", got, platform, goruntime.GOOS, goruntime.GOARCH, want, ua)
+ }
+ }
+}