fix(server): exclude stack trace from REST error responses#2501
Conversation
Remove stack trace from error messages returned to clients to avoid leaking internal implementation details. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @ymc9's task —— View job PR Review: Remove Stack Trace from REST Error Responses ✅Todo List:
Review SummaryThis is a excellent security-focused change that removes stack trace information from REST API error responses. The change is simple, targeted, and addresses a real security concern. ✅ Security BenefitsHIGH PRIORITY FIX - This change addresses a significant security vulnerability:
📋 Code Quality AssessmentLocation: Change Analysis: // Before
return this.makeError('unknownError', err instanceof Error ? `${err.message}\n${err.stack}` : 'Unknown error');
// After
return this.makeError('unknownError', err instanceof Error ? `${err.message}` : 'Unknown error');✅ Positive Aspects
|
📝 WalkthroughWalkthroughRemoved stack traces from HTTP error response detail in RestApiHandler; switched debug logging to use Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
Claude finished @ymc9's task —— View job PR Code Review ✅Todo List:
Review SummaryThis is an excellent security improvement that removes stack trace information from REST API error responses. The change is minimal, focused, and addresses a real security vulnerability. ✅ Security Analysis - EXCELLENTCritical Security Fix:
Changed code at // Before: Leaked stack traces
return this.makeError('unknownError', err instanceof Error ? `${err.message}\n${err.stack}` : 'Unknown error');
// After: Only returns safe error message
return this.makeError('unknownError', err instanceof Error ? `${err.message}` : 'Unknown error');✅ Code Quality Assessment - VERY GOODStrengths:
Note: Internal logging at line 515 still captures full error details including stack traces for debugging: log(this.options.log, 'debug', () => `...${err instanceof Error ? '\n' + err.stack : ''}`);✅ Potential Issues Analysis - NONE IDENTIFIEDEdge cases considered:
✅ Performance Considerations - NO IMPACT
✅ Test Coverage AssessmentCurrent test plan is adequate but could be enhanced: ✅ Existing coverage:
💡 Recommended additional tests:
📝 Overall AssessmentScore: 9.5/10 This is a production-ready security fix that should be merged immediately. The change is:
🎯 Recommendation: ✅ APPROVE AND MERGEThis PR represents security best practices and should be deployed to production as soon as possible to prevent potential information disclosure. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/server/src/api/rest/index.ts (1)
510-518: LGTM! Security improvement correctly removes stack traces from API responses.This change properly addresses the security concern by excluding stack traces from the error response detail while preserving them in debug logs for troubleshooting purposes.
♻️ Optional: Simplify redundant template literal
The template literal around
err.messageis redundant since it's already a string:private handleGenericError(err: unknown): Response | PromiseLike<Response> { - const resp = this.makeError('unknownError', err instanceof Error ? `${err.message}` : 'Unknown error'); + const resp = this.makeError('unknownError', err instanceof Error ? err.message : 'Unknown error');🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/server/src/api/rest/index.ts` around lines 510 - 518, The handleGenericError method constructs the error detail using a redundant template literal; update the ternary expression in handleGenericError so it passes err.message directly (or 'Unknown error') to makeError instead of using `${err.message}`, keeping the same behavior; reference makeError, handleGenericError, log, and safeJSONStringify to locate the change and ensure debug logging still includes err.stack but responses do not.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/server/src/api/rest/index.ts`:
- Around line 510-518: The handleGenericError method constructs the error detail
using a redundant template literal; update the ternary expression in
handleGenericError so it passes err.message directly (or 'Unknown error') to
makeError instead of using `${err.message}`, keeping the same behavior;
reference makeError, handleGenericError, log, and safeJSONStringify to locate
the change and ensure debug logging still includes err.stack but responses do
not.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 91580b3c-d21a-4365-818f-2e00a3507004
📒 Files selected for processing (1)
packages/server/src/api/rest/index.ts
Summary
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit