-
Notifications
You must be signed in to change notification settings - Fork 33.7k
fix: read CF API credentials from POST body to prevent URL-based leakage #1126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,21 @@ export default { | |
| return new Response(读取日志内容, { status: 200, headers: { 'Content-Type': 'application/json;charset=utf-8' } }); | ||
| } else if (区分大小写访问路径 === 'admin/getCloudflareUsage') {// 查询请求量 | ||
| try { | ||
| const Usage_JSON = await getCloudflareUsage(url.searchParams.get('Email'), url.searchParams.get('GlobalAPIKey'), url.searchParams.get('AccountID'), url.searchParams.get('APIToken')); | ||
| // 优先从 POST body 读取凭据(避免敏感信息暴露在 URL / 服务器日志中) | ||
| // 兼容旧版 GET query 参数作为降级方案 | ||
| let Email, GlobalAPIKey, AccountID, APIToken; | ||
| if (request.method === 'POST') { | ||
| try { | ||
| const body = await request.json(); | ||
| Email = body.Email; GlobalAPIKey = body.GlobalAPIKey; | ||
| AccountID = body.AccountID; APIToken = body.APIToken; | ||
| } catch (_) { } | ||
| } | ||
| Email = Email ?? url.searchParams.get('Email'); | ||
| GlobalAPIKey = GlobalAPIKey ?? url.searchParams.get('GlobalAPIKey'); | ||
| AccountID = AccountID ?? url.searchParams.get('AccountID'); | ||
| APIToken = APIToken ?? url.searchParams.get('APIToken'); | ||
|
||
| const Usage_JSON = await getCloudflareUsage(Email, GlobalAPIKey, AccountID, APIToken); | ||
|
Comment on lines
+90
to
+106
|
||
| return new Response(JSON.stringify(Usage_JSON, null, 2), { status: 200, headers: { 'Content-Type': 'application/json' } }); | ||
| } catch (err) { | ||
| const errorResponse = { msg: '查询请求量失败,失败原因:' + err.message, error: err.message }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For POST requests, this attempts
request.json()unconditionally and silently ignores parse errors. That means non-JSON/empty/malformed bodies fall back to query params with no signal, and the common case relies on exceptions for control flow. Consider gating parsing onContent-Type: application/json(you already computecontentTypeearlier) and returning a 400 for invalid JSON when method is POST, instead of swallowing the error.