Skip to content

fix(logging): 隐藏访问日志中的查询凭据 - #7972

Merged
seefs001 merged 2 commits into
QuantumNous:mainfrom
ceezyyy:fix/redact-access-log-final
Oct 23, 2026
Merged

seefs001 merged 2 commits into
QuantumNous:mainfrom
ceezyyy:fix/redact-access-log-final

Conversation

@ceezyyy

@ceezyyy ceezyyy commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

问题

Closes #7970

访问日志会记录 Gemini ?key=... 等查询凭据。这个 PR 接续 #7969,将最终修复整理为一个提交,并包含此前评审指出的原始 # 和非法编码边界。

改动

在 URL 副本上复用现有脱敏函数,不修改请求。保留转义路径,避免原始 # 被解析成 fragment;查询串解析失败时,日志只保留路径。保留现有 OAuth 和制品访问凭据处理。

13 个回归场景同时检查日志脱敏、原始查询串和 RequestURI 保留、普通参数、状态及请求关联信息。

验证

基线为官方 7fb6e57a,Go 1.27.0 / macOS amd64,设置 GO111MODULE=on GOWORK=off:

  • 原版日志代码下:10 个凭据场景失败、3 个兼容性场景通过;修复后 13 个场景全部通过。
  • go test ./middleware -count=1:通过。
  • go test -race ./middleware -run 'TestSetUpLogger|TestTaskArtifactAccess|TestRedactTaskArtifactAccess' -count=1:通过。
  • go vet ./middleware、git diff --check:无错误。

仅使用假 Key 和内存请求;未调用生产或供应商,反向代理及历史日志不在范围内。依据 OWASP ASVS 5.0.0 的 16.2.5 避免记录可用凭据。

代码由 AI 辅助完成。

Summary by CodeRabbit

  • Bug Fixes
    • Sensitive values in non-OAuth request URLs are now redacted from logs. Malformed query strings are logged as paths only, while OAuth callback queries remain omitted.
    • Request URLs and queries continue to be preserved for normal request handling.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 284b418c-6364-46dd-880c-ca192f88c1c1
📥 Commits

Reviewing files that changed from the base of the PR and between 9a87fa6 and 09532ae.

📒 Files selected for processing: 2
  • middleware/logger.go
  • middleware/logger_test.go
+---------------------------------------------------------------------------+
| In Vino Veritas, In Codice Bugas. In wine, there is truth; in code, bugs. |
+---------------------------------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1e80c397-a285-46be-aa41-0a791311ba71
📥 Commits

Reviewing files that changed from the base of the PR and between 7fb6e57 and ed69bba.

📒 Files selected for processing: 2
  • middleware/logger.go
  • middleware/logger_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

The access logger now sanitizes non-OAuth request URLs before logging. It omits OAuth query strings and logs only the path when query parsing fails. Tests check credential redaction and confirm that the request query and URI remain unchanged.

Changes

Access log query sanitization

Layer / File(s) Summary
Sanitize request URLs in logs
middleware/logger.go, middleware/logger_test.go
The logger sanitizes non-OAuth query values and omits OAuth query strings. If query parsing fails, it logs only the path. Tests cover these cases and verify that request query data remains unchanged.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: calcium-ion

Merge Risk: ⚪ Minimal · up to ed69b

Access logs redact the covered query credentials without changing requests. No merge-blocking issue was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: hiding query credentials in access logs.
Linked Issues check Passed Issue #7970 requires access-log redaction for URL query credentials while preserving the request query and RequestURI, retaining the path and ordinary parameters, and preserving OAuth and artifact cre…
Out of Scope Changes check Passed The reviewed changes are limited to access-log URL handling in middleware/logger.go and a focused regression test in middleware/logger_test.go. The test directly supports issue #7970. No unrelated…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
Full details: Linked Issues check

Explanation

Issue #7970 requires access-log redaction for URL query credentials while preserving the request query and RequestURI, retaining the path and ordinary parameters, and preserving OAuth and artifact credential handling. middleware/logger.go copies param.Request.URL, converts raw # before sanitization, uses relaycommon.SanitizeURLForLog, and logs only the path when url.ParseQuery fails. The existing redactTaskArtifactAccessQuery() middleware remains installed. middleware/logger_test.go covers repeated and encoded keys, escaped %23 and %25 paths, raw #, malformed queries, ordinary parameters, OAuth queries, status, request IDs, and request preservation.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to access-log URL handling in middleware/logger.go and a focused regression test in middleware/logger_test.go. The test directly supports issue #7970. No unrelated production behavior or deployment, proxy, historical-log, or external-service work is present in the supplied change summary and reviewed files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the log at night
And keeps each secret out of sight
The path stays clear, the query stays
Untouched for handlers through their days
Then hops away beneath the moon

Comment @coderabbitai help to get the list of available commands.

@ceezyyy
ceezyyy force-pushed the fix/redact-access-log-final branch from ed69bba to 9a87fa6 Compare October 22, 2026 16:39
@seefs001
seefs001 merged commit 30748c6 into QuantumNous:main Oct 23, 2026
1 check was pending
cicioln pushed a commit to cicioln/new-api that referenced this pull request Oct 25, 2026
* fix(logging): 隐藏访问日志中的查询凭据

* fix(logging): redact query credentials in access logs

---------

Co-authored-by: seefs001 <[email protected]>
(cherry picked from commit 30748c6)
cyanmst pushed a commit to cyanmst/new-api-cyanmst that referenced this pull request Oct 26, 2026
* fix(logging): 隐藏访问日志中的查询凭据

* fix(logging): redact query credentials in access logs

---------

Co-authored-by: seefs001 <[email protected]>
(cherry picked from commit 30748c6)
kyuhwi-choi pushed a commit to attodev/new-api that referenced this pull request Oct 28, 2026
* fix(logging): 隐藏访问日志中的查询凭据

* fix(logging): redact query credentials in access logs

---------

Co-authored-by: seefs001 <[email protected]>
(cherry picked from commit 30748c6)
lizhongyi1209 pushed a commit to lizhongyi1209/new-api that referenced this pull request Nov 1, 2026
* fix(logging): 隐藏访问日志中的查询凭据

* fix(logging): redact query credentials in access logs

---------

Co-authored-by: seefs001 <[email protected]>
Tangxinyan0904 pushed a commit to Tangxinyan0904/new-api that referenced this pull request Nov 4, 2026
* fix(logging): 隐藏访问日志中的查询凭据

* fix(logging): redact query credentials in access logs

---------

Co-authored-by: seefs001 <[email protected]>
(cherry picked from commit 30748c6)
shirosoralumie648 added a commit to shirosoralumie648/newapi-rev that referenced this pull request Nov 5, 2026
Sync 75 upstream commit(s) via merge (fork history preserved).

Upstream commits:
- 7061447 fix(auth): 校验 Redis 鉴权缓存完整性 (QuantumNous#8200)
- ba5f736 fix(gemini): bill embeddings from upstream usageMetadata (QuantumNous#8182)
- 94b5216 feat(vertex): add per-channel v1beta1 endpoint switch (QuantumNous#8179)
- 83b18fe feat(channel): return created IDs with input mappings (QuantumNous#8164)
- 52c1730 feat(gemini): add Argon fields and reasoning mappings (QuantumNous#8177)
- 9b473a3 fix(twofa): restart the failure count after a lockout expires (QuantumNous#8172)
- 45746ee feat(relay): add opt-in HTTP/2 health checks (QuantumNous#8059)
- c046559 feat(plugins): bill gemini omni by the tokens vertex reports (QuantumNous#8153)
- 651d5a2 fix(xai): preserve token details in stream usage conversion (QuantumNous#6420)
- 70e6af6 perf: read and edit request JSON and base64 with moego (QuantumNous#8148)
- d0abbf6 feat(plugins): generate video with Gemini Omni on Vertex AI channels (QuantumNous#8142)
- ea343c4 fix(plugins): charge relayed streams even when the reserve or task insert fails (QuantumNous#8121)
- fe57cba fix(plugins): prefer Kling's returned price (list_price) for Kling 4.0 cash billing (QuantumNous#8125)
- 1424ffd fix(plugins): load plugins that declare their own /{key} address (QuantumNous#8119)
- 8b253de fix(plugins): keep Kling 4.0 durations in range and map every video size (QuantumNous#8118)
- c59f6fd feat(plugins): serve task plugins at the vendors' own paths and answer as the vendors do (QuantumNous#8117)
- 37d23dc fix(profile): honor global sidebar visibility (QuantumNous#7429)
- 7743627 fix(deps): upgrade DOMPurify to 3.4.17 (QuantumNous#8116)
- 883eeb8 feat(plugins): warn about task models a plugin cannot charge
- 1e8c707 chore(deps): bump @codemirror/language from 6.12.4 to 6.13.1 in /web (QuantumNous#8102)
- 6e78cb3 chore(deps): bump marked from 18.0.6 to 18.1.2 in /web (QuantumNous#8103)
- 9fc70bb chore(deps-dev): bump @tanstack/react-query-devtools in /web (QuantumNous#8104)
- cef7820 chore(deps-dev): bump knip from 6.27.0 to 6.43.0 in /web (QuantumNous#8105)
- 1695171 chore(deps): bump tailwind-merge from 3.6.0 to 3.7.0 in /web (QuantumNous#8106)
- 7fa815e chore(deps-dev): bump fast-uri from 3.1.7 to 3.1.9 in /electron (QuantumNous#8007)
- ee0f0ac chore(deps-dev): bump electron from 41.10.6 to 42.11.16 in /electron (QuantumNous#8008)
- 837b814 chore(deps): bump undici in /electron (QuantumNous#8006)
- 3150dfe chore(deps): bump github.com/go-jose/go-jose/v4 from 4.1.4 to 4.1.6 (QuantumNous#8112)
- a3851c2 fix: save Turnstile keys before enabling (QuantumNous#7960)
- 4193734 fix(logger): keep gin access and recovery logs on the current log file after rotation (QuantumNous#8098)
- f366017 Merge commit from fork
- 829f082 fix: unmount authenticated layout on sign-out to stop credential-less refetches (QuantumNous#8110)
- 9eda50a Merge commit from fork
- a2defd2 Merge commit from fork
- e449cc7 feat: sample immediate task successes in model performance metrics (QuantumNous#8067)
- fcc241c fix: start affinity fallback at the highest channel priority (QuantumNous#8078)
- b08ee86 fix(cloudflare): preserve embedding response data (QuantumNous#8041)
- 26c488c fix(relay): allow Azure channels to opt in to Responses WebSocket (QuantumNous#8047) (QuantumNous#8075)
- 55515db fix(relay): terminate streams on exact bare done markers (QuantumNous#8074)
- 49271d2 fix(aws): preserve safeguards in Bedrock Invoke requests (QuantumNous#8071)
- 5478811 fix: count completed non-stream relays after context cancellation (QuantumNous#7844)
- ad56112 fix(relay): apply GPT-6 chat parameter rules to gpt-6.1-sol and gpt-6.1-terra (QuantumNous#8064)
- 01da3a5 perf(relay): stop recompiling param override regexes on every request (QuantumNous#8061)
- 34003e9 test: stabilize channel affinity cache keys (QuantumNous#8009)
- 0165fef fix(relaykit): preserve Gemini text alongside tool calls (QuantumNous#7998)
- 4d962e4 fix(relaykit): preserve tool argument numbers in Claude responses (QuantumNous#7996)
- f1569d1 fix(pricing): classify dynamic per-request billing correctly (QuantumNous#8010)
- bc795cc fix:修复stop为非字符串和[]string的协议转换问题 (QuantumNous#7935)
- 9823ebc fix(billing): bill cache_creation_input_tokens reported in prompt_tokens_details (QuantumNous#7909)
- e835b1b chore(deps): bump axios from 1.18.1 to 1.20.0 in /web (QuantumNous#7835)
- 5c8032d chore(deps): bump react-i18next from 17.0.10 to 17.1.0 in /web (QuantumNous#7981)
- 0b667ca chore(deps): bump i18next from 26.3.6 to 26.5.3 in /web (QuantumNous#7979)
- 4105bd0 chore(deps): bump input-otp from 1.4.2 to 1.5.0 in /web (QuantumNous#7980)
- b6b85ca chore(deps): bump react-resizable-panels from 4.12.2 to 4.14.6 in /web (QuantumNous#7982)
- 1dafb19 fix(gemini): preserve top-level imageConfig in chat conversion
- 0034b24 fix(task): wait up to 72 hours before timing out tasks
- a404460 chore(web): upgrade Bun to 1.4.4 and use bun check
- 33c61a2 fix: prevent stale values when switching edit drawer records (QuantumNous#7989)
- 30748c6 fix(logging): 隐藏访问日志中的查询凭据 (QuantumNous#7972)
- 7fb6e57 fix(channels): preserve advanced custom body passthrough settings (QuantumNous#7971)
- e9d4d63 feat(billing): bill OpenAI 12-hour prompt cache writes at their own price (QuantumNous#7965)
- d0b840e fix(relay): keep the client's JSON Schema property order
- d8e6561 feat(web): copy model names from usage log details
- 8802113 feat(task): let ordinary channels compete on shared plugin endpoints
- eb169e7 feat(pricing): adjust synced upstream prices by the site exchange rate
- e2321a5 chore(web): sort locale keys
- db80ac8 fix(task): let task plugins validate their own requests
- dbe97be feat(task): pass client request headers to task plugin drivers
- 556517f feat(task): accept multipart bodies on native plugin routes
- 94cc3ff fix(billing): bill Claude cache writes that arrive without a 5m/1h split
- 7e65967 fix(relay): stop cutting off slow clients during large stream events
- 0c2af97 fix(relay): finish delivered Responses streams without false disconnect errors (QuantumNous#7956)
- 7d8b912 fix: upgrade Go to 1.26.10 for CVE-2026-111943 (QuantumNous#7942)
- 4d36f2c chore(deps-dev): bump vitest from 4.1.10 to 5.0.4 in /web (QuantumNous#7838)
- eea05e0 chore(deps): bump github.com/klauspost/compress from 1.18.3 to 1.18.7 (QuantumNous#7931)

Local tests not run (CI-only).
timwenx pushed a commit to timwenx/new-api that referenced this pull request Nov 18, 2026
* fix(logging): 隐藏访问日志中的查询凭据

* fix(logging): redact query credentials in access logs

---------

Co-authored-by: seefs001 <[email protected]>
xiaolanawaqaq pushed a commit to xiaolanawaqaq/new-apiaaa that referenced this pull request Nov 26, 2026
* fix(logging): 隐藏访问日志中的查询凭据

* fix(logging): redact query credentials in access logs

---------

Co-authored-by: seefs001 <[email protected]>
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.

访问日志未对 URL 查询凭据脱敏

2 participants