@@ -51,6 +51,7 @@ const log_verbose_flag = process.argv.includes('-v');
5151let log_verbose = log_verbose_flag ;
5252let port_http = 0 ;
5353let port_https = 0 ;
54+ let upload_limit = 10 * 1024 * 1024 ;
5455let compression_enabled = true ;
5556let exiting = false ;
5657/// any path -> file
@@ -1063,6 +1064,17 @@ const request_handle = async (request, response, https) => {
10631064 ) {
10641065 if ( ! file_dyn_enabled ) throw 405 ;
10651066 if ( 'content-length' in request_headers ) {
1067+ const content_length = Number ( request_headers [ 'content-length' ] ) ;
1068+ if (
1069+ isNaN ( content_length ) ||
1070+ content_length < 0 ||
1071+ content_length % 1 > 0
1072+ ) {
1073+ throw 400 ;
1074+ }
1075+ if ( content_length > upload_limit ) {
1076+ throw 413 ;
1077+ }
10661078 request_body_promise = new Promise ( resolve => {
10671079 const request_body_chunks = [ ] ;
10681080 request . on ( 'data' , chunk => {
@@ -1539,6 +1551,9 @@ const request_handle = async (request, response, https) => {
15391551 http . STATUS_CODES [ err ] || 'Error'
15401552 } </h1></body></html>`) ;
15411553 }
1554+ if ( 'content-length' in request_headers ) {
1555+ request . socket . destroy ( ) ;
1556+ }
15421557 }
15431558}
15441559
@@ -1821,6 +1836,7 @@ await file_keep_new('rtjscomp.json', data => {
18211836 const type_dynamics_new = get_prop_list ( data , 'type_dynamics' ) ;
18221837 const type_mimes_new = get_prop_map ( data , 'type_mimes' ) ;
18231838 const type_raws_new = get_prop_list ( data , 'type_raws' ) ;
1839+ const upload_limit_new = get_prop_uint ( data , 'upload_limit' , 10 ) ;
18241840 const zstd_level_new = get_prop_uint ( data , 'zstd_level' , 3 ) ;
18251841
18261842 if ( data ) {
@@ -1832,20 +1848,21 @@ await file_keep_new('rtjscomp.json', data => {
18321848 if ( gzip_level_new > 9 ) {
18331849 throw 'gzip_level > 9' ;
18341850 }
1835- if ( zstd_level_new > 19 ) {
1836- throw 'zstd_level > 19' ;
1837- }
18381851 if (
18391852 port_http_new > 65535 ||
18401853 port_https_new > 65535
18411854 ) {
18421855 throw 'port > 65535' ;
18431856 }
1857+ if ( zstd_level_new > 19 ) {
1858+ throw 'zstd_level > 19' ;
1859+ }
18441860
18451861 compression_enabled = compression_enabled_new ;
18461862 GZIP_OPTIONS . level = compression_enabled ? gzip_level_new : 0 ;
18471863 ZSTD_OPTIONS . params [ ZSTD_c_compressionLevel ] = zstd_level_new ;
18481864 log_verbose = log_verbose_new ;
1865+ upload_limit = upload_limit_new * 1024 * 1024 ;
18491866 if ( path_ghosts_new ) {
18501867 path_ghosts . clear ( ) ;
18511868 for ( const key of path_ghosts_new ) {
0 commit comments