Skip to content

fix: 修复用户资源 URL 请求泄露 Grok 认证头的问题#545

Open
passer12 wants to merge 2 commits into
chenyme:mainfrom
passer12:fix/secure-asset-url-fetch
Open

fix: 修复用户资源 URL 请求泄露 Grok 认证头的问题#545
passer12 wants to merge 2 commits into
chenyme:mainfrom
passer12:fix/secure-asset-url-fetch

Conversation

@passer12
Copy link
Copy Markdown

Summary

修复 upload_from_input 在下载用户提供的资源 URL 时复用 Grok 请求头的问题。

此前该逻辑使用 build_http_headers(token, lease=lease) 构造请求头访问用户输入的 URL。该请求头用于访问 grok.com,会包含 Grok 认证相关的 Cookie 等信息,存在将用户 Grok token 派生凭据泄露给任意外部 URL 的风险。

本次修改后,用户资源 URL 下载仅使用通用图片下载请求头:

  • Accept
  • User-Agent

不再向用户提供的 URL 发送 CookieAuthorizationOriginRefererx-xai-request-idBaggage 等 Grok 专用或敏感请求头。上传文件到 Grok 的请求逻辑保持不变,仍继续使用 build_http_headers

Testing

  • 执行 python -m py_compile app/dataplane/reverse/transport/asset_upload.py,通过。

  • 使用图片 URL 验证多模态图片输入仍可正常工作:

    • https://picx.zhimg.com/....jpg
    • 返回 HTTP 200 OK
    • Grok 成功描述图片内容
  • 使用 webhook 风格 URL 验证外部 URL 请求行为:

    • https://webhook.site/.../test.png
    • 在 webhook.site 后台确认请求头不再携带 Grok 认证相关字段

Related

N/A

Copilot AI review requested due to automatic review settings May 18, 2026 03:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR mitigates a credential-leak risk by ensuring that when upload_from_input fetches user-provided resource URLs, it no longer reuses Grok-authenticated request headers (cookies and other Grok-specific headers) intended for grok.com.

Changes:

  • Introduced a dedicated _URL_FETCH_HEADERS header set for downloading user-provided URLs.
  • Updated upload_from_input to use _URL_FETCH_HEADERS (instead of build_http_headers) when calling session.get(...) for external URLs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/dataplane/reverse/transport/asset_upload.py Outdated
highkay added a commit to highkay/grok2api that referenced this pull request May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants