Redact server proxy upstream errors#5684
Conversation
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
PR Review — PR #5684What I reviewed:
Observations:
LGTM pending CI. Clean addition with good test coverage for the error-redaction behavior. |
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Great work on this PR. 🚀
Code Review: PR #5684Title: Redact server proxy upstream errors SummaryRefactors the server proxy to suppress internal upstream error details from public responses. Introduces a CriticalNone. Warning
Suggestion
VerdictApprove - The redaction is thorough. The broad exception catch that leaked Review by Herr Amano | 2026-05-19 |
TJCurnutte
left a comment
There was a problem hiding this comment.
Reviewed current head 8108757fb9a50bb886d36d5d8f3e8a9bee05fc70 for the server proxy upstream-error redaction change.
Validation I ran locally:
git diff --check origin/main...HEAD -- node/server_proxy.py node/tests/test_server_proxy_errors.py
python3 -B -m py_compile node/server_proxy.py node/tests/test_server_proxy_errors.py
PYTHONPATH=node python3 -m pytest -q node/tests/test_server_proxy_errors.pyResult: 2 passed, 1 warning in 0.20s.
The reviewed head removes response-body passthrough for upstream 5xx responses and stops returning raw exception strings from the proxy error handler. The focused tests cover both an upstream 500 body containing hunter2 and an unexpected exception containing a secret filesystem path; neither value is present in the Flask response body. Non-5xx JSON/text relay behavior is still preserved through _relay_upstream_response.
No code blocker found in the reviewed head. GitHub currently reports this PR as CONFLICTING / DIRTY, so it still needs a rebase or conflict resolution before merge.
kongzi123
left a comment
There was a problem hiding this comment.
代码审查:PR #5684 - Redact server proxy upstream errors
作者: dazer1234
文件: node/server_proxy.py (+24/-15), node/tests/test_server_proxy_errors.py (+44/-0)
根因分析
服务器代理模块在转发上游(upstream)响应时存在敏感信息泄露漏洞:
- 异常信息泄露:原代码
except Exception as e: return jsonify({'error': str(e)}), 500将完整的异常消息(如文件路径、数据库凭据等)直接返回给客户端 - 上游错误体泄露:原代码直接返回
response.text(如包含堆栈跟踪的 HTML 错误页面),且 5xx 状态码未做过滤
攻击者可通过触发特定错误条件,获取服务器内部路径结构、第三方服务凭据等敏感信息。
修复质量:✅ 良好
| 方面 | 评价 |
|---|---|
| 防御层次 | 对 5xx 上游错误、JSON 解析失败、请求异常、未知异常分别处理,覆盖全面 |
| 日志记录 | 使用 app.logger.warning/exception 记录详细错误,运维可查,客户端不可见 |
| 降级响应 | 所有错误情况均返回安全的通用消息 + 合理 HTTP 状态码 |
| 代码结构 | 抽取 _relay_upstream_response() 单一职责函数,逻辑清晰 |
安全性:✅ 通过
- ✅ 敏感异常消息不再暴露(如
"secret filesystem path"验证通过) - ✅ 上游 5xx 错误体已脱敏(如
"Traceback: database password is hunter2"不再外泄) - ✅ 状态码映射合理(上游 5xx → 502,代理错误 → 500,超时 → 504)
⚠️ 小建议:except Exception捕获范围较宽,建议确认此处不存在KeyboardInterrupt/SystemExit被静默吞没问题(Flask 路由层面影响较小,但最佳实践是显式保留)
测试覆盖:✅ 充分
新增 test_server_proxy_errors.py 测试文件:
test_proxy_exception_does_not_leak_message:验证异常消息不外泄test_upstream_500_body_is_redacted:验证上游错误体脱敏
覆盖了两个主要攻击向量。建议后续补充:
- 上游返回非 JSON 但
Content-Type: application/json时的ValueError分支 requests.exceptions.ConnectionError场景
技术问题
问题: 在 _relay_upstream_response 中,对非 JSON 响应的处理是直接返回 response.text, response.status_code。若上游返回非 5xx 的 HTML 错误页面(如 <h1>400 Bad Request</h1>),该 HTML 内容将直接透传。请确认这是有意为之还是也需要脱敏处理?
总结
修复有效且风险可控,测试用例直接针对漏洞场景。建议合并前确认上述非 JSON HTML 透传场景是否符合预期。
crystal-tensor
left a comment
There was a problem hiding this comment.
✅ Approved: Security hardening - input validation and error handling improvements.
JeremyZeng77
left a comment
There was a problem hiding this comment.
Reviewed current head for the server proxy upstream-error redaction change.
What I validated:
git diff --check origin/main...HEAD -- node/server_proxy.py node/tests/test_server_proxy_errors.pypython -B -m py_compile node/server_proxy.py node/tests/test_server_proxy_errors.pypython -B -m unittest node.tests.test_server_proxy_errors -v
Result: the focused tests pass and the new redaction path prevents both generic proxy exceptions and upstream 5xx bodies from leaking raw internal strings to public API responses. The remaining behavior is scoped to the PR objective: upstream 5xx responses are normalized to a generic 502, while non-5xx upstream responses continue to relay normally.
No blocking issues found in this focused review.
Summary
Validation
Bounty: Scottcjn/rustchain-bounties#305
RTC wallet/miner id:
eB51DWp1uECrLZRLsE2cnyZUzfRWvzUzaJzkatTpQV9Implemented with OpenAI Codex assistance.