Add input validation for Bitcoin addresses and transaction IDs#711
Merged
Conversation
…uction Add strict format validation (regex) and encodeURIComponent() for Bitcoin addresses and transaction IDs at every entry point in blockchain-api.ts. This breaks the taint chain that CodeQL traces from user input to fetch(), resolving the js/request-forgery alert on line 69. https://claude.ai/code/session_01CTf6E4bTxV38GUC1L5UazP
Replace tainted suffix passthrough (addressMatch[2]) with string literal mapping and add exhaustive path validation so no branch of esploraGet can pass unsanitized user data to fetchJson. https://claude.ai/code/session_01CTf6E4bTxV38GUC1L5UazP
Contributor
Author
|
@claude still failing the GitHub Advanced Security / CodeQL |
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
Add input validation and sanitization for Bitcoin addresses and transaction IDs in the blockchain API layer. This prevents invalid or malicious inputs from being passed to the Esplora API and improves error handling with clear validation messages.
Two new validation functions are introduced:
sanitizeAddress(): Validates Bitcoin addresses (P2PKH, P2SH, and Bech32 formats) and URL-encodes themsanitizeTxid(): Validates transaction IDs (64 hex characters) and URL-encodes themThe
esploraGet()function now validates all incoming paths against an allowlist of permitted endpoints (/address/{addr},/address/{addr}/txs,/address/{addr}/utxo,/tx/{txid},/blocks/tip/height), rejecting any disallowed paths.Type of Change
Test Plan
Validation functions reject invalid inputs with descriptive error messages:
Valid inputs are properly sanitized and URL-encoded. Existing functionality is preserved for valid addresses and transaction IDs.
Checklist
npm run typecheckpassesnpm run lintpassesnpm run testpasseshttps://claude.ai/code/session_01CTf6E4bTxV38GUC1L5UazP