Skip to content

Commit ecba07b

Browse files
committed
+ MaxBatchCalls check
1 parent 10a252f commit ecba07b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/BaseJsonRpcServer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class BaseJsonRpcServer {
7575
*/
7676
public $IsXDR = true;
7777

78+
/**
79+
* Max Batch Calls
80+
* @var int
81+
*/
82+
public $MaxBatchCalls = 10;
83+
7884
/**
7985
* Error Messages
8086
* @var array
@@ -122,6 +128,11 @@ private function getRequest() {
122128

123129
// check for batch call
124130
if ( is_array( $this->request ) ) {
131+
if( count( $this->request ) > $this->MaxBatchCalls ) {
132+
$error = self::InvalidRequest;
133+
break;
134+
}
135+
125136
$this->calls = $this->request;
126137
$this->isBatchCall = true;
127138
} else {

tests/DateTimeRpcServiceTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,16 @@ public function testBatchCalls() {
102102
}
103103
}
104104

105+
106+
public function testMultipleBatchCalls() {
107+
$requests = array();
108+
for ( $i = 1; $i < 12; $i ++ ) {
109+
$requests[] = array( 'jsonrpc' => '2.0', 'method' => 'GetRelativeTime', 'params' => array( 'now' ), 'id' => $i );
110+
}
111+
112+
$response = $this->call( $requests );
113+
$this->assertCount( 3, $response );
114+
$this->assertArrayHasKey( 'code', $response['error'] );
115+
}
116+
105117
}

0 commit comments

Comments
 (0)