Skip to Content
Menu

spam_domain_prevention()

Prevent blacklisted domains from accessing the website.

PHP April 1, 2021

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Security.php on line 240.

    7 Hooks

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Filters
    This function has no filter hooks available. Request one?

    Actions
    "nebula_spambot_prevention"
    "nebula_spambot_prevention"
    "nebula_spambot_prevention"
    "nebula_spambot_prevention"
    "nebula_spambot_prevention"
    "nebula_spambot_prevention"
    "qm/info"
    Need a new action hook? Request one here.

    PHP
            public function spam_domain_prevention(){
                $this->timer('Spam Domain Prevention');
    
                //Skip lookups if user has already been checked or for logged in users.
                if ( (isset($this->super->cookie['spam_domain']) && $this->super->cookie['spam_domain'] === false) || is_user_logged_in() ){
                    return false;
                }
    
                if ( $this->get_option('spam_domain_prevention') ){
                    $spam_domain_array = $this->get_spam_domain_list();
                    $ip_address = $this->get_ip_address();
    
                    if ( count($spam_domain_array) > 1 ){
                        //Check the Referrer
                        if ( isset($this->super->server['HTTP_REFERER']) && $this->contains(strtolower($this->super->server['HTTP_REFERER']), $spam_domain_array) ){
                            $this->ga_send_exception('(Security) Spam domain prevented. Referrer: ' . $this->super->server['HTTP_REFERER'], true, array('security_note' => 'Spam Referrer'));
                            do_action('nebula_spambot_prevention');
                            header('HTTP/1.1 403 Forbidden');
                            wp_die(
                                'Access forbidden.', //Message
                                '403 Forbidden', //Title
                                array(
                                    'response' => 403, //HTTP status code
                                    'back_link' => false //Remove the back link
                                )
                            );
                        }
    
                        //Check the Remote Host (the hostname of the client making the request)
                        if ( isset($this->super->server['REMOTE_HOST']) && $this->contains(strtolower($this->super->server['REMOTE_HOST']), $spam_domain_array) ){
                            $this->ga_send_exception('(Security) Spam domain prevented. Hostname: ' . $this->super->server['REMOTE_HOST'], true, array('security_note' => 'Spam Hostname'));
                            do_action('nebula_spambot_prevention');
                            header('HTTP/1.1 403 Forbidden');
                            wp_die(
                                'Access forbidden.', //Message
                                '403 Forbidden', //Title
                                array(
                                    'response' => 403, //HTTP status code
                                    'back_link' => false //Remove the back link
                                )
                            );
                        }
    
                        //Check the Server Name (the server's domain name)
                        if ( isset($this->super->server['SERVER_NAME']) && $this->contains(strtolower($this->super->server['SERVER_NAME']), $spam_domain_array) ){
                            $this->ga_send_exception('(Security) Spam domain prevented. Server Name: ' . $this->super->server['SERVER_NAME'], true, array('security_note' => 'Spam Server Name'));
                            do_action('nebula_spambot_prevention');
                            header('HTTP/1.1 403 Forbidden');
                            wp_die(
                                'Access forbidden.', //Message
                                '403 Forbidden', //Title
                                array(
                                    'response' => 403, //HTTP status code
                                    'back_link' => false //Remove the back link
                                )
                            );
                        }
    
                        //Check the Network Hostname (reverse DNS lookup of the client IP address)
                        if ( isset($ip_address) && $this->contains(strtolower(gethostbyaddr($ip_address)), $spam_domain_array) ){
                            $this->ga_send_exception('(Security) Spam domain prevented. Network Hostname: ' . $ip_address, true, array('security_note' => 'Spam Network Hostname'));
                            do_action('nebula_spambot_prevention');
                            header('HTTP/1.1 403 Forbidden');
                            wp_die(
                                'Access forbidden.', //Message
                                '403 Forbidden', //Title
                                array(
                                    'response' => 403, //HTTP status code
                                    'back_link' => false //Remove the back link
                                )
                            );
                        }
    
                        //Check Query String of the requested page URL. Note: Commented out as we are now checking the entire URI below
                        // if ( isset($_SERVER['QUERY_STRING']) && $this->contains(strtolower($_SERVER['QUERY_STRING']), $spam_domain_array) ){
                        //     $this->ga_send_exception('(Security) Spam domain prevented. Query String: ' . $_SERVER['QUERY_STRING'], true, array('security_note' => 'Spam Query'));
                        //     do_action('nebula_spambot_prevention');
                        //     header('HTTP/1.1 403 Forbidden');
                        //     wp_die(
                        //         'Access forbidden.', //Message
                        //         '403 Forbidden', //Title
                        //         array(
                        //             'response' => 403, //HTTP status code
                        //             'back_link' => false //Remove the back link
                        //         )
                        //     );
                        // }
    
                        //Check the entire URL of this requested page (including the query string)
                        if ( isset($_SERVER['REQUEST_URI']) && $this->contains(strtolower($_SERVER['REQUEST_URI']), $spam_domain_array) ){
                            $this->ga_send_exception('(Security) Spam domain prevented. URL: ' . $_SERVER['REQUEST_URI'], true, array('security_note' => 'Spam domain in the requested URL'));
                            do_action('nebula_spambot_prevention');
                            header('HTTP/1.1 403 Forbidden');
                            wp_die(
                                'Access forbidden.', //Message
                                '403 Forbidden', //Title
                                array(
                                    'response' => 403, //HTTP status code
                                    'back_link' => false //Remove the back link
                                )
                            );
                        }
                    } else {
                        $this->ga_send_exception('(Security) spammers.txt has no entries!', false);
                    }
    
                    $this->set_cookie('spam_domain', false);
                }
    
                do_action('qm/info', 'Spam Domain Check Performed');
                $this->timer('Spam Domain Prevention', 'end');
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?