🐛 修正脚本资源分类与页面资源权限边界 - #1686
Open
cyfung1031 wants to merge 16 commits into
Open
Conversation
cyfung1031
marked this pull request as ready for review
August 22, 2026 01:32
Collaborator
Author
|
结论:发现一个 P2,建议 Request changes,置信度高。 [P2] 非法
|
Collaborator
Author
|
已针对本 PR 关联评论中的两个问题完成修复,并推送到当前 PR head 762795d9。 修复内容:
验证:
此修复沿用现有 parser 的声明形状语义,没有扩大 URL scheme 校验范围。 |
cyfung1031
marked this pull request as draft
August 24, 2026 10:21
Collaborator
Author
|
改動較大。先人手檢查一下代碼再Ready |
3 tasks
This comment was marked as resolved.
This comment was marked as resolved.
cyfung1031
marked this pull request as ready for review
September 8, 2026 20:21
Collaborator
Author
|
AI 修正了问题也审查了 |
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 / 检查清单
N/A — 本 PR 未关联需要自动关闭的 issue;主要跟进 PR review 中确认的资源边界问题。
Description / 描述
背景
ResourceService原先会把@require、@require-css和@resource合并到同一个 string-keyed map,再沿页面执行链路继续传递。这样会带来三个问题:@require仍可能被重复带入页面 payload;@resource没有按实际可用的 GM Resource API grant 做边界过滤;后续 review 还确认了两个兼容性缺口:页面 resource gate 与
createContext()的GM./GM_grant 转换规则曾经各自维护,可能静默丢弃合法@resource;同时GM.getResourceURL虽已出现在 ScriptCat 的公开类型中,runtime API 注册并未完整覆盖该大小写形式。本次改动
parseResourceDeclaration(),让资源读取和安装/更新路径使用同一套@resource <name> <url>解析规则;非法声明不会进入资源下载流程。require、require-css、resource三个独立 map,并让编译、页面缓存、本地file:///刷新及各 consumer 优先使用类别来源。@require已编译进代码,不再作为页面 resource payload 转发;@require-css单独放入requireCssResource;@resource只在脚本具有有效 Resource API grant 时转发声明过的名称。getGrantCandidates(),由createContext()与 page resource gate 共用GM.↔GM_compatibility expansion,避免两套规则再次漂移。GM_getResourceTextGM.getResourceTextGM_getResourceURLGM.getResourceUrlGM.getResourceURLGM_getResourceUrlGM.getResourceURLruntime API,与公开类型定义保持一致。resourceByType时只读取resourceByType.resource;仅对没有分类表的旧 payload 回退到 legacyresource,避免 background/scheduled script 把同名@require当作@resource读取。script_executor的requireCssResource ?? resource兼容路径,用于旧的已注册 userscript payload。测试与回归覆盖
新增/调整的测试覆盖:
trimScriptInfo()到createContext()再到真实 GM API 调用的跨边界行为;@grant none与 context-menu 的既有 grant 语义;@require/@require-css/@resource同 key 时的类别隔离;@require编译顺序及页面 payload 不重复携带;@require-css声明顺序与 category-specific CSS 选择;@resource不创建资源、也不触发安装下载;与本问题无关的 sandbox isolation / value-update routing 验证已从本 PR final diff 移除,避免扩大审查范围。
实现考虑与兼容性
ScriptRunResource.resource的 merged map 目前仍作为兼容形状保留,但新的核心 consumer 已改用类别来源。完全移除 merged internal model 会涉及 background/sandbox、注册脚本 payload 与跨版本兼容,留待后续独立 refactor,不在本 bug-fix PR 扩大范围。本 PR 不宣称量化的 heap 或 runtime 性能提升。当前可以直接由数据流验证的是:页面边界不再携带已编译的
@require,并且未获得 Resource API 能力的脚本不会收到对应@resourcepayload。定量内存/性能比较留给后续 profiling。建议审查重点
getGrantCandidates()是否与createContext()的既有 grant compatibility 语义一致;resourceByType是否在 page cache、local refresh、background/sandbox 与页面 consumer 间保持正确类别;resource/ CSS fallback 是否只承担兼容职责,没有重新成为新路径的权威 source;require/require-css/resource时,各 consumer 是否读取正确类别。验证
Final diff 绑定:
a466b22ef78fa983348f298b1737a4ad24cec1962a9a55e633e83061ea31e5fc111d059cac3c42e3当前 head 的 GitHub checks:
testworkflow — successcodecov/project— success,72.08% (+0.01%)compared with basea466b22早期 head 曾做过额外本地与 browser verification,但由于之后仍有 grant/API/test commits,本描述不把那些旧 revision 的结果作为 final-head acceptance evidence;当前 readiness 以以上绑定到
2a9a55e的远端 checks 与 final diff 为准。Screenshots / 截图
N/A — 非视觉改动。