Skip to content

Add input validation for Bitcoin addresses and transaction IDs#711

Merged
jamespepper81 merged 2 commits into
alert-autofix-3from
claude/dreamy-pascal-1SZMO
May 27, 2026
Merged

Add input validation for Bitcoin addresses and transaction IDs#711
jamespepper81 merged 2 commits into
alert-autofix-3from
claude/dreamy-pascal-1SZMO

Conversation

@jamespepper81
Copy link
Copy Markdown
Contributor

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 them
  • sanitizeTxid(): Validates transaction IDs (64 hex characters) and URL-encodes them

The 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

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor / cleanup

Test Plan

Validation functions reject invalid inputs with descriptive error messages:

  • Invalid Bitcoin addresses (wrong format, length, characters)
  • Invalid transaction IDs (non-hex characters, incorrect length)
  • Disallowed Esplora endpoints

Valid inputs are properly sanitized and URL-encoded. Existing functionality is preserved for valid addresses and transaction IDs.

Checklist

  • npm run typecheck passes
  • npm run lint passes
  • npm run test passes
  • Documentation updated (if applicable)

https://claude.ai/code/session_01CTf6E4bTxV38GUC1L5UazP

claude added 2 commits May 27, 2026 15:57
…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
@jamespepper81 jamespepper81 merged commit b79c705 into alert-autofix-3 May 27, 2026
@jamespepper81 jamespepper81 deleted the claude/dreamy-pascal-1SZMO branch May 27, 2026 16:36
@jamespepper81 jamespepper81 restored the claude/dreamy-pascal-1SZMO branch May 27, 2026 16:40
@jamespepper81
Copy link
Copy Markdown
Contributor Author

@claude still failing the GitHub Advanced Security / CodeQL

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.

2 participants