Merged
Conversation
在模块顶层保存原生 CustomEvent、MouseEvent、dispatchEvent、addEventListener 引用, 防止页面脚本通过 hook 全局构造函数窃取 IPC 通信密钥,伪造 GM_* API 调用。
Collaborator
|
喔。。。你在修 mv2 |
Member
Author
有一个安全漏洞,处理一下,顺便看看还有什么firefox容易处理的问题 |
Member
Author
|
怎么 draft 了,不要大改啊,我只想解决问题,都不维护firefox的mv2了 |
Collaborator
跟 MV3 一样 改用 performanceClone 吧 |
Contributor
There was a problem hiding this comment.
Pull request overview
本 PR 旨在修复页面脚本通过 hook CustomEvent/dispatchEvent/addEventListener 等全局对象,从事件名中窃取 content↔inject IPC 通信密钥(flag)并伪造 GM_* 调用的权限提升漏洞;通过在模块初始化阶段缓存原生构造器与事件 API 引用,避免后续使用到可被页面篡改的全局对象。
Changes:
- 新增
src/app/message/common.ts:在模块顶层缓存CustomEvent/MouseEvent及事件派发/监听相关方法引用。 MessageContent改为使用缓存的构造器与事件方法进行收发,避免直接访问window.addEventListener/dispatchEvent。- 调整 Jest 初始化(新增
JEST_TESTING环境变量设置并变更 setup 配置),并更新.gitignore。
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/inject.ts | 轻微格式调整(空行),不影响功能。 |
| src/app/message/content.ts | 消息收发从直接调用全局事件 API 切换为使用缓存引用。 |
| src/app/message/common.ts | 新增缓存原生构造器/事件方法的公共模块,为通信防 hook 提供基础能力。 |
| jest.setup.js | 增加 process.env.JEST_TESTING = "true"。 |
| jest.config.js | 调整 Jest setup 文件加载顺序与配置项。 |
| .gitignore | 忽略新增的本地/测试输出相关目录与文件。 |
Comments suppressed due to low confidence (1)
src/app/message/content.ts:43
- 事件类型判断仍在使用可被页面脚本篡改的全局
MouseEvent:如果页面在运行后覆盖了window.MouseEvent,这里的instanceof MouseEvent可能失效,导致 relatedTarget 的分支不执行并把 MouseEvent 当成 CustomEvent 处理。建议改用已保存的原生引用MouseEventClone来做instanceof判断。
(event: unknown) => {
if (event instanceof MouseEvent) {
this.relatedTarget.set(event.clientX, <Element>event.relatedTarget);
return;
Member
Author
|
@cyfung1031 跑不通啊,还是要验证一下吧 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist / 检查清单
Description / 描述
修复页面脚本通过 hook
window.CustomEvent构造函数窃取 content↔inject IPC 通信密钥的权限提升漏洞。漏洞: inject 脚本在页面上下文中使用全局
CustomEvent/dispatchEvent/addEventListener,页面脚本可以 hook 这些全局对象,从事件名中提取通信密钥(flag),然后伪造任意 GM_* API 调用(包括GM_xmlhttpRequest、GM_cookie等)。修复: 在模块顶层(content script
document_start注入时,早于任何页面脚本执行)保存原生 API 引用,后续通信全部使用保存的引用,不再直接访问可被篡改的全局对象。参考 v1.3
packages/message/common.ts的做法。Screenshots / 截图
N/A