<commit_before><?php

include 'config.php';
include 'functions.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!isset($_GET['token']) || $_GET['token'] === null) {
        // Not authenticated
    $error['status'] = '401';
        $error['description'] = ' Unauthorized';
        header('Content-Type: application/json');
        echo json_encode($error);
        http_response_code(401);
        exit();
    }
// Authenticated
$token = $mysqli->real_escape_string($_GET['token']);
    $sql = "SELECT * FROM tokens WHERE token = '$token'";
    if (!$result = $mysqli->query($sql)) {
        if ($debug) {
            echo "Error: Our query failed to execute and here is why: \n";
            echo 'Query: '.$sql."\n";
            echo 'Errno: '.$mysqli->errno."\n";
            echo 'Error: '.$mysqli->error."\n";
            exit();
        } else {
            echo 'The connection to the database failed';
        }
    }
    if ($result->num_rows === 0) {
        $error['status'] = '401';
        $error['description'] = ' Unauthorized';
        header('Content-Type: application/json');
        echo json_encode($error);
        http_response_code(401);
        exit();
    }
    $token = $result->fetch_assoc();

    updateActivity($activityType, $activityTitle, $activityOrigin);
} elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
    if (!isset($_GET['token']) || $_GET['token'] === null) {
        // Not authenticated
    $error['status'] = '401';
        $error['description'] = ' Unauthorized';
        header('Content-Type: application/json');
        echo json_encode($error);
        http_response_code(401);
        exit();
    }
// Authenticated
$token = $mysqli->real_escape_string($_GET['token']);
    $sql = "SELECT * FROM tokens WHERE token = '$token'";
    if (!$result = $mysqli->query($sql)) {
        if ($debug) {
            echo "Error: Our query failed to execute and here is why: \n";
            echo 'Query: '.$sql."\n";
            echo 'Errno: '.$mysqli->errno."\n";
            echo 'Error: '.$mysqli->error."\n";
            exit();
        } else {
            echo 'The connection to the database failed';
        }
    }
    if ($result->num_rows === 0) {
        $error['status'] = '401';
        $error['description'] = ' Unauthorized';
        header('Content-Type: application/json');
        echo json_encode($error);
        http_response_code(401);
        exit();
    }
    $token = $result->fetch_assoc();
// Insert activity
} else {
    echo 'ERROR';
}<commit_msg>Security checks<commit_after><?php

include 'config.php';
include 'functions.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!isset($_GET['token']) || $_GET['token'] === null) {
        // Not authenticated
    $error['status'] = '401';
        $error['description'] = ' Unauthorized';
        header('Content-Type: application/json');
        echo json_encode($error);
        http_response_code(401);
        exit();
    }
// Authenticated
$token = $mysqli->real_escape_string($_GET['token']);
    $sql = "SELECT * FROM tokens WHERE token = '$token'";
    if (!$result = $mysqli->query($sql)) {
        if ($debug) {
            echo "Error: Our query failed to execute and here is why: \n";
            echo 'Query: '.$sql."\n";
            echo 'Errno: '.$mysqli->errno."\n";
            echo 'Error: '.$mysqli->error."\n";
            exit();
        } else {
            echo 'The connection to the database failed';
        }
    }
    if ($result->num_rows === 0) {
        $error['status'] = '401';
        $error['description'] = ' Unauthorized';
        header('Content-Type: application/json');
        echo json_encode($error);
        http_response_code(401);
        exit();
    }
    $token = $result->fetch_assoc();
if (!isset($_POST['activityType']) || !isset($_POST['activityTitle'])){
  $error['status'] = '400';
  $error['description'] = ' Bad Request';
  header('Content-Type: application/json');
  echo json_encode($error);
  http_response_code(400);
  exit();
}
    updateActivity($activityType, $activityTitle, $activityOrigin);
} elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
    if (!isset($_GET['token']) || $_GET['token'] === null) {
        // Not authenticated
    $error['status'] = '401';
        $error['description'] = ' Unauthorized';
        header('Content-Type: application/json');
        echo json_encode($error);
        http_response_code(401);
        exit();
    }
// Authenticated
$token = $mysqli->real_escape_string($_GET['token']);
    $sql = "SELECT * FROM tokens WHERE token = '$token'";
    if (!$result = $mysqli->query($sql)) {
        if ($debug) {
            echo "Error: Our query failed to execute and here is why: \n";
            echo 'Query: '.$sql."\n";
            echo 'Errno: '.$mysqli->errno."\n";
            echo 'Error: '.$mysqli->error."\n";
            exit();
        } else {
            echo 'The connection to the database failed';
        }
    }
    if ($result->num_rows === 0) {
        $error['status'] = '401';
        $error['description'] = ' Unauthorized';
        header('Content-Type: application/json');
        echo json_encode($error);
        http_response_code(401);
        exit();
    }
    $token = $result->fetch_assoc();
// Insert activity
} else {
  $error['status'] = '405';
  $error['description'] = ' Method Not Allowed';
  header('Content-Type: application/json');
  echo json_encode($error);
  http_response_code(405);
  exit();
}
{'fraction_non_alphanumeric': 0.1870201096892139, 'fraction_numerical': 0.01170018281535649, 'mean_word_length': 2.509300833867864, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1133677', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1636, 'n_words': 367}