Skip to content

fix: sanitize API error responses to prevent internal details leaking#146

Merged
poyrazK merged 3 commits intomainfrom
fix/api-raw-error-messages
May 7, 2026
Merged

fix: sanitize API error responses to prevent internal details leaking#146
poyrazK merged 3 commits intomainfrom
fix/api-raw-error-messages

Conversation

@poyrazK
Copy link
Copy Markdown
Owner

@poyrazK poyrazK commented May 7, 2026

Summary

  • Replace all raw http.Error(w, err.Error(), ...) calls with a new writeJSONError helper that:

    • Logs the full internal error internally with h.logger.Error
    • Returns only a safe public message as JSON {"error": "..."} to the client
    • Never exposes err.Error() to clients
  • Affected handlers: ListAuditLogs, CreateZone, ListZones, ListRecordsForZone, CreateRecord, DeleteZone, DeleteRecord

Fixes #86.

Test plan

  • go build ./... — clean build
  • go test ./... -timeout 60s — all tests pass

Replace all raw http.Error(w, err.Error(), ...) calls with a new
writeJSONError helper that:
- Logs the full internal error internally
- Returns only a safe public message to the client as JSON

Affected handlers: ListAuditLogs, CreateZone, ListZones,
ListRecordsForZone, CreateRecord, DeleteZone, DeleteRecord.

Fixes #86.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Warning

Rate limit exceeded

@poyrazK has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 11 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3420a334-3434-49e2-90b0-b026dc4b5ce6

📥 Commits

Reviewing files that changed from the base of the PR and between 21acd90 and 7216f25.

📒 Files selected for processing (1)
  • internal/adapters/api/handler.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/api-raw-error-messages

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

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

poyrazK added 2 commits May 7, 2026 19:43
The errcheck linter flagged that json.NewEncoder(w).Encode(resp)
return value was not checked in writeJSONError. This could silently
swallow encoding errors. Now logs the encoding failure internally.

Fixes: #86
Copy link
Copy Markdown
Owner Author

@poyrazK poyrazK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to merge

@poyrazK poyrazK merged commit c8372fe into main May 7, 2026
7 checks passed
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.

API handlers return raw error messages to clients

1 participant