fix: add DoS protection for UTXO deserialization#94
Merged
Conversation
Add configurable script size validation to prevent memory exhaustion attacks in UTXO deserialization functions. The vulnerability existed in NewUTXOFromReader() and NewUTXOValueFromReader() where malicious actors could provide extremely large script length values (up to 4.3GB) causing OOM crashes. The fix validates script lengths against the configurable maxscriptsizepolicy setting (default 500KB) before allocation. Changes: - Add maxUTXOScriptSize variable loaded from settings.Policy - Validate script length before memory allocation in both reader functions - Add comprehensive DoS protection tests including concurrent attack simulation - Add overflow protection capping at math.MaxUint32 Fixes #4248
Contributor
|
🤖 Claude Code Review Status: Complete Summary: No critical issues found. The DoS protection implementation is well-designed and properly addresses the vulnerability. Previously Fixed:
Implementation Quality:
The fix effectively prevents memory exhaustion attacks while maintaining compatibility with BSV's post-Genesis unbounded script sizes through policy-based limits. |
icellan
requested changes
Nov 3, 2025
|
icellan
approved these changes
Nov 3, 2025
oskarszoon
added a commit
that referenced
this pull request
Nov 11, 2025
This reverts commit 3e3412e.
7 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
Fixes a critical DoS vulnerability in UTXO deserialization where malicious actors could provide extremely large script length values causing memory exhaustion.
Changes
maxUTXOScriptSizevariable loaded fromsettings.Policy.MaxScriptSizePolicy(default 500KB)NewUTXOFromReader()andNewUTXOValueFromReader()math.MaxUint32Vulnerability Details
The vulnerability existed in:
services/utxopersister/UTXO.go:336-NewUTXOFromReader()services/utxopersister/UTXO.go:357-NewUTXOValueFromReader()Both functions read a 4-byte script length from untrusted input and immediately allocate memory without bounds checking. An attacker could provide a script length up to 4.3GB (max uint32), causing OOM crashes.
Security Impact
Before: Attacker could crash Teranode by providing malicious UTXO files/streams with 4.3GB script lengths
After: Script lengths validated against policy limit (default 500KB) before allocation, preventing memory exhaustion
Test Coverage
Configuration
The limit is configurable via
maxscriptsizepolicyin settings:Closes #4248