mirror of
https://github.com/block/buzz.git
synced 2026-11-30 21:21:48 +00:00
Allow bb-block staging in native browser authentication
Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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) }
|
||||
|
||||
Reference in New Issue
Block a user