GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (421)

Security Analysis    not enabled

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

  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  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.
  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.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
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.

phpmyfaq/api.php (10 issues)

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
3
/**
4
 * The REST API.
5
 *
6
 *
7
 *
8
 * This Source Code Form is subject to the terms of the Mozilla Public License,
9
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
10
 * obtain one at http://mozilla.org/MPL/2.0/.
11
 *
12
 * @package phpMyFAQ
13
 * @author Thorsten Rinne <[email protected]>
14
 * @copyright 2009-2019 phpMyFAQ Team
15
 * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
16
 * @link https://www.phpmyfaq.de
17
 * @since 2009-09-03
18
 */
19
20
define('IS_VALID_PHPMYFAQ', null);
21
22
use phpMyFAQ\Attachment\Factory;
23
use phpMyFAQ\Category;
24
use phpMyFAQ\Comment;
25
use phpMyFAQ\Faq;
26
use phpMyFAQ\Filter;
27
use phpMyFAQ\Helper\HttpHelper;
28
use phpMyFAQ\Language;
29
use phpMyFAQ\Language\Plurals;
30
use phpMyFAQ\News;
31
use phpMyFAQ\Search;
32
use phpMyFAQ\Search\Resultset;
33
use phpMyFAQ\Services;
34
use phpMyFAQ\Strings;
35
use phpMyFAQ\Tags;
36
use phpMyFAQ\User\CurrentUser;
37
use phpMyFAQ\Utils;
38
39
//
40
// Bootstrapping
41
//
42
require 'src/Bootstrap.php';
43
44
//
45
// Send headers
46
//
47
$http = new HttpHelper();
48
$http->setContentType('application/json');
49
$http->addHeader();
50
51
//
52
// Set user permissions
53
//
54
$currentUser = -1;
55
$currentGroups = array(-1);
56
$auth = false;
57
58
$action = Filter::filterInput(INPUT_GET, 'action', FILTER_SANITIZE_STRING);
59
$language = Filter::filterInput(INPUT_GET, 'lang', FILTER_SANITIZE_STRING, 'en');
60
$categoryId = Filter::filterInput(INPUT_GET, 'categoryId', FILTER_VALIDATE_INT);
61
$recordId = Filter::filterInput(INPUT_GET, 'recordId', FILTER_VALIDATE_INT);
62
$tagId = Filter::filterInput(INPUT_GET, 'tagId', FILTER_VALIDATE_INT);
63
64
$faqusername = Filter::filterInput(INPUT_POST, 'faqusername', FILTER_SANITIZE_STRING);
65
$faqpassword = Filter::filterInput(INPUT_POST, 'faqpassword', FILTER_SANITIZE_STRING);
66
67
//
68
// Get language (default: english)
69
//
70
$Language = new Language($faqConfig);
71
$language = $Language->setLanguage($faqConfig->get('main.languageDetection'), $faqConfig->get('main.language'));
72
73
//
74
// Set language
75
//
76
if (Language::isASupportedLanguage($language)) {
77
    require LANGUAGE_DIR.'/language_'.$language.'.php';
78
} else {
79
    require LANGUAGE_DIR.'/language_en.php';
80
}
81
$faqConfig->setLanguage($Language);
82
83
$plr = new Plurals($PMF_LANG);
84
Strings::init($language);
85
86
//
87
// Set empty result
88
$result = [];
89
90
//
91
// Check if user is already authenticated
92
//
93
if (is_null($faqusername) && is_null($faqpassword)) {
94
95
    $currentUser = CurrentUser::getFromCookie($faqConfig);
96
    // authenticate with session information
97
    if (!$currentUser instanceof CurrentUser) {
98
        $currentUser = CurrentUser::getFromSession($faqConfig);
99
    }
100
    if ($currentUser instanceof CurrentUser) {
101
        $auth = true;
102
    } else {
103
        $currentUser = new CurrentUser($faqConfig);
104
    }
105
}
106
107
//
108
// Handle actions
109
//
110
switch ($action) {
111
112
    case 'getVersion':
113
        $result = ['version' => $faqConfig->get('main.currentVersion')];
114
        break;
115
116
    case 'getApiVersion':
117
        $result = ['apiVersion' => $faqConfig->get('main.currentApiVersion')];
118
        break;
119
120
    case 'getCount':
121
        $faq = new Faq($faqConfig);
122
        $faq->setUser($currentUser);
0 ignored issues
show
It seems like $currentUser can also be of type object<phpMyFAQ\User\CurrentUser>; however, phpMyFAQ\Faq::setUser() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
123
        $faq->setGroups($currentGroups);
124
        $result = ['faqCount' => $faq->getNumberOfRecords($language)];
125
        break;
126
127
    case 'getDefaultLanguage':
128
        $result = ['defaultLanguage' => $faqConfig->getLanguage()->getLanguage()];
129
        break;
130
131
    case 'search':
132
        $faq = new Faq($faqConfig);
133
        $faq->setUser($currentUser);
0 ignored issues
show
It seems like $currentUser can also be of type object<phpMyFAQ\User\CurrentUser>; however, phpMyFAQ\Faq::setUser() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
134
        $faq->setGroups($currentGroups);
135
        $user = new CurrentUser($faqConfig);
136
        $search = new Search($faqConfig);
137
        $search->setCategory(new Category($faqConfig));
138
139
        $faqSearchResult = new Resultset($user, $faq, $faqConfig);
140
        $searchString = Filter::filterInput(INPUT_GET, 'q', FILTER_SANITIZE_STRIPPED);
141
        try {
142
            $searchResults = $search->search($searchString, false);
143
            $url = $faqConfig->getDefaultUrl().'index.php?action=faq&cat=%d&id=%d&artlang=%s';
144
            $faqSearchResult->reviewResultset($searchResults);
0 ignored issues
show
It seems like $searchResults defined by $search->search($searchString, false) on line 142 can also be of type resource; however, phpMyFAQ\Search\Resultset::reviewResultset() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
145
            foreach ($faqSearchResult->getResultset() as $data) {
146
                $data->answer = html_entity_decode(strip_tags($data->answer), ENT_COMPAT, 'utf-8');
147
                $data->answer = Utils::makeShorterText($data->answer, 12);
148
                $data->link = sprintf($url, $data->category_id, $data->id, $data->lang);
149
                $result[] = $data;
150
            }
151
        } catch (Search\Exception $e) {
152
            $result = ['error' => $e->getMessage()];
153
        }
154
        break;
155
156
    case 'getCategories':
157
        $category = new Category($faqConfig, $currentGroups, true);
158
        $category->setUser($currentUser);
0 ignored issues
show
It seems like $currentUser can also be of type object<phpMyFAQ\User\CurrentUser>; however, phpMyFAQ\Category::setUser() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
159
        $category->setGroups($currentGroups);
160
        $result = array_values($category->getAllCategories());
161
        break;
162
163
    case 'getFaqs':
164
        $faq = new Faq($faqConfig);
165
        $faq->setUser($currentUser);
0 ignored issues
show
It seems like $currentUser can also be of type object<phpMyFAQ\User\CurrentUser>; however, phpMyFAQ\Faq::setUser() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
166
        $faq->setGroups($currentGroups);
167
        $result = $faq->getAllRecordPerCategory($categoryId);
168
        break;
169
170
    case 'getFAQsByTag':
171
        $tags = new Tags($faqConfig);
172
        $recordIds = $tags->getRecordsByTagId($tagId);
173
        $faq = new Faq($faqConfig);
174
        $faq->setUser($currentUser);
0 ignored issues
show
It seems like $currentUser can also be of type object<phpMyFAQ\User\CurrentUser>; however, phpMyFAQ\Faq::setUser() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
175
        $faq->setGroups($currentGroups);
176
        $result = $faq->getRecordsByIds($recordIds);
177
        break;
178
179
    case 'getFaq':
180
        $faq = new Faq($faqConfig);
181
        $faq->setUser($currentUser);
0 ignored issues
show
It seems like $currentUser can also be of type object<phpMyFAQ\User\CurrentUser>; however, phpMyFAQ\Faq::setUser() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
182
        $faq->setGroups($currentGroups);
183
        $faq->getRecord($recordId);
184
        $result = $faq->faqRecord;
185
        break;
186
187
    case 'getComments':
188
        $comment = new Comment($faqConfig);
189
        $result = $comment->getCommentsData($recordId, 'faq');
190
        break;
191
192
    case 'getAllFaqs':
193
        $faq = new Faq($faqConfig);
194
        $faq->setUser($currentUser);
0 ignored issues
show
It seems like $currentUser can also be of type object<phpMyFAQ\User\CurrentUser>; however, phpMyFAQ\Faq::setUser() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
195
        $faq->setGroups($currentGroups);
196
        $faq->getAllRecords(FAQ_SORTING_TYPE_CATID_FAQID, ['lang' => $language]);
197
        $result = $faq->faqRecords;
198
        break;
199
200
    case 'getFaqAsPdf':
201
        $service = new Services($faqConfig);
202
        $service->setFaqId($recordId);
203
        $service->setLanguage($language);
204
        $service->setCategoryId($categoryId);
205
206
        $result = ['pdfUrl' => $service->getPdfApiLink()];
207
        break;
208
209
    case 'getAttachmentsFromFaq':
210
        $attachments = $result = [];
211
        try {
212
            $attachments = Factory::fetchByRecordId($faqConfig, $recordId);
213
        } catch (\phpMyFAQ\Attachment\Exception $e) {
214
            $result = ['error' => $e->getMessage()];
215
        }
216
        foreach ($attachments as $attachment) {
217
            $result[] = [
218
                'filename' => $attachment->getFilename(),
219
                'url' => $faqConfig->getDefaultUrl().$attachment->buildUrl(),
220
            ];
221
        }
222
        break;
223
224 View Code Duplication
    case 'getPopular':
225
        $faq = new Faq($faqConfig);
226
        $faq->setUser($currentUser);
0 ignored issues
show
It seems like $currentUser can also be of type object<phpMyFAQ\User\CurrentUser>; however, phpMyFAQ\Faq::setUser() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
227
        $faq->setGroups($currentGroups);
228
        $result = array_values($faq->getTopTenData(PMF_NUMBER_RECORDS_TOPTEN));
229
        break;
230
231 View Code Duplication
    case 'getLatest':
232
        $faq = new Faq($faqConfig);
233
        $faq->setUser($currentUser);
0 ignored issues
show
It seems like $currentUser can also be of type object<phpMyFAQ\User\CurrentUser>; however, phpMyFAQ\Faq::setUser() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
234
        $faq->setGroups($currentGroups);
235
        $result = array_values($faq->getLatestData(PMF_NUMBER_RECORDS_LATEST));
236
        break;
237
238
    case 'getNews':
239
        $news = new News($faqConfig);
240
        $result = $news->getLatestData(false, true, true);
241
        break;
242
243
    case 'getPopularSearches':
244
        $search = new Search($faqConfig);
245
        $result = $search->getMostPopularSearches(7, true);
246
        break;
247
248
    case 'getPopularTags':
249
        $tags = new Tags($faqConfig);
250
        $result = $tags->getPopularTagsAsArray(16);
251
        break;
252
253
    case 'login':
254
        $currentUser = new CurrentUser($faqConfig);
255
        if ($currentUser->login($faqusername, $faqpassword)) {
256
            if ($currentUser->getStatus() != 'blocked') {
257
                $auth = true;
258
                $result = [
259
                    'loggedin' => true
260
                ];
261
            } else {
262
                $result = [
263
                    'loggedin' => false,
264
                    'error' => $PMF_LANG['ad_auth_fail'].' ('.$faqusername.')'
265
                ];
266
            }
267
        } else {
268
            $result = [
269
                'loggedin' => false,
270
                'error' => $PMF_LANG['ad_auth_fail']
271
            ];
272
        }
273
        break;
274
}
275
276
//
277
// Check if FAQ should be secured
278
//
279
if (!$auth && $faqConfig->get('security.enableLoginOnly')) {
280
    $http->sendJsonWithHeaders(
281
        [
282
            'error' => 'You are not allowed to view this content.'
283
        ]
284
    );
285
    $http->sendStatus(403);
286
}
287
288
$http->sendJsonWithHeaders($result);
289