fix: add hash format validation to importBlock endpoint
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 5s
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Successful in 2s
Cross-Node Transaction Testing / transaction-test (push) Successful in 2s
Deploy to Testnet / deploy-testnet (push) Successful in 1m18s
Integration Tests / test-service-integration (push) Successful in 1m23s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 2s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 2s
Multi-Node Stress Testing / stress-test (push) Successful in 2s
Node Failover Simulation / failover-test (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Failing after 44s
Security Scanning / security-scan (push) Successful in 42s
Cross-Chain Functionality Tests / aggregate-results (push) Successful in 2s
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 5s
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Successful in 2s
Cross-Node Transaction Testing / transaction-test (push) Successful in 2s
Deploy to Testnet / deploy-testnet (push) Successful in 1m18s
Integration Tests / test-service-integration (push) Successful in 1m23s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 2s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 2s
Multi-Node Stress Testing / stress-test (push) Successful in 2s
Node Failover Simulation / failover-test (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Failing after 44s
Security Scanning / security-scan (push) Successful in 42s
Cross-Chain Functionality Tests / aggregate-results (push) Successful in 2s
- Validate block hash is 0x + 64 hex chars; return 400 for invalid format - Fixes test_block_import and test_block_import_complete CI failures - Update test_block_import_complete Test 2 to expect 400 (invalid hash format) instead of 409 (conflict); invalid hash is now rejected before DB lookup - Move re import to top of router.py
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
import uuid
|
||||
from typing import Any, Dict, Optional, List
|
||||
@@ -874,6 +875,10 @@ async def import_block(
|
||||
chain_id = block_data.get("chain_id") or block_data.get("chainId") or get_chain_id(None)
|
||||
block_hash = block_data["hash"]
|
||||
|
||||
# Validate block hash format: must be 0x followed by exactly 64 hex characters
|
||||
if not isinstance(block_hash, str) or not re.fullmatch(r"0x[0-9a-fA-F]{64}", block_hash):
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid block hash format")
|
||||
|
||||
try:
|
||||
block_height = int(block_data["height"])
|
||||
except (KeyError, TypeError, ValueError) as exc:
|
||||
|
||||
Reference in New Issue
Block a user