Prevent Host header attack

Viewed 31432

I scanned my website whit Acunetix Web Vulnerability Scanner and I got Host Header attack vulnerability.

In description says that I writed

(_SERVER["HTTP_HOST"] in PHP

but i didn't and i don't know how to fix this.

Here is my header of affected file

<?php
    include 'core/init.php';

    if($user->is_loggedin()){
        redirect('index.php');
        exit();
    }

    if($detect->isMobile()){
        redirect('http://m.website.com/prijava.php');
        exit();
    }

    if(isset($_POST['prijava'])){
        $post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
        if(time() - $user->failTime($post['email']) < 600 && $user->failCount($post['email']) >= 3){
            $err = '<p style="color:red;">Račun vam je zaključan na 10 minuta.</p>';
        }else{          
            if(empty($post['email']) || empty($post['password'])){
                $err = '';
            }elseif($id = $user->prijava($post['email'], $post['password'])){
                if($user->isActive($post['email'])){                    
                    $_SESSION['user'] = $id['id'];
                    $user->resetFail();
                    redirect('index.php');
                    exit();
                }else{
                    $err = '<p style="color:red;">Korisnički račun nije aktiviran.</p>';    
                }           
            }else{
                if($user->checkMail($post['email'])){
                    if($user->storeFail($post['email'])){
                        $err = '<p style="color:red;">Lozinka i email se ne poklapaju.</p>';
                    }
                }else{
                    $err = '<p style="color:red;">Lozinka i email se ne poklapaju.</p>';
                }           
            }
        }       
    }
?>

And html

<head>
    <meta charset="UTF-8">
    <title>Prijava</title>
    <link rel="shortcut icon" href="images/favicon.png" type="image/png">
    <link rel="stylesheet" type="text/css" href="css/sign.css?<?php echo time(); ?>">       
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>

Here is image of Vulnerability description:

enter image description here

To sum up, how can I protect my website, thank you.

2 Answers
Related