🔒 Sanitize internal system errors in API responses#89
Conversation
Co-authored-by: mbayue <70324722+mbayue@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant Client
participant API as API Route
participant ErrorUtil as toErrorPayload
participant System as Internal System (DB/IO)
Client->>API: HTTP request
API->>System: Internal operation (e.g., db.query)
System-->>API: Error (status=500, message with sensitive info)
alt status >= 500 (NEW: Sanitized)
API->>ErrorUtil: toErrorPayload(error)
Note over ErrorUtil: Replaces raw message with<br/>'Internal Server Error'
ErrorUtil-->>API: { error: 'Internal Server Error', code, status, ... }
else status < 500 (Unchanged: preserved message)
API->>ErrorUtil: toErrorPayload(error)
Note over ErrorUtil: Keeps original error.message
ErrorUtil-->>API: { error: err.message, ... }
end
API-->>Client: HTTP response with sanitized payload
🎯 What: Modified
⚠️ Risk: When system errors occur (e.g. database disconnects, file IO errors), their raw
toErrorPayloadinserver/utils/errors.tsto sanitize messages for 500-level HTTP errors..messagestring could contain sensitive details such as file paths, connection strings, IPs, or passwords. Exposing this information directly in API responses results in an Information Disclosure vulnerability.🛡️ Solution: Implemented logic to check if
err.status >= 500. If so, the raw error message is suppressed and replaced with a generic 'Internal Server Error' string in the response payload. 400-level status codes retain their specific messages as they are generally safe validation/client errors.PR created automatically by Jules for task 3638637770407784940 started by @mbayue
Summary by cubic
Sanitizes 500-level API error messages by returning "Internal Server Error" instead of the raw message to prevent sensitive info leaks. Leaves 4xx messages unchanged and adds tests to cover both paths.
Written for commit fe9c036. Summary will update on new commits.