Skip to content

Global exception handling leaks internal error details (including possible Soroban/DB error messages) to API clients #19

Closed

Description

@chonilius

Background

main.ts does not register any global ExceptionFilter; NestJS's default
exception handling for uncaught errors returns a generic 500 with, depending
on configuration, potentially the raw error message. Several service methods
throw raw Error objects with interpolated internal details directly, e.g.
SorobanClientService.invoke throws a plain Error containing the raw
simulation-error string, and another containing a JSON-stringified
error-result object from a failed transaction submission. These are plain
Errors, not NestJS HttpExceptions, and nothing in the visible code catches
and sanitizes them before they'd reach an HTTP response.

Problem Statement

Investigate what actually reaches the client today for each of the
following failure paths, and fix any that leak internal detail:

  • A Soroban simulation/submission failure bubbling up through
    EscrowService.fund/release/etc. — does the raw simulation error detail
    (which could include contract execution traces, internal RPC endpoint
    details, or account/keypair details) reach the HTTP response body?
  • A raw TypeORM/Postgres error (e.g. a constraint violation, a connection
    failure) — does the underlying SQL error message (which can leak schema
    details, table/column names, or even fragments of query parameters)
    reach the client?
  • Any place where a caught error's message or stack is directly
    interpolated into a response or a BadRequestException message.

Requirements

  • Add a global ExceptionFilter (registered via useGlobalFilters) that
    catches all unhandled errors, logs the full detail server-side (using the
    correlation-ID-aware structured logging from the observability issue, if
    landed first — otherwise standard Logger), and returns a sanitized,
    generic error response to the client (with a reference/correlation ID the
    client can quote when reporting the issue, not the raw message).
  • Convert internal service-layer raw Error throws that currently leak
    Soroban/DB internals into either caught-and-rethrown sanitized
    HttpExceptions at the boundary, or ensure the global filter
    categorically strips detail from any non-HttpException error reaching
    it.
  • Explicitly allow validated, intentional client-facing messages (e.g.
    BadRequestException messages that are already written for end users,
    like the split-percentage validation errors) to pass through unmodified —
    the fix must distinguish "safe, intentional user-facing message" from
    "raw internal exception," not blanket-suppress everything.
  • Add tests asserting: a simulated Soroban failure results in a generic
    sanitized client response (not containing the raw internal error content)
    while still being fully logged server-side with detail intact.

Acceptance Criteria

  • A global exception filter is registered and covers both NestJS
    HttpExceptions and raw Errors.
  • Tests prove a raw Soroban/DB error's message content is absent from
    the HTTP response body, while present in server logs.
  • Legitimate BadRequestException/NotFoundException messages
    written for end users are unaffected.

Technical Notes

Files: src/main.ts, src/escrow/soroban-client.service.ts,
src/escrow/escrow.service.ts, and any custom filter you add (suggest
src/common/filters/global-exception.filter.ts).

Difficulty Justification

Requires careful classification logic to avoid the common failure mode of
either leaking everything (status quo) or over-suppressing everything
(breaking legitimate validation error messages users need to see) — a
correct fix needs a principled boundary, not a blanket try/catch.

Activity

  1. added
    very hard
    bug
    security
    help wanted
    on Jul 15, 2026
  2. added
    GrantFox OSS
    Maybe Rewarded
    Official Campaign | FWC26
    on Jul 15, 2026
  3. circleboyslimited commented on Jul 17, 2026

    @circleboyslimited
    Contributor

    I will investigate the application's current exception flow to identify where internal errors propagate to HTTP responses, with particular focus on Soroban transaction failures, database exceptions, and uncaught runtime errors. The goal is to verify whether sensitive implementation details such as RPC responses, contract execution traces, SQL errors, or stack information are exposed to API consumers.

    Based on the findings, I will implement a global NestJS ExceptionFilter to provide consistent error handling across the application. The filter will preserve intentional client-facing HttpException messages while sanitizing unexpected internal exceptions into generic error responses. Detailed error information, including stack traces and contextual metadata, will be logged server-side together with correlation identifiers for troubleshooting.

    I will also review service-layer error handling, replacing raw Error throws where appropriate or ensuring they are safely transformed before reaching the HTTP boundary. This will establish a clear separation between internal diagnostics and externally exposed API responses.

    Finally, I will add integration tests covering Soroban failures, database exceptions, and validation errors to verify that sensitive information is never returned to clients while remaining fully available in server logs for debugging.

  4. grantfox-oss commented on Jul 17, 2026

    @grantfox-oss

    🦊 GrantFox — @circleboyslimited has been assigned to this issue as part of the Official Campaign | FWC26 campaign!

    Next steps:

    1. Open a Pull Request referencing this issue (e.g., Closes #19)
    2. Your PR will be reviewed by the MergeFi maintainers

    Good luck! Track your progress on GrantFox.

  5. grantfox-oss commented on Jul 17, 2026

    @grantfox-oss

    🎉 This issue has been marked as completed on GrantFox as part of the Official Campaign | FWC26 campaign!

    @circleboyslimited's PR #34 was approved and merged by @chonilius.

    🏆 @circleboyslimited: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (118 total points). Track your full progress on GrantFox.

    👏 Great work, @circleboyslimited! Keep contributing to MergeFi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

GrantFox OSSMaybe RewardedOfficial Campaign | FWC26bughelp wantedsecurityvery hard

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions