for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Teampass - a collaborative passwords manager.
* ---
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @project Teampass API
* @file BaseController.php
* @author Nils Laumaillé ([email protected])
* @copyright 2009-2022 Teampass.net
* @license https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0
* @see https://www.teampass.net
*/
class BaseController
{
* __call magic method.
public function __call($name, $arguments)
$this->sendOutput('', array('HTTP/1.1 404 Not Found'));
}
* Get URI elements.
* @return array
protected function getUriSegments()
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri = explode( '/', $uri );
return $uri;
* Get querystring params.
protected function getQueryStringParams()
return parse_str($_SERVER['QUERY_STRING'], $query);
parse_str($_SERVER['QUERY_STRING'], $query)
null
This check looks for function or method calls that always return null and whose return value is used.
class A { function getObject() { return null; } } $a = new A(); if ($a->getObject()) {
The method getObject() can return nothing but null, so it makes no sense to use the return value.
getObject()
The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
return parse_str($_SERVE...QUERY_STRING'], $query)
void
array
$_SERVER['QUERY_STRING']
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;
* Send API output.
* @param mixed $data
* @param string $httpHeader
protected function sendOutput($data, $httpHeaders=array())
header_remove('Set-Cookie');
if (is_array($httpHeaders) && count($httpHeaders)) {
foreach ($httpHeaders as $httpHeader) {
header($httpHeader);
echo $data;
exit;
exit
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.