Skip to content

feat(api): sanitize HTTP API error responses - #147

Open
halibobo1205 wants to merge 1 commit into
developfrom
feature/http_error_optimization
Open

feat(api): sanitize HTTP API error responses#147
halibobo1205 wants to merge 1 commit into
developfrom
feature/http_error_optimization

Conversation

@halibobo1205

@halibobo1205 halibobo1205 commented Sep 1, 2026

Copy link
Copy Markdown
Owner

User description

What does this PR do?

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

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:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

Client-visible changes:

  • all processError-based error bodies lose the "class : " 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.


CodeAnt-AI Description

Standardize HTTP error responses and prevent internal details from reaching clients

What Changed

  • HTTP failures now return consistent {"Error": ...} JSON instead of exception class names, raw internal messages, or bare-text responses
  • Unrecognized failures use internal server error; only approved validation and maintenance messages remain visible
  • Rate-limited requests return {"Error":"lack of computing resources"} consistently
  • Invalid address failures use a fixed INVALID address message, and address validation no longer exposes library error details
  • Added coverage for sanitized errors, approved messages, rate-limit responses, and Solidity transaction endpoints

Impact

✅ 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:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

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:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

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.

@codeant-ai

codeant-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Incremental review completed e09fc42 Sep 01, 2026 · 05:30 05:30
✅ Reviewed your PR 159bdaf Sep 01, 2026 · 03:20 03:25

@codeant-ai

codeant-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-01T06:11:32.631950Z 395466a New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Sep 1, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread framework/src/main/java/org/tron/core/services/http/RateLimiterServlet.java Outdated
@halibobo1205
halibobo1205 force-pushed the feature/http_error_optimization branch from 159bdaf to e09fc42 Compare September 1, 2026 05:30
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.
@halibobo1205
halibobo1205 force-pushed the feature/http_error_optimization branch from e09fc42 to 395466a Compare September 1, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant