From 6dc16ef7a3963549bafdcafa7098ed3d7bce5f4e Mon Sep 17 00:00:00 2001 From: totoro Date: Mon, 20 Apr 2020 19:46:52 +0900 Subject: [PATCH] remove denial of service which is not serializable and not working since anubis 1.17 (Anubis 1.17 take more care about serializable type and warn about it if a non serializable type will is in serialization process) --- generic/session.anubis | 5 +++-- generic/types/session.anubis | 2 +- web/CXM_making_a_web_site.anubis | 3 +-- web/CXM_multihost_http_server.anubis | 81 ++++++++++++++++++++++++++++++++++++--------------------------------------------- 4 files changed, 41 insertions(+), 50 deletions(-) diff --git a/generic/session.anubis b/generic/session.anubis index 0a2ba96..3185d67 100644 --- a/generic/session.anubis +++ b/generic/session.anubis @@ -7,6 +7,7 @@ */ transmit xlib/generic/types/session.anubis +read system/data_io.anubis public define Var(List(Session_Field)) empty_fields_list = @@ -32,7 +33,7 @@ public define Var(List(Session_Field)) bool(v) then bool(v), int(v) then int(v), db_id(v) then db_id(v), - message(v) then message(v), + message(v) then message(if unflatten_message(make_data_io(v)) is {failure then message(0), success(msg) then msg}), byte_array(v) then byte_array(v), float(v) then float(v), word128(v) then word128(v), @@ -61,7 +62,7 @@ public define List(Session_Field_No_Var) bool(v) then bool(v), int(v) then int(v), db_id(v) then db_id(v), - message(v) then message(v), + message(v) then message(if flatten_message(v) is {failure then constant_byte_array(0,0), success(ba) then ba}), byte_array(v) then byte_array(v), float(v) then float(v), word128(v) then word128(v), diff --git a/generic/types/session.anubis b/generic/types/session.anubis index 29df479..4a87af1 100644 --- a/generic/types/session.anubis +++ b/generic/types/session.anubis @@ -35,7 +35,7 @@ public type Session_Field_Datum_No_Var: bool(Bool), //fully implented int(Int), //fully implemented db_id(DB_id), - message(Message), //fully implemented + message(ByteArray), //fully implemented byte_array(ByteArray), float(Float), word128(Word128), diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index f1cee73..7ad36f8 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -3006,13 +3006,12 @@ public define Start_Web_Sites_Result with http_server_r = start_http_server(ip_address,http_port, map(get_description,web_sites), - load_denial_of_service_info, + //load_denial_of_service_info, shutdown_required), with https_server_r = start_https_server(ip_address,https_port, ssl_certificate_common_name, map(get_description,web_sites), - load_denial_of_service_info, shutdown_required), if http_server_r is ok(http_server) then diff --git a/web/CXM_multihost_http_server.anubis b/web/CXM_multihost_http_server.anubis index 909f323..9d31090 100644 --- a/web/CXM_multihost_http_server.anubis +++ b/web/CXM_multihost_http_server.anubis @@ -351,8 +351,8 @@ public define StartServerResult ( Word32 ip_address, Word32 http_port, - List(Web_Site_Description) web_sites, - DenialOfService dos + List(Web_Site_Description) web_sites + //DenialOfService dos ). public define StartServerResult @@ -361,8 +361,8 @@ public define StartServerResult Word32 ip_address, Word32 https_port, String certificate_common_name, - List(Web_Site_Description) web_sites, - DenialOfService dos + List(Web_Site_Description) web_sites + //DenialOfService dos ). The first argument 'ip_address' is the IP address on which the servers listen. If you @@ -2509,8 +2509,8 @@ define One Word32 ip_addr, // of the client HTTP_Request_Line request_line, List(HTTP_header) headers, - ByteArray body, - One -> String generate_tt // trust ticket generation + ByteArray body + //One -> String generate_tt // trust ticket generation ) = with all_web_args = query_string(request_line) + read_www_url_encoded_web_args(to_string(body),0), @@ -3014,7 +3014,6 @@ define One HTTP_Request_Line request_line, List(HTTP_header) headers, String body_temp_file, - One -> String generate_tt, SState s ) = if get_boundary(headers) is @@ -3285,7 +3284,7 @@ define Maybe((String,Web_Site_Description)) -define One -> String make_generate_trust_ticket(DenialOfService dos). + define One -> String make_generate_trust_ticket(DenialOfService dos). define One http_https_handler @@ -3293,7 +3292,6 @@ define One List(Web_Site_Description) sites, HTTP_Buffered_Connection connection, Bool is_https, - DenialOfService dos, SState s, (One) -> Bool shutdown_required ) = @@ -3305,7 +3303,7 @@ define One println("shutdown required on http_https_handler"); unique else - if dos is denial_of_service(mc_v,rld_v,hd_v,ad_v,ld_v,ra_v) then + //if dos is denial_of_service(mc_v,rld_v,hd_v,ad_v,ld_v,ra_v) then if remote_IP_address_and_port(connection.conn) is (ip_addr,port) then if read_request_line(connection) is { @@ -3330,7 +3328,7 @@ define One //Get the type of encoding which decide if we read the content in ByteArray for www_url or in //temporary file for multipart. - with generate_tt = make_generate_trust_ticket(dos), + //with generate_tt = make_generate_trust_ticket(dos), if get_encoding_type(headers) is { //WWW_URL @@ -3340,9 +3338,9 @@ define One error(msg) then log_journal_msg(desc,format(msg)), ok(body) then //HERE produce the answer of the server - www_url_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, body, generate_tt); + www_url_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, body); //it's HTTP 1.1 keep-alive is default - http_https_handler(sites, connection, is_https, dos, s, shutdown_required) + http_https_handler(sites, connection, is_https, s, shutdown_required) } //MULTIPART_FORM_DATA @@ -3380,10 +3378,10 @@ define One with duration = (UTime) unow - t0, println("Read body "+read_size+" duration: " + __utime_to_string(duration)); - multipart_form_data_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, desc.site_directory + tmp_body_file, generate_tt, s); + multipart_form_data_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, desc.site_directory + tmp_body_file, s); //it's HTTP 1.1 keep-alive is default - http_https_handler(sites, connection, is_https, dos, s, shutdown_required) + http_https_handler(sites, connection, is_https, s, shutdown_required) else println("Can't copy data from stream to temporary file "), @@ -3394,10 +3392,10 @@ define One with duration = (UTime) unow - t0, println("Read body "+read_size+" duration: " + __utime_to_string(duration)); - multipart_form_data_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, desc.site_directory + tmp_body_file, generate_tt, s); + multipart_form_data_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, desc.site_directory + tmp_body_file, s); //it's HTTP 1.1 keep-alive is default - http_https_handler(sites, connection, is_https, dos, s, shutdown_required) + http_https_handler(sites, connection, is_https, s, shutdown_required) else println("Can't copy data from stream to temporary file ") @@ -3427,48 +3425,46 @@ define One Below are the two tools for constructing the handlers required by 'start_server' and 'start_ssl_server' (see 'predefined.anubis'). -define Bool is_dubious_IP(Word32 ip, DenialOfService dos). + define Bool is_dubious_IP(Word32 ip, DenialOfService dos). define Server -> ((RWStream) -> One) make_http_handler ( List(Web_Site_Description) sites, - DenialOfService dos, (One) -> Bool shutdown_required ) = (Server server) |-> (RWStream conn) |-> if remote_IP_address_and_port(conn) is (addr,_) then - if is_dubious_IP(addr,dos) - then print("Rejecting dubious IP address "+ip_addr_to_string(addr)+"\n") - else +// if is_dubious_IP(addr,dos) +// then print("Rejecting dubious IP address "+ip_addr_to_string(addr)+"\n") +// else with connection = http_buffered_connection(tcp(conn), var(constant_byte_array(0, 0)), var(0), var([])), - http_https_handler(sites, connection, false, dos, sstate(var(0),var(0)), shutdown_required). + http_https_handler(sites, connection, false, sstate(var(0),var(0)), shutdown_required). + public define One http_direct_handler ( List(Web_Site_Description) sites, RWStream conn, - DenialOfService dos, (One) -> Bool shutdown_required ) = if remote_IP_address_and_port(conn) is (addr,_) then - if is_dubious_IP(addr,dos) - then print("Rejecting dubious IP address "+ip_addr_to_string(addr)+"\n") - else +// if is_dubious_IP(addr,dos) +// then print("Rejecting dubious IP address "+ip_addr_to_string(addr)+"\n") +// else with connection = http_buffered_connection(tcp(conn), var(constant_byte_array(0, 0)), var(0), var([])), - http_https_handler(sites, connection, false, dos, sstate(var(0),var(0)), shutdown_required). + http_https_handler(sites, connection, false, sstate(var(0),var(0)), shutdown_required). define Server -> (SSL_Connection -> One) make_https_handler ( List(Web_Site_Description) sites, - DenialOfService dos, (One) -> Bool shutdown_required ) = (Server server) |-> (SSL_Connection conn) |-> with connection = http_buffered_connection(ssl(conn), var(constant_byte_array(0, 0)), var(0), var([])), - http_https_handler(sites, connection, true, dos, sstate(var(0),var(0)), shutdown_required). + http_https_handler(sites, connection, true, sstate(var(0),var(0)), shutdown_required). @@ -3599,7 +3595,7 @@ define One record_dubious_IP(addr,list_of_dubious(dos)). -public define DenialOfService + public define DenialOfService load_denial_of_service_info = if (RetrieveResult(DenialOfService))retrieve(my_anubis_directory+"/web_sites/dos_info") is @@ -3732,8 +3728,8 @@ define StartServerResult Word32 ip_address, Word32 port, Server -> ((RWStream) -> One) handler, - Int retries, - DenialOfService dos + Int retries + //DenialOfService dos ) = if start_server(ip_address, port, @@ -3743,7 +3739,7 @@ define StartServerResult ok(server) else print("Port "+port+": retry number "+retries+"\r"); sleep(1000); - start_http_server(ip_address,port,handler,retries+1,dos). + start_http_server(ip_address,port,handler,retries+1). public define StartServerResult start_http_server @@ -3751,14 +3747,12 @@ public define StartServerResult Word32 ip_address, Word32 port, List(Web_Site_Description) sites, - DenialOfService dos, (One) -> Bool shutdown_required ) = create_directories(sites); start_http_server(ip_address,port, - make_http_handler(sites, dos, shutdown_required), - 0, - dos). + make_http_handler(sites, shutdown_required), + 0). For the HTTPS server, we have a problem which is due to the fact that 'anbexec' is not @@ -3775,8 +3769,7 @@ define StartServerResult Word32 port, String certificate_common_name, Server -> (SSL_Connection -> One) handler, - Int retries, - DenialOfService dos + Int retries ) = if start_ssl_server(ip_address, port, @@ -3789,8 +3782,7 @@ define StartServerResult sleep(1000); start_https_server(ip_address,port, certificate_common_name, - handler,retries+1, - dos). + handler,retries+1). public define StartServerResult @@ -3800,13 +3792,12 @@ public define StartServerResult Word32 port, String certificate_common_name, // of SSL server certificate List(Web_Site_Description) sites, - DenialOfService dos, (One) -> Bool shutdown_required ) = create_directories(sites); start_https_server(ip_address,port,certificate_common_name, - make_https_handler(sites, dos, shutdown_required), - 0,dos). + make_https_handler(sites, shutdown_required), + 0). -- libgit2 0.21.4