@@ -32,7 +32,7 @@ describe('[Util/RPC]', () => {
32
32
const httpServer = createRPCServerListener ( {
33
33
server,
34
34
withEngineMiddleware : { jwtSecret : new Uint8Array ( 32 ) } ,
35
- maxPayload : '15mb' ,
35
+ maxPayload : Config . RPC_ETH_MAXPAYLOAD_DEFAULT ,
36
36
} )
37
37
const wsServer = createWsRPCServerListener ( {
38
38
server,
@@ -75,7 +75,7 @@ describe('[Util/RPC]', () => {
75
75
const httpServer = createRPCServerListener ( {
76
76
server,
77
77
withEngineMiddleware : { jwtSecret : new Uint8Array ( 32 ) } ,
78
- maxPayload : '15mb' ,
78
+ maxPayload : Config . RPC_ENGINE_MAXPAYLOAD_DEFAULT ,
79
79
} )
80
80
const wsServer = createWsRPCServerListener ( {
81
81
server,
@@ -86,6 +86,96 @@ describe('[Util/RPC]', () => {
86
86
'should return http and ws servers' ,
87
87
)
88
88
} )
89
+ it ( 'should reject oversized RPC payloads' , async ( ) => {
90
+ const config = new Config ( {
91
+ accountCache : 10000 ,
92
+ storageCache : 1000 ,
93
+ rpcEthMaxPayload : '1kb' ,
94
+ rpcEngineMaxPayload : '10mb' ,
95
+ } )
96
+ const client = await EthereumClient . create ( { config, metaDB : new MemoryLevel ( ) } )
97
+
98
+ const manager = new RPCManager ( client , config )
99
+ const { logger } = config
100
+ const methodConfig = Object . values ( MethodConfig ) [ 0 ]
101
+ const { server } = createRPCServer ( manager , {
102
+ methodConfig,
103
+ rpcDebug : 'eth' ,
104
+ logger,
105
+ rpcDebugVerbose : undefined as any ,
106
+ } )
107
+
108
+ const ethHttpServer = createRPCServerListener ( {
109
+ server,
110
+ withEngineMiddleware : undefined ,
111
+ maxPayload : config . rpcEthMaxPayload ,
112
+ } )
113
+
114
+ const engineHttpServer = createRPCServerListener ( {
115
+ server,
116
+ withEngineMiddleware : undefined ,
117
+ maxPayload : config . rpcEngineMaxPayload ,
118
+ } )
119
+
120
+ const ethPort = 8545
121
+ const enginePort = 8551
122
+
123
+ ethHttpServer . listen ( ethPort )
124
+ engineHttpServer . listen ( enginePort )
125
+
126
+ const oversizedEthPayload = JSON . stringify ( {
127
+ jsonrpc : '2.0' ,
128
+ id : 1 ,
129
+ method : 'eth_getBlockByNumber' ,
130
+ params : [ 'latest' , true ] ,
131
+ data : 'eth' . repeat ( 2500 ) ,
132
+ } )
133
+
134
+ const oversizedEnginePayload = JSON . stringify ( {
135
+ jsonrpc : '2.0' ,
136
+ id : 1 ,
137
+ method : 'engine_newPayloadV2' ,
138
+ params : [
139
+ {
140
+ baseFeePerGas : '0x' ,
141
+ blockHash : '0x' ,
142
+ blockNumber : '0x' ,
143
+ extraData : '0x' . repeat ( 2500 ) ,
144
+ feeRecipient : '0x' ,
145
+ gasLimit : '0x' ,
146
+ gasUsed : '0x' ,
147
+ logsBloom : '0x' ,
148
+ parentHash : '0x' ,
149
+ prevRandao : '0x' ,
150
+ receiptsRoot : '0x' ,
151
+ stateRoot : '0x' ,
152
+ timestamp : '0x' ,
153
+ transactions : [ ] ,
154
+ } ,
155
+ ] ,
156
+ } )
157
+
158
+ const resEth = await fetch ( `http://localhost:${ ethPort } ` , {
159
+ method : 'POST' ,
160
+ body : oversizedEthPayload ,
161
+ headers : { 'Content-Type' : 'application/json' } ,
162
+ } )
163
+
164
+ const resEngine = await fetch ( `http://localhost:${ enginePort } ` , {
165
+ method : 'POST' ,
166
+ body : oversizedEnginePayload ,
167
+ headers : {
168
+ 'Content-Type' : 'application/json' ,
169
+ } ,
170
+ } )
171
+
172
+ assert . strictEqual (
173
+ resEth . status ,
174
+ 413 ,
175
+ 'ETH server should reject oversized payload with 413 status' ,
176
+ )
177
+ assert . strictEqual ( resEngine . status , 200 , 'ENGINE server should accept oversized payload' )
178
+ } )
89
179
} )
90
180
91
181
describe ( '[Util/RPC/Engine eth methods]' , async ( ) => {
0 commit comments