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

Đang mở Phù hợp với người mới
#316 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@Blizzeq đang làm issue này rồi.

Từ ngày 1/10/2026.

  • #317 của @Blizzeq — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, python
Lĩnh vực
devtools, security, testing-qa

Hướng nghiên cứu

Lỗi nằm trong src/choreographer/protocol/devtools_async_helpers.py tại dòng 37, nơi một URL được chèn vào một template literal JavaScript. Hãy bắt đầu bằng cách kiểm tra hàm create_and_wait và các trình trợ giúp giao thức devtools xung quanh. Sử dụng json.dumps để escape chuỗi URL một cách chính xác, và cũng cập nhật hàm để kiểm tra exceptionDetails trong phản hồi. Chạy tập lệnh tái tạo được cung cấp để xác minh bản sửa lỗi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Python
Star
17
Fork
10
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của plotly/choreographer

Tất cả issue của plotly/choreographer

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.