Inline script triggers CSP error in chrome extension

オープン
#945 コメント 1 件 リアクション 6 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript

調査の方向性

まず injectVueHookToIframe を見つけ、Manifest V3 CSP を使用する Chrome 拡張機能で問題を再現します。インラインスクリプトの作成を追跡し、CSP 違反を回避する外部コードの注入方法を決定します。Vue devtools iframe hook が報告されたエラーなしで動作すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

When using vite plugin vue devtools to develop a chrome extension page, the extension reported the following error:

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost: * http://127.0.0.1: *". Either the 'unsafe-inline' keyword, a hash ('sha256-FhCISuQOxB+ZEYLZlvQzFWx4//lRqFQPUeFSEkdvsT0='), or a nonce ('nonce-...') is required to enable inline execution.

It seems to be triggered by the following code:

function injectVueHookToIframe(iframe) {
  if (iframe.__vdevtools__injected) return
  try {
    iframe.__vdevtools__injected = true
    const inject = () => {
      try {
        iframe.contentWindow.__VUE_DEVTOOLS_IFRAME__ = iframe
        const script = iframe.contentDocument.createElement('script')
        script.textContent = `;(${detectIframeApp.toString()})(window, true)`
        iframe.contentDocument.documentElement.appendChild(script)
        script.parentNode.removeChild(script)
      } catch (e) {}
    }
    inject()
    iframe.addEventListener('load', () => inject())
  } catch (e) {}
}

The problem is:

// This line attempts to inject inline script blocks
script.textContent = `;(${detectIframeApp.toString()})(window, true)`
iframe.contentDocument.documentElement.appendChild(script)

In chrome extension Manifest V3, there is no way to declare inline script as safe, CSP will prevent code injection and throw errors.

Can the injection method of the code be changed to external code?

主要言語
TypeScript
スター
2.9k
フォーク
291
平均マージ
2日 48分
マージ済み PR(30日)
19

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vuejs/devtools のほかの issue

vuejs/devtools の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。