Repository navigation
Description
Summary
Some HTTP APIs return Java exception class names and unaudited Throwable.getMessage() values to clients when handling exceptions, for example:
{
"Error": "class java.lang.NullPointerException : null"
}This proposal standardizes client-facing error messages from standard HTTP Servlets in phase 1:
- Existing messages are temporarily preserved for exceptions explicitly covered for compatibility.
- All other exceptions return the stable message
internal server error. - Java exception class prefixes and raw exception messages that are not explicitly allowed are no longer returned to clients.
Phase 1 changes only the content and format of failure responses. Successful responses, request rules, HTTP status codes, and gRPC behavior remain unchanged.
The shared HTTP rate-limit response is also sanitized for JSON-RPC endpoints, returning {"Error":"lack of computing resources"} without the Java exception class prefix. Other JSON-RPC behavior remains unchanged.
Problem
Motivation
Returning runtime exception information directly to clients has the following problems:
- It provides little value to clients in diagnosing or handling request failures.
- Exception messages may change with JDK or dependency versions and are unsuitable as a stable, long-term API contract.
Current State
Before this change, standard HTTP error-response paths behave inconsistently:
Util.processErrorreturns a concatenation of the Java exception class name and raw message.- Some Servlets bypass
Util.processErrorand directly return exception class names orThrowable.getMessage()values. - Two Solidity query endpoints return plain-text error bodies instead of standard JSON.
Limitations and Risks
- Clients that depend on Java exception class names, raw exception messages, or plain-text error bodies will observe compatibility changes.
- To limit the compatibility impact of phase 1, non-blank raw messages from three exact exception types are temporarily preserved.
Proposed Solution
Proposed Design
1. Standardize HTTP error-response paths
The standard Servlet JSON and text error-response paths governed by phase 1 are routed through Util.processError, which centrally determines the final client-facing message.
Endpoints with a specialized response format, such as validateaddress, retain that format and replace dynamic exception messages locally.
2. Preserve compatibility messages for three exact exception types
For compatibility with existing clients, exception classification preserves raw messages only for the following exact runtime types:
JsonFormat.ParseExceptionContractValidateExceptionMaintenanceUnavailableException
These three cases are legacy residuals temporarily retained for compatibility with existing behavior. Subclasses and nested causes are not matched.
3. Preserve audited fixed and existing response texts
Existing client-facing validation and state messages are preserved through their audited paths:
- The rate limiter directly returns the fixed text
lack of computing resources, without constructing an exception for formatting. - The Scan Events deprecation text is preserved only when both the exact
IllegalArgumentExceptiontype andEVENTS_DEPRECATED_MSGmatch. - Existing GetBlock validation messages and fixed address-validation responses are retained.
These fixed or pre-existing response texts do not broaden the exception-type compatibility rules above.
4. Fail closed for all other exceptions
Except for the explicitly allowed compatibility branches above, exceptions must not expose Java exception class names or raw messages to clients. This includes, but is not limited to:
NullPointerException- Array or collection bounds exceptions
- Ordinary
IllegalArgumentException - Other unmapped runtime or internal exceptions
They return:
{
"Error": "internal server error"
}Key Changes
- The change is limited to the HTTP Servlet layer in the
frameworkmodule. - Standard JSON and text error-response paths governed by phase 1 are routed through
Util.processError. - Java exception class prefixes are removed from standard error responses.
- Exception compatibility rules use exact runtime types and, for the events-deprecation exception, an exact message constant.
- Exceptions that are not explicitly allowed return
internal server error. - The two Solidity query endpoints change their error bodies from plain text to standard
{"Error":"..."}JSON. - The shared rate-limit response is sanitized for all affected HTTP endpoints, including JSON-RPC endpoints.
Impact
- Security
- Standard generic and unclassified error-response paths no longer return Java exception class names or uncontrolled raw messages.
- The three compatibility branches that retain raw messages remain known residuals.
- Stability
- Unknown exceptions use a stable message instead of depending on JDK or library exception messages.
- Performance
- The change adds only lightweight exception-type and fixed-message comparisons.
- Normal request paths are unaffected.
- Developer Experience
- Standard HTTP error-response behavior is centralized in
Util.processError.
- Standard HTTP error-response behavior is centralized in
Compatibility
| Item | Result |
|---|---|
| Breaking Change | Yes, limited to some HTTP failure responses. Some error messages will change, including the shared rate-limit response used by JSON-RPC endpoints. The two Solidity query endpoints will return JSON instead of plain-text error bodies. These changes must be included in the release notes. |
| Default Behavior Change | Yes. Only failure responses change; successful responses remain unchanged. |
| Migration Required | Conditional. Clients that rely only on successful responses or documented response fields require no migration. Clients that depend on Java exception class names, raw exception messages, or plain-text Solidity error bodies must be updated. |
Affected clients should:
- Read the
Errorfield from the standard JSON response. - Stop depending on Java exception class names.
- Stop treating JDK or third-party exception messages as a stable API contract.
- Handle unknown server errors as
internal server error.
The following behavior remains unchanged:
- Existing HTTP status codes
- Status codes and response content for successful requests
- Request parameters and validation rules
- gRPC API behavior
- JSON-RPC behavior, except for the shared HTTP rate-limit response described above
Acceptance Criteria
- Standard Servlet error-response paths governed by phase 1 generate responses through
Util.processError; endpoints with specialized response formats retain their formats and use audited messages. - These paths no longer concatenate Java exception class names or directly return arbitrary
Throwable.getMessage()values. - On the exception-classification path, only the exact runtime types
JsonFormat.ParseException,ContractValidateException, andMaintenanceUnavailableExceptionmay preserve non-blank raw messages. - For those three types, a null, empty, or whitespace-only message results in
internal server error. - Subclasses and nested causes do not inherit compatibility exemptions.
- The events-deprecation message is preserved only when both the exact exception type and exact message constant match.
- Rate-limit rejections return
{"Error":"lack of computing resources"}, including on JSON-RPC endpoints. - Existing audited GetBlock validation messages and fixed address-validation responses are preserved.
- All other exceptions return:
{
"Error": "internal server error"
}- If writing the error response to the client fails, at most one additional
debuglog entry is recorded. - The two Solidity query endpoints return standard JSON error responses.
- HTTP status codes, successful responses, request rules, and gRPC behavior remain unchanged.
- JSON-RPC behavior remains unchanged except for the shared HTTP rate-limit response described above.
Follow-up
Future phases will:
- Distinguish client parameter errors from internal server errors based on the specific HTTP input source.
- Avoid treating JDK or third-party exception messages as part of the long-term API contract.
Additional Notes
- Do you have ideas regarding implementation? Yes. Route the in-scope standard Servlet error paths through
Util.processError, classify exceptions by exact runtime type, and preserve audited fixed or existing response texts at their designated call sites. - Are you willing to implement this feature? Yes.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
halibobo1205 commentedon Sep 1, 2026
Baseline: where today's error responses actually come from
Before discussing the design, here is a factual inventory of how error bodies are produced on
developtoday.The main channel.
Util.processError(Exception, ...)has 176 call sites across 121 servlet files in theframework/.../services/httppackage, all in servlet request-handling paths: 175 sit directly indoGet/doPost, and one sits inGetBlockServlet's privatehandle(...), which is shared by both. Of these, 172 are incatch (Exception e)blocks, while the remaining 4 are thecatch (IllegalArgumentException e)events-deprecation gates in the twoScanShieldedTRC20NotesBy*Servletclasses—the only sites that also set HTTP 400. All of them funnel intoprintErrorMsg, which returns:{"Error": "class <FQCN> : <raw Throwable.getMessage()>"}In-scope standard error paths that bypass
processErrortoday:Util.printErrorMsg(e)inline instead ofprocessError:GetBurnTrxServlet,GetNodeInfoServlet,GetPendingSizeServlet, andGetRewardServlethave one each, whileGetTransactionInfoByBlockNumServlethas two. They produce the same class-name + raw-message body, but bypass the shared writer.GetBlockServletbuilds its own{"Error": e.getMessage()}for theIllegalArgumentExceptions thrown byWallet.getBlock, with fixed texts such asnum must be non-positive number.andid must be legal block hash.GetBrokerageServletandGetRewardServlethand-concatenate{"Error": "INVALID address, <raw e.getMessage()>"}. The raw suffix is not JSON-escaped, so a message containing a double quote produces an invalid JSON body.ValidateAddressServletcopiese.getMessage()into themessagefield of its{result, message}body on the exception branch, exposing Bouncy Castle, Base64, or JDK-generated text.RateLimiterServletwritesprintErrorMsg(new IllegalAccessException("lack of computing resources")), so the rejection body carries theclass java.lang.IllegalAccessException :prefix on every rate-limited endpoint.solidity/GetTransactionByIdSolidityServletandGetTransactionInfoByIdSolidityServletprint baree.getMessage()text lines. Because the Content-Type is set centrally toapplication/json; charset=utf-8, these error bodies are not valid JSON, and a null message prints the literal linenull.This list covers the standard JSON / text error paths in scope for phase 1. Other exception outlets exist and are registered separately.
ValidateAddressServlet's POST parse failure logs and writes no response body.RateLimiterServlet's generic catch logs without synthesizing an error body, so the response may be empty or partially written. The trigger / estimate endpoints place exception text inside their structured businessresult.messageenvelope (see the residuals note below).What leaks through in practice: JDK 17 “helpful NPE” messages exposing code-level variable, expression, and method names; protobuf
InvalidProtocolBufferExceptiondetails; Bouncy CastleDecoderExceptiontexts; andNumberFormatExceptioninternals. These are not reliable or stable client diagnostics and can change across JDK or dependency upgrades.For historical context, the
NullPointerExceptionshown in the issue summary was fixed at the parsing layer by #6828, which shipped in v4.8.2. This proposal addresses the exposure pattern itself rather than one instance of it.waynercheung commentedon Sep 2, 2026
@halibobo1205 Thanks for documenting the phase-1 boundary so clearly. I found one adjacent container-level case and would like your view on whether it belongs here as a later phase or in a separate linked issue.
Phase 1 standardizes responses for exceptions caught by the HTTP servlets. Uncaught servlet/container failures take a different path:
HttpService.OversizedRequestErrorHandlerhandles the 413 case added by #6843, but delegates other failures to Jetty's defaultErrorHandler.I checked
jetty-server9.4.58.setShowStacks(false)protects only the HTML representation. The JSON representation still emitsThrowable.toString()values from the cause chain, while the plain-text representation prints the cause stack. Disabling showStacks alone is therefore not sufficient.This is relevant to #6941 because its JSON-RPC servlet will stop jsonrpc4j from swallowing fatal Errors. #6941 will handle that path locally: before rethrowing a fatal Error, the servlet will make a best-effort attempt to commit a zero-length HTTP 500 response. Depending on transport state, the client may receive the empty 500 response or observe a closed connection, but Jetty should not render the Throwable when the response can be committed. Normal JSON-RPC errors remain HTTP 200 JSON-RPC responses.
The remaining global case affects the seven
HttpServiceimplementations and is broader than JSON-RPC. A possible follow-up would sanitize exception-backed/container 5xx responses while preserving the existing 413 handling. I would leave ordinary 404/405 behavior unchanged until its compatibility impact is evaluated. The fix should be covered by embedded-Jetty tests for HTML, JSON, and plain-text responses.Would you prefer to track this as phase 2 of #6936, or as a separate linked hardening issue? My preference is a separate issue because it covers a different layer, affects all HTTP services, and requires a different compatibility and test scope. Either choice is fine; #6941 will remain limited to JSON-RPC behavior.
halibobo1205 commentedon Sep 2, 2026
@waynercheung I agree this belongs outside this issue because it concerns the shared container error-rendering layer rather than servlet-level exception handling. Any eventual fix should preserve #6843’s 413 behavior and avoid changing ordinary 404/405 responses unless separately evaluated.
halibobo1205 commentedon Sep 4, 2026
Design notes: why exact runtime type matching and no cause unwrapping
The proposal classifies only the top-level exception by exact runtime class: no subtype matching
and no inspection of the cause chain. A separate package-private
processError(String, ...)overload is used at four audited call sites for the rate-limit text, the existing GetBlock
validation texts, and the two
INVALID addressresponses.ValidateAddressServletretains its ownfixed
Invalid addressbody. These paths do not participate in exception classification. Theevents-deprecation text remains on the exception path and is preserved only when both the exact
exception type and the audited message constant match. The reasoning, grounded in what
developdoes today:
Why not unwrap causes. On
develop, all 176processErrorcall sites pass an exceptioncaught by a handler-local catch directly to
processError: 172 usecatch (Exception), and fourare the events-deprecation
catch (IllegalArgumentException)sites. Some callees do wraplower-level exceptions, but the existing HTTP formatter serializes only the top-level exception
class and message; it never unwraps or serializes the cause. Unwrapping would therefore expose
information that is not part of the current response contract, and would broaden the audited
surface from the caught exception to arbitrary nested causes.
CreateCommonTransactionServletis the only reflective path in this package whose reflectionexception can propagate into
processError. AnInvocationTargetExceptionreaches the formatteras the wrapper itself; its target exception is not serialized. Exact top-level classification
therefore fails closed there without introducing new cause exposure.
Why not match subclasses.
ContractValidateExceptionhas two declared subclasses in the sourcestracked on
develop, and neither reaches the classification path under the defaultdevelopchain state: one is translated into a structured
Returnby the HTTP-facing broadcast pathsbefore
processErroris involved, and the other comes from an actuator whose validation failsearlier, in that state, with a plain
ContractValidateException. If a subtype does reach a handler, exactmatching would deliberately fail closed rather than let it inherit the residual.
JsonFormat.ParseExceptionand
MaintenanceUnavailableExceptionhave no declared subclasses in the tracked sources.Why these three compatibility residuals.
JsonFormat.ParseExceptionpreserves request-derived parser diagnostics. In particular, thefix(jsonrpc): harden RPC/HTTP parameter validation #6828 fix released in v4.8.2 reports
invalid address for field ...through this path.ContractValidateExceptionpreserves existing validation messages used by clients and tooling.Some construction sites may themselves carry lower-level text, so this remains an explicit
compatibility residual rather than a security endorsement.
MaintenanceUnavailableExceptionrepresents the existing maintenance-period business state.On the classification path, a null, empty, or whitespace-only residual message would still fail
closed to
internal server error. The events-deprecation text would be preserved only for theexact
IllegalArgumentExceptiontype carrying the exact audited constant, so no other exceptiontype can borrow that message.
Why status codes remain unchanged in phase 1. TronWeb's default
HttpProvideruses Axioswithout overriding
validateStatus, and returnsresponse.dataonly on the fulfilled path. Axiosrejects non-2xx responses by default, so introducing new 4xx/5xx status codes for errors that
currently return 2xx would also change TronWeb calls from resolving with the response body to
rejecting with an Axios error; for an HTTP error response, the body is instead available at
error.response.data. That is a separateclient-compatibility change, so phase 1 limits itself to response-message sanitization and leaves
status-code semantics to a follow-up.
feat(api): sanitize HTTP API error responses
halibobo1205 commentedon Sep 8, 2026
Compatibility Summary
Compatibility summary for the phase-1 change.
<FQCN>is the fully-qualified Java exceptionclass name and
<message>is the raw exception text.{"Error":"class <FQCN> : <message>"}{"Error":"<message>"}JsonFormat.ParseException,ContractValidateException, andMaintenanceUnavailableException. Existing diagnostic text is retained; the class prefix is removed.null, an empty string, or whitespace{"Error":"internal server error"}{"Error":"class <FQCN> : <message>"}{"Error":"internal server error"}{"Error":"class java.lang.IllegalArgumentException : <deprecation message>"}{"Error":"<deprecation message>"}'events' field is deprecated and no longer supportedand HTTP 400 are preserved. Matching requires the exact exception type and message constant.{"Error":"class java.lang.IllegalAccessException : lack of computing resources"}{"Error":"lack of computing resources"}gettransactionbyidandgettransactioninfobyidservletsnull{"Error":"..."}JSONinternal server error.{"Error":"<existing validation message>"}getBrokerageandgetReward{"Error": "INVALID address, <raw exception message>"}{"Error":"INVALID address"}validateaddressinput validation{"result":false,"message":"<raw exception message>"};messagemay be absent when the exception message is null{"result":false,"message":"Invalid address"}address. Existing successful format messages andLength errorbehavior remain unchanged.{}responses for missing transaction records.validateaddressPOST parsing/body-size failures; this change does not add a response body to those log-only paths.Operator-facing note, not a client-visible change:
getburntrx,getnodeinfo,getpendingsizeand
getrewardpreviously logged their catch-all failures aterrorlevel. Those failures arenow logged at
debuglevel on the shared error path, so these log entries are not emitted underthe default log configuration.
feat(api): sanitize HTTP API error responses
fix(api): keep server-side failure logging at error level
feat(api): sanitize HTTP API error responses (#6954)
halibobo1205 commentedon Oct 29, 2026
Implemented by PR #6954.