-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(privacy): FrameCheckWrapper.js given incorrect value for url comparison #27320
base: master
Are you sure you want to change the base?
Changes from all commits
a5cc1cf
f8e2844
fb742f2
b998fd1
a7628ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
import Foundation | ||
import Shared | ||
import WebKit | ||
import XCTest | ||
|
||
class URLExtensionTests: XCTestCase { | ||
|
@@ -135,4 +136,58 @@ class URLExtensionTests: XCTestCase { | |
embeddedURL | ||
) | ||
} | ||
|
||
// Test that `windowOriginURL` returns the same value as `window.origin`. | ||
@MainActor func testWindowOriginURL() async { | ||
let testURLs = [ | ||
// multiple subdomains | ||
(URL(string: "https://one.two.three.example.com")!, "https://one.two.three.example.com"), | ||
// trailing slash | ||
(URL(string: "https://example.com/")!, "https://example.com"), | ||
// query | ||
(URL(string: "https://www.example.com/?v=1234567")!, "https://www.example.com"), | ||
// match | ||
(URL(string: "https://www.example.com")!, "https://www.example.com"), | ||
// punycode | ||
(URL(string: "http://Дом.ru/")!, "http://xn--d1aqf.ru"), | ||
// punycode | ||
(URL(string: "http://Дoм.ru/")!, "http://xn--o-gtbz.ru"), | ||
] | ||
|
||
let webView = WKWebView() | ||
for (value, expected) in testURLs { | ||
do { | ||
let expectation = XCTestExpectation(description: "didFinish") | ||
let navigationDelegate = NavigationDelegate(didFinish: { | ||
expectation.fulfill() | ||
}) | ||
webView.navigationDelegate = navigationDelegate | ||
webView.loadHTMLString("", baseURL: value) | ||
|
||
// await load of html | ||
await fulfillment(of: [expectation], timeout: 2) | ||
|
||
guard let result = try await webView.evaluateJavaScript("window.origin") as? String else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used in a unit test only to fetch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
XCTFail("Expected a String result") | ||
return | ||
} | ||
XCTAssertEqual(result, expected) | ||
XCTAssertEqual(result, value.windowOriginURL.absoluteString) | ||
} catch { | ||
XCTFail("Expected a valid `window.origin`") | ||
} | ||
} | ||
} | ||
} | ||
|
||
private class NavigationDelegate: NSObject, WKNavigationDelegate { | ||
private var didFinish: () -> Void | ||
|
||
init(didFinish: @escaping () -> Void) { | ||
self.didFinish = didFinish | ||
} | ||
|
||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | ||
didFinish() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't
URL.origin.url
akaURLOrigin(url: self).url
already do this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar. I would need to drop trailing slash but I believe with that either could be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this:
http://Дом.com
what does this return as the origin in both JS and URLComponents?If it returns the same, then it's all good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work fine in both. URLComponents correctly punycodes the domain.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://Дом.ru/
will outputhttp://xn--d1aqf.ru
http://Дoм.ru/
will outputhttp://xn--o-gtbz.ru
Added in a7628ea