Как принять атрибут samesite = строго к новой открытой вкладке - PullRequest
0 голосов
/ 24 апреля 2019

Я хочу открыть сайт в своем приложении.Ниже приведен код PoC для сайта.Если я открою ссылку выше тег ссылки прямо в той же вкладкеТогда cookie не будет добавлен в запрос.Если открыть в новой вкладке, cookie будет идти в запросе.если нажать на кнопку отправки.Вы увидите, что запрос GET / POST к https://humblehunter.io/temp/samesite.php содержит cookie, который должен быть защищен атрибутом samesite.

Я передал конфигурацию текущего веб-просмотра новому открытому веб-представлению в следующем коде, нокажется, что конфигурация не работает в новой вкладке.

func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration,
                 for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
        if navigationAction.targetFrame == nil {
            // WKWebView requires WKUIDelegate to return a child view created with
            // exactly the same |configuration| object (exception is raised if config is
            // different). |configuration| param and config returned by
            // WKWebViewConfigurationProvider are different objects because WKWebView
            // makes a shallow copy of the config inside init, so every WKWebView
            // owns a separate shallow copy of WKWebViewConfiguration.
            if let url = navigationAction.request.url, url.isHttpBased() || url.isFileBased() || UIApplication.shared.canOpenURL(url) {
                let newWebView = WKWebView(frame: CGRect.zero, configuration: configuration)
                newWebView.customUserAgent = UserAgent.defaultUserAgent

                self.delegate?.controller(self,
                                          didSelectOpenInNewTabWithURL: navigationAction.request.url,
                                          isPrivate: InPrivateModeHelper.isPrivateMode,
                                          shouldOpenInBackground: false,
                                          preConfiguredWebView: newWebView)

                return newWebView
            }
        }

        return nil
    }

Код PoC:

<!DOCTYPE html>
<html>
<body>
<a href="https://humblehunter.io/temp/samesite.php">samesite</a>
<!-- <a href="https://humblehunter.io/temp/samesite.php" target=_blank>samesite</a> -->
<form action="https://humblehunter.io/temp/samesite.php" method="post" target="_blank">
<input type="text" name="username" value="abcd" hidden=true><br>
<input type="text" name="password" value="xyz" hidden=true><br>
  <input type="submit" value="Submit">
</form>
</body>
</html>
...