Chrome 48+ でウェブセキュリティを無効にする 質問する

Chrome 48+ でウェブセキュリティを無効にする 質問する

フラグに問題があります--disable-web-security。Windows の Chrome 48 および Chrome 49 ベータ版では動作しません。

まず、すべてのインスタンスを強制終了し、再起動してフラグ付きで Chrome を実行し、別のマシンでも試してみました。ベータ版では、警告ポップアップ (「サポートされていないフラグを使用しています...」) が表示されますが、CORS は引き続き適用されています。パブリック バージョンでは、フラグが完全に無視されるようです。

それに関するニュースや人々の報告はないようですので、地元の問題である可能性があります。ご助力や関連情報をいただければ幸いです。

ベストアンサー1

2021-10-18更新

Chrome 95 の時点では、MacOS と Windows では、--disable-site-isolation-trialsWeb セキュリティを無効にするために必要なフラグのままであるため、以下に示す Chrome のコマンドライン引数は引き続き有効です。(一部の引数は Chrome で正式にサポートされていないため、警告が表示されます。)

ウェブセキュリティを無効にした状態でChromeが正常に起動したかどうかをテストするには、次のスニペットを実行します。ウェブセキュリティテストこの投稿の下部にあります。

2020-04-30更新

Chrome 81以降では、両方 --disable-site-isolation-trialsを有効にする--user-data-dirには、を介して空でないプロファイル パスを指定する必要があります。--disable-web-security

# MacOS (in Terminal)
open -na Google\ Chrome --args --user-data-dir=/tmp/temporary-chrome-profile-dir --disable-web-security --disable-site-isolation-trials

# Windows (from "Run" dialog [Windows+R] or start menu in Windows 8+)
chrome.exe --user-data-dir=%TMP%\temporary-chrome-profile-dir --disable-web-security --disable-site-isolation-trials

(推測)Chromeでは、デフォルトプロファイルでウェブセキュリティを無効にしてブラウザを起動した場合の高いセキュリティリスクを軽減するために、空でないプロファイルパスが必要であると思われます。 --user-data-dir=--user-data-dir=/some/path 詳細については下記をご覧ください。

感謝スネビョルンコメント欄に Chrome 81 のヒントを投稿してください。


2020-03-06更新

Chrome 80以降(おそらくそれ以前)では、フラグの組み合わせは--user-data-dir=/tmp/some-path --disable-web-security --disable-site-isolation-trials ウェブセキュリティを無効にしなくなりました

Chromiumのコードベースがいつ後退したかは不明ですが、Chromiumの古いビルド(Chromium ダウンロード ページの「それほど簡単ではない手順」) が私が見つけた唯一の回避策です。最終的には、これらのフラグを使用して Web セキュリティを適切に無効にするバージョン 77.0.3865.0 を使用しました。


オリジナル投稿 2019-11-01

--disable-site-isolation-trialsChrome 67 以降では、引数と一緒にフラグを渡し--user-data-dir=--disable-web-securityWeb セキュリティを完全に無効にする必要があります。

MacOS では、完全なコマンドは次のようになります。

open -na Google\ Chrome --args --user-data-dir= --disable-web-security --disable-site-isolation-trials

に関して--user-data-dir

パーデイビッド・アメイの回答--user-data-dir=ただし、 Chrome がオプションを尊重するように指定する必要があります--disable-web-security

--user-data-dir=--user-data-dir=/some/path

経由で空のパスを渡すことは では機能--user-data-dir=します--disable-web-securityが、電子メールなどへのアクティブなログイン セッションを持つデフォルトの Chrome プロファイルを使用するため、セキュリティ上の理由から推奨されません。Chrome セキュリティが無効になっていると、アクティブなセッションはブラウザ内の追加の脆弱性に対して脆弱になります。

したがって、Chromeプロファイルには代替ディレクトリを使用することをお勧めします--user-data-dir=/tmp/chrome-sesh@ジェームスBコメントでこの点を指摘していただきありがとうございます。

ソース

この修正は、ブラウザ テスト フレームワーク Cypress 内で発見されました。参考:

ウェブセキュリティテスト

このソリューションによって Google Chrome の Web セキュリティが実際に無効になったことを確認するには、次のスニペットを実行します。

window.addEventListener("DOMContentLoaded", () => {
  const iframe = document.querySelector("iframe");
  iframe.addEventListener("load", () => {
    const canAccessIframeDocument = !!iframe.contentDocument;
    document
      .querySelector(
        canAccessIframeDocument ? ".security-disabled" : ".security-enabled"
      )
      .classList.remove("hidden");
  });
  // To ensure the `load` event always fires, only set iframe src after the
  // event listener is attached.
  iframe.src = "https://google.com";
});
body {
  font-family: sans-serif;
}

.hidden {
  display: none;
}

/* Web security should normally be enabled, so this is colored green, despite
   the objective of this solution to disable it. */
.security-enabled {
  font-weight: bold;
  color: darkgreen;
}

.security-disabled {
  font-weight: bold;
  color: darkred;
}
<h1>Web Security Test</h1>
<p>
  This test attempts to access the inner contents of a cross-origin iframe,
  which is normally disallowed.
</p>
<p class="security-enabled hidden">
  Web security is enabled. The cross-origin iframe document could not be
  accessed.
</p>
<p class="security-disabled hidden">
  Web security is disabled. The cross-origin iframe document was
  successfully accessed.
</p>
<iframe class="hidden">
  Iframes are not supported.
</iframe>

おすすめ記事