[BUG]: Some JS characters aren't escaped when running the page-ready check

未关闭 适合新手
#316 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@Blizzeq 已经在做这个了。

开始于 2026年10月1日。

  • #317 来自 @Blizzeq —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript, python

调研方向

该错误位于 src/choreographer/protocol/devtools_async_helpers.py 的第 37 行,其中将 URL 插入到了 JavaScript 模板字面量中。首先检查 create_and_wait 函数及其周围的 devtools 协议辅助函数。使用 json.dumps 正确转义 URL 字符串,并更新该函数以检查响应中的 exceptionDetails。运行提供的复现脚本来验证修复。

由索引模型根据 Issue 内容生成。

描述

bug P3 size: 1
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.evaluate returns that as a normal response, and the race in create_and_wait counts any finished task as a load. So create_and_wait returns a tab for a page that never loaded.
    • A ${...} sequence runs arbitrary JavaScript in the page.
  • A fix is to build the JavaScript string with json.dumps(url) and drop the backticks from the template. json.dumps supplies its own quotes and escapes the contents, so a backtick and a ${ are both inert.
  • create_and_wait should also inspect the response for exceptionDetails instead of counting every finished task as a successful load
  • This was found while working on #295
主要语言
Python
星标
17
派生
10
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

plotly/choreographer 的其他 Issue

查看 plotly/choreographer 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。