Skip to content

[BUG] inject-into无法正确绕过csp限制的bug #866

@1665169869

Description

@1665169869

问题描述

基于vite-monkey写的脚本dev调试情况下用inject-into无法正确绕过csp限制的bug
实测后:
vite-plugin-monkey build编译导入 == 正确注入脚本
vite-plugin-monkey dev调试 == 无法绕过csp
Image
Image

重现步骤

  1. pnpm create monkey
  2. 使用inject-into
  3. pnpm dev

脚本猫版本

v1.2.0.1300 beta

操作系统以及浏览器信息

windows11 edge 版本 135.0.3179.73 (正式版本) (64 位)

补充信息 (选填)

测试代码如下:

main.js

const div = document.createElement("div");
div.innerHTML = "hello scriptcat";
document.body.append(div);

vite.config.js

export default defineConfig({
  plugins: [
    monkey({
      entry: 'src/main.js',
      userscript: {
        icon: 'https://vitejs.dev/logo.svg',
        namespace: 'npm/vite-plugin-monkey',
        name: 'test',
        version: '1.0.0',
        description: 'test',
        "inject-into": "content",
        grant: 'none',
        match: ['http://www.example.com/*'],
      },
    }),
  ],
});

HTTP Response

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: no-store, no-cache, must-revalidate
Connection: keep-alive
Content-Encoding: gzip
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; media-src 'none'; frame-ancestors 'none';
Content-Type: text/html; charset=UTF-8
Date: Mon, 20 Oct 2025 06:33:23 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive: timeout=4
Pragma: no-cache
Proxy-Connection: keep-alive
Server: nginx
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Xss-Protection: 1; mode=block

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1🔥 重要但是不紧急的内容

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions