Allow bb-block staging in native browser authentication

Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
Tom Brow
2026-10-20 17:07:23 -07:00
parent 91d7d325d4
commit 3c3fc0b0c2
2 changed files with 27 additions and 4 deletions

View File

@@ -1126,6 +1126,14 @@ extension BuzzPushNavigationTarget {
/// Keeps the authentication callback scoped to the system browser session.
// Keep native login origins aligned with HostedEnvironment's trusted account origins.
func isTrustedBuzzBrowserAuthURL(_ url: URL) -> Bool {
url.scheme == "https"
&& ["app.builderlab.xyz", "app.builderlabstaging.xyz", "test.blockstaging.build"].contains(url.host ?? "")
&& url.path == "/api/goose/v1/auth/login" && url.user == nil && url.password == nil
&& url.port == nil && url.fragment == nil
}
private final class BuzzBrowserAuthBridge: NSObject, ASWebAuthenticationPresentationContextProviding {
private let channel: FlutterMethodChannel
private var session: ASWebAuthenticationSession?
@@ -1147,10 +1155,7 @@ private final class BuzzBrowserAuthBridge: NSObject, ASWebAuthenticationPresenta
guard self.session == nil,
let args = call.arguments as? [String: String],
let raw = args["url"], let url = URL(string: raw),
url.scheme == "https",
["app.builderlab.xyz", "app.builderlabstaging.xyz"].contains(url.host ?? ""),
url.path == "/api/goose/v1/auth/login", url.user == nil, url.password == nil,
url.port == nil, url.fragment == nil
isTrustedBuzzBrowserAuthURL(url)
else { result(FlutterError(code: "unavailable", message: nil, details: nil)); return }
self.pending = result
let attemptID = UUID()

View File

@@ -8,6 +8,24 @@ import XCTest
class RunnerTests: XCTestCase {
func testBrowserAuthAcceptsConfiguredStagingAndRejectsUntrustedURLs() throws {
for host in ["app.builderlab.xyz", "app.builderlabstaging.xyz", "test.blockstaging.build"] {
let url = try XCTUnwrap(URL(string: "https://\(host)/api/goose/v1/auth/login?type=cli&product=buzz"))
XCTAssertTrue(isTrustedBuzzBrowserAuthURL(url), host)
}
for raw in [
"http://test.blockstaging.build/api/goose/v1/auth/login",
"https://test.blockstaging.build.attacker.test/api/goose/v1/auth/login",
"https://buzz.test.blockstaging.build/api/goose/v1/auth/login",
"https://test.blockstaging.build/other",
"https://user@test.blockstaging.build/api/goose/v1/auth/login",
"https://test.blockstaging.build:8443/api/goose/v1/auth/login",
"https://test.blockstaging.build/api/goose/v1/auth/login#fragment",
] {
XCTAssertFalse(isTrustedBuzzBrowserAuthURL(try XCTUnwrap(URL(string: raw))), raw)
}
}
@MainActor
private func descendants(of view: UIView) -> [UIView] {
view.subviews.flatMap { [$0] + descendants(of: $0) }