scriptcat icon indicating copy to clipboard operation
scriptcat copied to clipboard

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

Open 1665169869 opened this issue 2 months ago • 3 comments

问题描述

基于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

1665169869 avatar Oct 20 '25 06:10 1665169869

Image Image

有完整的脚本代码吗? ( 要看 metablock )

cyfung1031 avatar Oct 20 '25 06:10 cyfung1031

Image Image

有完整的脚本代码吗? ( 要看 metablock )

有的1665169869/inject-into-example-bug

1665169869 avatar Oct 20 '25 09:10 1665169869

归档.zip

一个可在 https://content-security-policy.com/ 复现的示例,这似乎是一个合理的表现,参考:https://github.com/lisonge/vite-plugin-monkey/issues/1

在 inject-into content 可以绕过元素的CSP策略,但是这里使用的方法是通过网络的形式注入脚本,是被网络层面的CSP策略拦截的,可以考虑给脚本猫也添加上一个禁用CSP策略的选项

CodFrm avatar Oct 20 '25 15:10 CodFrm