@@ -29,7 +29,7 @@ ngx_http_bot_verifier_module_handler(ngx_http_request_t *r)
2929
3030 ngx_int_t connection_status = check_connection (loc_conf -> redis .connection );
3131 if (connection_status == NGX_ERROR ) {
32- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "No cache connection found , creating a new connection" );
32+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "No cache connection, creating new connection" );
3333
3434 if (loc_conf -> redis .connection != NULL ) {
3535 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Cache connection error: %s" , loc_conf -> redis .connection -> errstr );
@@ -38,7 +38,7 @@ ngx_http_bot_verifier_module_handler(ngx_http_request_t *r)
3838 connection_status = reset_connection (loc_conf );
3939
4040 if (connection_status == NGX_ERROR ) {
41- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Unable to establish a connection to cache , bypassing" );
41+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Unable to establish cache connection, bypassing" );
4242
4343 if (loc_conf -> redis .connection != NULL ) {
4444 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Cache connection error: %s" , loc_conf -> redis .connection -> errstr );
@@ -49,55 +49,48 @@ ngx_http_bot_verifier_module_handler(ngx_http_request_t *r)
4949 }
5050 }
5151
52- ngx_str_t address ;
53- ngx_int_t address_status = ngx_http_bot_verifier_module_determine_address (r , & address );
52+ char address [INET_ADDRSTRLEN ];
53+ memset (address , '\0' , INET_ADDRSTRLEN );
54+ ngx_int_t address_status = ngx_http_bot_verifier_module_determine_address (r , address );
55+
5456 if (address_status == NGX_ERROR ) {
5557 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Unable to determine connected address, bypassing" );
5658 return NGX_DECLINED ;
5759 }
5860
59- ngx_int_t verification_status = lookup_verification_status (loc_conf -> redis .connection , & address );
61+ ngx_int_t verification_status = lookup_verification_status (loc_conf -> redis .connection , address );
6062 if (verification_status == NGX_ERROR ) {
6163 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Unable to lookup verification status, bypassing" );
6264 return NGX_DECLINED ;
6365 }
6466
65- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Lookup result %d" , verification_status );
66-
6767 if (verification_status == SUCCESS ) {
68- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Actor has already been verified , bypassing" );
68+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Cache returned valid actor , bypassing verification and allowing request " );
6969 return NGX_DECLINED ;
7070 }
7171
7272 if (verification_status == FAILURE ) {
73- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Actor previously failed verification, blocking request" );
73+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Cache returned invalid actor, bypassing verification and blocking request" );
7474 return NGX_HTTP_FORBIDDEN ;
7575 }
7676
7777 if (verification_status == ERROR ) {
78- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "There was an error looking up the actor, failing open " );
78+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Cache error" );
7979 return NGX_DECLINED ;
8080 }
8181
82- if (verification_status == NOT_FOUND ) {
83- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Actor has not been verified, initiating verification process" );
84- }
85-
8682 ngx_int_t ret = ngx_http_bot_verifier_module_identifies_as_known_bot (r , loc_conf );
8783
8884 if (ret == NGX_OK ) {
89- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Bot identity detected" );
90- ret = ngx_http_bot_verifier_module_verify_bot (r , loc_conf );
85+ ret = ngx_http_bot_verifier_module_verify_bot (r , loc_conf , address );
9186 if (ret == NGX_OK ) {
92- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Verification successful" );
93- persist_verification_status (loc_conf -> redis .connection , & address , ret , loc_conf -> redis .expiry );
87+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Verification successful, allowing request " );
88+ persist_verification_status (loc_conf -> redis .connection , address , ret , loc_conf -> redis .expiry );
9489 } else if (ret == NGX_DECLINED ) {
95- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Verification failed" );
96- persist_verification_status (loc_conf -> redis .connection , & address , ret , loc_conf -> redis .expiry );
90+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Verification failed, blocking request " );
91+ persist_verification_status (loc_conf -> redis .connection , address , ret , loc_conf -> redis .expiry );
9792 return NGX_HTTP_FORBIDDEN ;
9893 }
99- } else {
100- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Bot does not identify" );
10194 }
10295
10396 return NGX_OK ;
0 commit comments