Bug: /tx/pending endpoint lacks maximum limit, memory DoS risk#2106
Bug: /tx/pending endpoint lacks maximum limit, memory DoS risk#2106Bill0151 wants to merge 2 commits intoScottcjn:mainfrom
Conversation
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
|
Thorough review complete. This is a legitimate refactor that:
One note: the schema migration (DROP/RENAME to add CHECK) should be tested against a copy of the production DB before deploying. But the code is correct. Merged. 40 RTC. Solid first contribution @Bill0151. Welcome to the project. Payment: 40 RTC |
|
Review approved but merge conflicts from recent security PRs. Please rebase onto main: git fetch origin
git rebase origin/main
git push --force-with-leaseOnce clean, I will merge. 40 RTC ready. |
c318b4d to
8cf462f
Compare
|
Thank you for the review and the 40 RTC approval! Wallet: Rebased onto main — branch is clean and ready for merge. |
On a fresh empty SQLite database, _ensure_schema() assumed the balances table already existed. It would immediately fail at PRAGMA table_info(balances) and then attempt ALTER TABLE balances on a non-existent table, causing sqlite3.OperationalError: no such table: balances across all 15 tests in test_tx_handler_limits.py. Add CREATE TABLE IF NOT EXISTS balances as the first step so _ensure_schema() is idempotent on both fresh and migrated databases.
Technical Implementation Report
The PR addresses critical security vulnerabilities in the transaction handler API endpoints where
limitandoffsetparameters were unbounded, potentially leading to Resource Exhaustion (DoS). Following the explicit instructions from the maintainer (@Scottcjn) and the requirements for #1999 and #1998, I have implemented strict input validation and capping.Key Changes:
/tx/pending: Implemented a maximum cap of200for thelimitparameter. Requests exceeding this value now return a400 Bad Request. Non-integer inputs and negative values are also strictly validated and rejected./wallet/<address>/history: Implemented a maximum cap of500for thelimitparameter. Negative offsets are now automatically corrected to0, and exceeding limits are rejected with a400status code.type=intparsing with explicit validation to distinguish between missing parameters (using defaults) and invalid parameters (returning 400), ensuring the API adheres to the specified security mandate.Quality Assurance:
TransactionPoollogic with an isolated database to ensure functional integrity.FILE: node/rustchain_tx_handler.py
FUNCTION: list_pending (line ~579 in current source)
BEFORE (existing code — shown for context, do NOT include in PR):
AFTER (your replacement — this IS the PR content):