feat(api): sanitize HTTP API error responses - #147
Conversation
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 159bdaf4b0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
159bdaf to
e09fc42
Compare
Standard HTTP error paths used to expose internal details to clients:
Util.processError prefixed every message with the Java exception class
name, several servlets printed raw Throwable.getMessage() directly, and
the two solidity query endpoints returned bare-text error bodies.
Centralize the client-facing text decision in Util.processError:
* keep the raw non-blank message only for the exact runtime types
JsonFormat.ParseException, ContractValidateException and
MaintenanceUnavailableException; a null, empty or whitespace-only
message falls back to "internal server error"
* keep two fixed messages only on exact type + exact text match:
IllegalAccessException("lack of computing resources") and
IllegalArgumentException(EVENTS_DEPRECATED_MSG)
* return {"Error":"internal server error"} for every other exception,
with no exception class name
Client-visible changes:
* all processError-based error bodies lose the "class <FQCN> : "
prefix; unclassified raw messages become "internal server error"
* the rate-limit rejection body becomes
{"Error":"lack of computing resources"} on every endpoint extending
RateLimiterServlet, including /jsonrpc (no JSON-RPC code is modified)
* gettransactionbyid / gettransactioninfobyid on solidity return
standard {"Error":...} JSON instead of bare text
* validateaddress, getBrokerage and getReward replace leaked library
messages in their failure branches with existing fixed texts; the
"INVALID address" body is now written via processError and loses
the space after the colon
* getblock keeps its exact error bodies (refactor only)
HTTP status codes, success responses, request validation rules and
gRPC behavior are unchanged.
e09fc42 to
395466a
Compare
User description
What does this PR do?
Centralize the client-facing text decision in Util.processError:
Why are these changes required?
Standard HTTP error paths used to expose internal details to clients: Util.processError prefixed every message with the Java exception class name, several servlets printed raw Throwable.getMessage() directly, and the two solidity query endpoints returned bare-text error bodies.
This PR has been tested by:
Follow up
Extra details
Client-visible changes:
HTTP status codes, success responses, request validation rules and gRPC behavior are unchanged.
CodeAnt-AI Description
Standardize HTTP error responses and prevent internal details from reaching clients
What Changed
{"Error": ...}JSON instead of exception class names, raw internal messages, or bare-text responsesinternal server error; only approved validation and maintenance messages remain visible{"Error":"lack of computing resources"}consistentlyINVALID addressmessage, and address validation no longer exposes library error detailsImpact
✅ No leaked exception details in HTTP error responses✅ Consistent JSON errors across API and Solidity endpoints✅ Clearer invalid-address and rate-limit messages💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.