MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / test_batch_abuse

Function test_batch_abuse

tests/security/test_api_vulnerabilities.py:310–353  ·  view source on GitHub ↗

Test batch command abuse

(tester)

Source from the content-addressed store, hash-verified

308
309
310def test_batch_abuse(tester):
311 """Test batch command abuse"""
312 print("\n[*] Testing batch command abuse...")
313
314 with SerialStudioClient() as client:
315 # Test 1: Huge batch request
316 print(" - Testing oversized batch (10000 commands)...")
317 huge_batch = [{"command": "api.getCommands"} for _ in range(10000)]
318
319 try:
320 start = time.time()
321 results = client.batch(huge_batch, timeout=30.0)
322 elapsed = time.time() - start
323
324 # Check if server rejected the batch (error dict returned)
325 if isinstance(results, dict) and results.get("error"):
326 print(f" Server rejected batch: {results.get('message')} (GOOD)")
327 elif isinstance(results, list) and len(results) > 0:
328 tester.log_vulnerability(
329 "MEDIUM",
330 "Batch Processing",
331 f"Server processed {len(results)} commands in {elapsed:.2f}s without limit",
332 f"{len(huge_batch)} commands",
333 )
334 else:
335 print(" Server rejected batch (GOOD)")
336 except (APIError, TimeoutError) as e:
337 print(f" Server rejected or timed out: {e} (GOOD)")
338
339 # Test 2: Nested batch requests (if possible)
340 print(" - Testing recursive batch commands...")
341 try:
342 # Try to create recursive structure
343 recursive_batch = [
344 {
345 "command": "project.loadJson",
346 "params": {"config": {"title": f"Level-{i}"}},
347 }
348 for i in range(100)
349 ]
350 results = client.batch(recursive_batch)
351 print(f" Processed {len(results)} nested commands")
352 except (APIError, TimeoutError):
353 print(" Rejected (GOOD)")
354
355
356def test_connection_exhaustion(tester):

Callers 1

mainFunction · 0.85

Calls 4

SerialStudioClientClass · 0.90
batchMethod · 0.80
getMethod · 0.45
log_vulnerabilityMethod · 0.45

Tested by

no test coverage detected