fix: 修复用户资源 URL 请求泄露 Grok 认证头的问题#545
Open
passer12 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
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_HEADERSheader set for downloading user-provided URLs. - Updated
upload_from_inputto use_URL_FETCH_HEADERS(instead ofbuild_http_headers) when callingsession.get(...)for external URLs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
highkay
added a commit
to highkay/grok2api
that referenced
this pull request
May 19, 2026
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.
Summary
修复
upload_from_input在下载用户提供的资源 URL 时复用 Grok 请求头的问题。此前该逻辑使用
build_http_headers(token, lease=lease)构造请求头访问用户输入的 URL。该请求头用于访问grok.com,会包含 Grok 认证相关的 Cookie 等信息,存在将用户 Grok token 派生凭据泄露给任意外部 URL 的风险。本次修改后,用户资源 URL 下载仅使用通用图片下载请求头:
AcceptUser-Agent不再向用户提供的 URL 发送
Cookie、Authorization、Origin、Referer、x-xai-request-id、Baggage等 Grok 专用或敏感请求头。上传文件到 Grok 的请求逻辑保持不变,仍继续使用build_http_headers。Testing
执行
python -m py_compile app/dataplane/reverse/transport/asset_upload.py,通过。使用图片 URL 验证多模态图片输入仍可正常工作:
https://picx.zhimg.com/....jpgHTTP 200 OK使用 webhook 风格 URL 验证外部 URL 请求行为:
https://webhook.site/.../test.pngRelated
N/A