Completed
Pull Request — master (#137)
by Philipp
04:15
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
if (!isset($_SESSION)) {
3
    session_start();
4
}
5
6
if (!isset($_SESSION['username'])) {
7
    if (isset($_SERVER['HTTP_REFERER'])) {
8
        error_log("auth.php referred by " . $_SERVER['HTTP_REFERER']);
9
    }
10
    $header = 'Location: login.php';
11
    $separator = '?';
12 View Code Duplication
    if (isset($_REQUEST['lang'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
        $header = $header . $separator . 'lang=' . $_REQUEST['lang'];
14
        $separator = '&';
15
    }
16 View Code Duplication
    if (isset($_REQUEST['pin'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
        $header = $header . $separator . 'pin=' . $_REQUEST['pin'];
18
        $separator = '&';
19
    }
20
    header($header);
0 ignored issues
show
Security Response Splitting introduced by
$header can contain request data and is used in response header context(s) leading to a potential security vulnerability.

2 paths for user data to reach this point

  1. Path: Read from $_REQUEST, and $header is assigned in auth.php on line 13
  1. Read from $_REQUEST, and $header is assigned
    in auth.php on line 13
  2. Path: Read from $_REQUEST, and $header is assigned in auth.php on line 17
  1. Read from $_REQUEST, and $header is assigned
    in auth.php on line 17

Response Splitting Attacks

Allowing an attacker to set a response header, opens your application to response splitting attacks; effectively allowing an attacker to send any response, he would like.

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
21
22
    exit;
23
}
24