fix: improve error response security and add sanitization utility #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses error message information disclosure identified during code review. It introduces a centralized error sanitization utility and updates the global error handler.
Key Changes
server/utils/errorResponse.tsserver/index.tsserver/routes/search.tsserver/routes/overlayTest.tsImplementation Details
1. Error Sanitization Utility (
errorResponse.ts)Uses a whitelist approach for maximum safety:
Sensitive patterns that are always masked:
at Function.xyz (/path/file.ts:123))/home/,/var/,C:\)ENOENT,EACCES,ECONNREFUSED)password,secret,token,apikey)file.ts:123,node_modules)sql,query,table,column)localhost,127.0.0.1,192.168.*,10.*)2. Global Error Handler Updates
Before:
After:
3. Route-Level Error Handling
Replaced manual error logging with
createErrorResponse():Security Analysis
/var/lib/agregarr/...visible192.168.1.xvisibleBehavior by Environment
NODE_ENV!= 'production''production''staging'Codex Review Findings (Addressed)
loggerimport in search.tserr.errors?.map()may throwArray.isArray()checkTest Plan
Example Error Response
Development (
NODE_ENV=development):{ "error": "Failed to search Plex", "message": "ECONNREFUSED: Connection refused at 192.168.1.178:32400" }Production (
NODE_ENV=production):{ "error": "Failed to search Plex" }🤖 Generated with Claude Code