Issues (27)

Security Analysis    no vulnerabilities found

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

api/index.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Teampass - a collaborative passwords manager.
4
 * ---
5
 * This library is distributed in the hope that it will be useful,
6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
 * ---
9
 *
10
 * @project   Teampass
11
 * @version    API
12
 *
13
 * @file      index.php
14
 * ---
15
 *
16
 * @author    Nils Laumaillé ([email protected])
17
 *
18
 * @copyright 2009-2025 Teampass.net
19
 *
20
 * @license   https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0
21
 * ---
22
 *
23
 * @see       https://www.teampass.net
24
 */
25
26
// Determine the protocol used
27
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://';
28
29
// Validate and filter the host
30
$host = filter_var($_SERVER['HTTP_HOST'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
31
32
// Allocate the correct CORS header
33
if ($host !== false) {
34
    header("Access-Control-Allow-Origin: $protocol$host");
35
} else {
36
    header("Access-Control-Allow-Origin: 'null'");
37
}
38
header("Content-Type: application/json; charset=UTF-8");
39
header("Access-Control-Allow-Methods: POST, GET");
40
header("Access-Control-Max-Age: 3600");
41
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
42
require __DIR__ . "/inc/bootstrap.php";
43
44
// sanitize url segments
45
$base = new BaseController();
0 ignored issues
show
The type BaseController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
$uri = $base->getUriSegments();
47
if (!is_array($uri)) {
48
    $uri = [$uri];  // ensure $uril is table
49
}
50
51
// Prepare DB password
52
if (defined('DB_PASSWD_CLEAR') === false) {
53
    define('DB_PASSWD_CLEAR', cryption(DB_PASSWD, '', 'decrypt', $SETTINGS)['string']);
54
}
55
56
// Do initial checks
57
$apiStatus = json_decode(apiIsEnabled(), true);
58
$jwtStatus = json_decode(verifyAuth(), true);
59
60
// Authorization handler
61
if ($uri[0] === 'authorize') {
62
    // Is API enabled in Teampass settings
63
    if ($apiStatus['error'] === false) {
64
        require API_ROOT_PATH . "/Controller/Api/AuthController.php";
65
        $objFeedController = new AuthController();
66
        $strMethodName = $uri[0] . 'Action';
67
        $objFeedController->{$strMethodName}();
68
    } else {
69
        // Error management
70
        errorHdl(
71
            $apiStatus['error_header'],
72
            json_encode(['error' => $apiStatus['error_message']])
73
        );
74
    }
75
} elseif ($jwtStatus['error'] === false) {
76
    // get infos from JWT parameters
77
    $userData = json_decode(getDataFromToken(), true);
78
79
    // define the position of controller in $uri
80
    $controller = $uri[0];
81
    $action = $uri[1];
82
    //error_log("API - controller: ".$controller." | action: ".$action." || ");//.print_r($userData, true)
83
    if ($userData['error'] === true) {
84
        // Error management
85
        errorHdl(
86
            $userData['error_header'],
87
            json_encode(['error' => $userData['error_message']])
88
        );
89
90
    // action related to USER
91
    } elseif ($controller === 'user') {
92
        require API_ROOT_PATH . "/Controller/Api/UserController.php";
93
        $objFeedController = new UserController();
94
        $strMethodName = (string) $action . 'Action';
95
        $objFeedController->{$strMethodName}();
96
97
    // action related to ITEM
98
    } elseif ($controller === 'item') {
99
        // Manage requested action
100
        itemAction(
101
            array_slice($uri, 1),
102
            $userData['data']
103
        ); 
104
105
    // action related to FOLDER
106
    } elseif ($controller === 'folder') {
107
        // Manage requested action
108
        folderAction(
109
            array_slice($uri, 1),
110
            $userData['data']
111
        );
112
    } else {
113
        errorHdl(
114
            "HTTP/1.1 404 Not Found",
115
            json_encode(['error' => 'No action provided'])
116
        );
117
    }
118
// manage error case
119
} else {
120
    if ($jwtStatus['error'] === true) {
121
        errorHdl(
122
            $jwtStatus['error_header'],
123
            json_encode(['error' => $jwtStatus['error_message']])
124
        );
125
    } else {
126
        errorHdl(
127
            "HTTP/1.1 404 Not Found",
128
            json_encode(['error' => 'Access denied'])
129
        );
130
    }
131
}