Skip to content

#2148: wallet-api: log only the first 1 KB of an invalid request - #2149

Open
profinch wants to merge 1 commit into
BeamMW:masterfrom
profinch:fix/2148-api-log-truncate
Open

profinch wants to merge 1 commit into
BeamMW:masterfrom
profinch:fix/2148-api-log-truncate

Conversation

@profinch

@profinch profinch commented Oct 6, 2026 •

Copy link
Copy Markdown

Fixes #2148.

When a request failed to parse, ApiBase::executeAPIRequest and ApiBase::fromError wrote the whole request to the warning log. Any client that can reach the API port could grow the log by up to 16 MB per request (the HTTP body limit; 64 KB per line in TCP mode) and fill the disk.

Fix
Both warnings now log the first 1024 bytes plus the request size, e.g. "xxxx…... (1000000 bytes). This matches stratum::parse_json, which already logs at most 1024 bytes. Short requests are logged unchanged.

Tests

  • wallet_api_test passes.
  • Manual: wallet-api --use_http=1, sending invalid 1 MB bodies (junk and an unterminated string). Before: 20 requests added 20 MB to the log. After: 40 requests added 48 KB, and the API keeps serving.
  • Manual, at the HTTP body limit: one invalid 16 MB request added 16,777,294 bytes to the log before the fix and 1,122 bytes after.

Merges cleanly with #2145 and #2146 (checked with git merge-tree).

A request that failed to parse was logged in full, so any client could grow
the log by up to 1 MB per request (64 KB per line in TCP mode). executeAPIRequest
and fromError now log the first 1024 bytes and the request size.
@vsnation

Copy link
Copy Markdown

Heads-up on an overlap: #2119 changes the same executeAPIRequest … parseCallInfo returned none line, for a different reason. A request that fails parsing can carry the ACL "key" (or change_password's new_pass), and these usually sit in the first few hundred bytes, so a 1 KB prefix still logs them. #2119 logs only the size there (… for a request of N bytes) and masks key / new_pass in the verbose FilterRequest dump. The two approaches combine fine: RequestForLog for fromError (apps path) and size-only in executeAPIRequest. Whichever lands second needs a one-line rebase.

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.

wallet-api: invalid requests are logged in full, a client can flood the log

2 participants