@@ -262,7 +262,17 @@ function createDevSSRMiddleware(
262262 server . ssrLoadModule ( VIACT_SERVER_MODULE_ID ) ,
263263 ] ) ;
264264
265- const webRequest = await nodeToWebRequest ( req ) ;
265+ let webRequest : Request ;
266+ try {
267+ webRequest = await nodeToWebRequest ( req ) ;
268+ } catch ( err ) {
269+ if ( err instanceof Error && err . message === "Request body too large" ) {
270+ res . statusCode = 413 ;
271+ res . end ( "Payload Too Large" ) ;
272+ return ;
273+ }
274+ throw err ;
275+ }
266276 const response = await framework . handleViactRequest ( {
267277 app : serverMod . resolvedApp ,
268278 registry : serverMod . registry ,
@@ -322,9 +332,17 @@ async function nodeToWebRequest(req: IncomingMessage): Promise<Request> {
322332 const init : RequestInit = { method, headers } ;
323333
324334 if ( ! BODYLESS_METHODS . has ( method . toUpperCase ( ) ) ) {
335+ const MAX_BODY_SIZE = 1024 * 1024 ; // 1 MB
325336 const chunks : Uint8Array [ ] = [ ] ;
337+ let totalSize = 0 ;
326338 for await ( const chunk of req ) {
327- chunks . push ( typeof chunk === "string" ? Buffer . from ( chunk ) : chunk ) ;
339+ const buf = typeof chunk === "string" ? Buffer . from ( chunk ) : chunk ;
340+ totalSize += buf . byteLength ;
341+ if ( totalSize > MAX_BODY_SIZE ) {
342+ req . destroy ( ) ;
343+ throw new Error ( "Request body too large" ) ;
344+ }
345+ chunks . push ( buf ) ;
328346 }
329347 const body = Buffer . concat ( chunks ) ;
330348 if ( body . byteLength > 0 ) {
0 commit comments