Security/3.4.0#464
Open
ronaldsg20 wants to merge 4 commits into
Open
Conversation
Dependency ReviewThe following issues were found:
|
…failures
I've defined ADDRESS_LIST_MAX_ITEMS, UTXO_RESPONSE_MAX_ROWS,
ADDRESS_INFO_MAX_TXIDS and PROVIDER_CONCURRENCY env variables in
order to set an upper bound of on the requests and avoid external
provider/services saturation
e44fa79 to
d6cae73
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Summary
Adds input-size caps, duplicate rejection, concurrency control, and per-address txid/UTXO row limits to the
/addresses-infoand/utxoendpoints to prevent resource exhaustion attacks. Also fixes three acceptance-test failures caused by unstubbed service dependencies hitting MongoDB.🔍 Description
What was changed
New utilities
src/config/limits.ts— centralised, env-overridable constants (ADDRESS_LIST_MAX_ITEMS,UTXO_RESPONSE_MAX_ROWS,ADDRESS_INFO_MAX_TXIDS,PROVIDER_CONCURRENCY,REJECT_DUPLICATE_ADDRESSES).src/utils/address-patterns.ts— single source of truth for BTC, EVM, and combined address regex patterns; replaces inline duplicated patterns across controllers and models.src/utils/address-list-validation.ts— shared guard that raises422 UnprocessableEntitywhen the list exceedsmaxItemsor contains duplicate addresses.src/utils/concurrency.ts—withConcurrencyhelper that processes items in bounded batches instead of an unboundedPromise.all, limiting simultaneous upstream calls.Controller hardening
AddressesInfoController— now validates the list, fans out withwithConcurrency, and capstxidsper address atADDRESS_INFO_MAX_TXIDSbefore serialisation.UtxoController— validates the list, fans out withwithConcurrency, and rejects responses that exceedUTXO_RESPONSE_MAX_ROWSwith413 PayloadTooLarge.Promise.all+.then/.catchchains toasync/await.Why it was changed
The
/addresses-infoand/utxoendpoints accepted arbitrarily long address lists and issued a separate upstream HTTP call per address with no concurrency ceiling, creating a straightforward amplification vector (one small API request → N simultaneous Blockbook calls). Duplicate addresses compounded the issue. The acceptance test failures were pre-existing regressions introduced when test setup did not stub all service dependencies.Scope of impact
All changes are additive or are refactors of existing validation logic. Default limits are generous (
ADDRESS_LIST_MAX_ITEMS=50,UTXO_RESPONSE_MAX_ROWS=1000,ADDRESS_INFO_MAX_TXIDS=100,PROVIDER_CONCURRENCY=5) and can be tuned via environment variables without a code change.🧪 How to Test
Unit tests
Acceptance tests (all should pass, 0 failing)
🧠 Known Issues / Limitations
withConcurrencyprocesses items in sequential chunks of sizePROVIDER_CONCURRENCY; truly interleaved concurrency (e.g. a semaphore) would give better throughput for large lists but is not required at current scale.ADDRESS_LIST_MAX_ITEMSdefaults to 50; downstream callers that currently send larger lists will receive 422 — a coordinated front-end update may be needed.413 PayloadTooLargeafter all upstream calls complete; future work could short-circuit earlier once the threshold is reached.📎 Related task