-
Notifications
You must be signed in to change notification settings - Fork 47
feat: share app cookies with InAppBrowser WebView #132
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -240,10 +240,29 @@ class WebViewHostController: UIViewController, WKNavigationDelegate, WKUIDelegat | |
| override func viewDidAppear(_ animated: Bool) { | ||
| super.viewDidAppear(animated) | ||
|
|
||
| // Load URL in viewDidAppear | ||
| // Load URL in viewDidAppear after syncing cookies | ||
| if !hasLoadedURL { | ||
| hasLoadedURL = true | ||
| webView.load(URLRequest(url: url)) | ||
| syncCookiesAndLoad() | ||
| } | ||
| } | ||
|
|
||
| private func syncCookiesAndLoad() { | ||
| // Sync cookies from HTTPCookieStorage to WKWebView | ||
| let cookies = HTTPCookieStorage.shared.cookies ?? [] | ||
| let cookieStore = webView.configuration.websiteDataStore.httpCookieStore | ||
|
|
||
| let group = DispatchGroup() | ||
| for cookie in cookies { | ||
| group.enter() | ||
| cookieStore.setCookie(cookie) { | ||
| group.leave() | ||
| } | ||
|
Comment on lines
+258
to
+260
|
||
| } | ||
|
Comment on lines
+256
to
+261
|
||
|
|
||
| group.notify(queue: .main) { [weak self] in | ||
| guard let self = self else { return } | ||
| self.webView.load(URLRequest(url: self.url)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
All cookies from HTTPCookieStorage are being synced to the WebView without domain filtering. This is a security concern because the InAppBrowser can open external URLs (not just V2EX URLs, as seen in URLRouter's
.external(url: url)case). This means V2EX login cookies could be exposed to arbitrary third-party websites.Consider filtering cookies to only sync those whose domain matches the target URL's domain. For example, only sync cookies with domain matching "v2ex.com" when opening V2EX URLs.