[BUG]: Some JS characters aren't escaped when running the page-ready check
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 75/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, python
- 领域
- devtools, security, testing-qa
调研方向
该错误位于 src/choreographer/protocol/devtools_async_helpers.py 的第 37 行,其中将 URL 插入到了 JavaScript 模板字面量中。首先检查 create_and_wait 函数及其周围的 devtools 协议辅助函数。使用 json.dumps 正确转义 URL 字符串,并更新该函数以检查响应中的 exceptionDetails。运行提供的复现脚本来验证修复。
由索引模型根据 Issue 内容生成。
描述
Description
The page-ready check inserts the URL into a JavaScript template literal without escaping it, at src/choreographer/protocol/devtools_async_helpers.py:37. A backtick in the URL ends the literal, and a ${...} sequence in the URL runs as JavaScript.
Steps to reproduce
- Run the following code:
import asyncio
import choreographer as choreo
from choreographer.protocol.devtools_async_helpers import create_and_wait
async def main():
browser = await choreo.Browser(headless=True)
try:
# Correct: raises TimeoutError after 5s, because the address never loads
await create_and_wait(browser, url="http://192.0.2.1:9999", timeout=5.0)
except TimeoutError:
print("plain URL: TimeoutError")
# Wrong: returns after 0.02s, for the same unreachable address
await create_and_wait(browser, url="http://192.0.2.1:9999/`", timeout=5.0)
print("URL with a backtick: returned OK")
await browser.close()
asyncio.run(main())
For the second problem, pass https://www.example.com/${(window.__injected = 42, "")} to create_and_wait, then read window.__injected back from the page. The value is 42.
Notes
- With this bug:
- A backtick makes the script raise a
SyntaxError.Runtime.evaluatereturns that as a normal response, and the race increate_and_waitcounts any finished task as a load. Socreate_and_waitreturns a tab for a page that never loaded. - A
${...}sequence runs arbitrary JavaScript in the page.
- A backtick makes the script raise a
- A fix is to build the JavaScript string with
json.dumps(url)and drop the backticks from the template.json.dumpssupplies its own quotes and escapes the contents, so a backtick and a${are both inert. create_and_waitshould also inspect the response forexceptionDetailsinstead of counting every finished task as a successful load- This was found while working on #295
- 主要语言
- Python
- 星标
- 17
- 派生
- 10
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
plotly/choreographer 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 45/100
plotly/choreographer#287 · 7 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 42/100
plotly/choreographer#284 ·
-
难度 3/5 1-2 天 新手友好度 45/100
plotly/choreographer#259 ·
查看 plotly/choreographer 的全部 Issue
相似的 Issue
-
cost:cheap practicality:seen-in-the-wild severity:medium
难度 2/5 1-3 小时 新手友好度 72/100
fairagro/m4.2_advanced_middleware_api#620 ·
维护者通常 1 天内回复
-
area:security effort:S priority:P2 provider:local-libvirt status:ready type:docs
难度 2/5 1-3 小时 新手友好度 75/100
randomparity/kdive#3495 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
microsoft/markitdown#2820 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复