Issues (10)

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.

src/Command/DaemonRunCommand.php (2 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
declare(strict_types=1);
4
5
namespace PHPFastCGI\FastCGIDaemon\Command;
6
7
use PHPFastCGI\FastCGIDaemon\DaemonInterface;
8
use PHPFastCGI\FastCGIDaemon\DaemonOptions;
9
use PHPFastCGI\FastCGIDaemon\DaemonOptionsInterface;
10
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainerInterface;
11
use PHPFastCGI\FastCGIDaemon\KernelInterface;
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\Console\Logger\ConsoleLogger;
17
18
class DaemonRunCommand extends Command
19
{
20
    const DEFAULT_NAME        = 'run';
21
    const DEFAULT_DESCRIPTION = 'Run the FastCGI daemon';
22
23
    /**
24
     * @var KernelInterface
25
     */
26
    private $kernel;
27
28
    /**
29
     * @var DriverContainerInterface
30
     */
31
    private $driverContainer;
32
33
    /**
34
     * @var DaemonInterface
35
     */
36
    private $daemon;
37
38
    /**
39
     * Constructor.
40
     *
41
     * @param KernelInterface          $kernel          The kernel to be given to the daemon
42
     * @param DriverContainerInterface $driverContainer The driver container
43
     * @param string                   $name            The name of the daemon run command
44
     * @param string                   $description     The description of the daemon run command
45
     */
46
    public function __construct(KernelInterface $kernel, DriverContainerInterface $driverContainer, $name = null, $description = null)
47
    {
48
        $this->kernel          = $kernel;
49
        $this->driverContainer = $driverContainer;
50
        $this->daemon          = null;
51
52
        $name        = $name        ?: self::DEFAULT_NAME;
53
        $description = $description ?: self::DEFAULT_DESCRIPTION;
54
55
        parent::__construct($name);
56
57
        $this
58
            ->setDescription($description)
59
            ->addOption('port',          null, InputOption::VALUE_OPTIONAL, 'TCP port to listen on (if not present, daemon will listen on FCGI_LISTENSOCK_FILENO)')
60
            ->addOption('host',          null, InputOption::VALUE_OPTIONAL, 'TCP host to listen on')
61
            ->addOption('fd',            null, InputOption::VALUE_OPTIONAL, 'File descriptor to listen on - defaults to FCGI_LISTENSOCK_FILENO', DaemonInterface::FCGI_LISTENSOCK_FILENO)
62
            ->addOption('request-limit', null, InputOption::VALUE_OPTIONAL, 'The maximum number of requests to handle before shutting down')
63
            ->addOption('memory-limit',  null, InputOption::VALUE_OPTIONAL, 'The memory limit on the daemon instance before shutting down')
64
            ->addOption('time-limit',    null, InputOption::VALUE_OPTIONAL, 'The time limit on the daemon in seconds before shutting down')
65
            ->addOption('auto-shutdown', null, InputOption::VALUE_NONE,     'Perform a graceful shutdown after receiving a 5XX HTTP status code')
66
            ->addOption('driver',        null, InputOption::VALUE_OPTIONAL, 'The implementation of the FastCGI protocol to use', 'userland');
67
    }
68
69
    /**
70
     * Creates a daemon configuration object from the Symfony command input and
71
     * output objects.
72
     *
73
     * @param InputInterface  $input  The  Symfony command input
74
     * @param OutputInterface $output The Symfony command output
75
     *
76
     * @return DaemonOptionsInterface The daemon configuration
77
     */
78
    private function getDaemonOptions(InputInterface $input, OutputInterface $output): DaemonOptionsInterface
79
    {
80
        $logger = new ConsoleLogger($output);
81
82
        $requestLimit = $input->getOption('request-limit') ?: DaemonOptions::NO_LIMIT;
83
        $memoryLimit  = $input->getOption('memory-limit')  ?: DaemonOptions::NO_LIMIT;
84
        $timeLimit    = $input->getOption('time-limit')    ?: DaemonOptions::NO_LIMIT;
85
        $autoShutdown = $input->getOption('auto-shutdown');
86
87
        return new DaemonOptions([
88
            DaemonOptions::LOGGER        => $logger,
89
            DaemonOptions::REQUEST_LIMIT => $requestLimit,
90
            DaemonOptions::MEMORY_LIMIT  => $memoryLimit,
91
            DaemonOptions::TIME_LIMIT    => $timeLimit,
92
            DaemonOptions::AUTO_SHUTDOWN => $autoShutdown,
93
        ]);
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    protected function execute(InputInterface $input, OutputInterface $output)
100
    {
101
        $port = $input->getOption('port');
102
        $host = $input->getOption('host');
103
        $fd = $input->getOption('fd');
104
105
        $daemonOptions = $this->getDaemonOptions($input, $output);
106
107
        $driver        = $input->getOption('driver');
108
        $daemonFactory = $this->driverContainer->getFactory($driver);
109
110
        if (null !== $port) {
111
            // If we have the port, create a TCP daemon
112
            $this->daemon = $daemonFactory->createTcpDaemon($this->kernel, $daemonOptions, $host ?: 'localhost', (int) $port);
0 ignored issues
show
$daemonOptions of type object<PHPFastCGI\FastCG...DaemonOptionsInterface> is not a sub-type of object<PHPFastCGI\FastCGIDaemon\DaemonOptions>. It seems like you assume a concrete implementation of the interface PHPFastCGI\FastCGIDaemon\DaemonOptionsInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
113
        } elseif (null !== $host) {
114
            // If we have the host but not the port, we cant create a TCP daemon - throw exception
115
            throw new \InvalidArgumentException('TCP port option must be set if host option is set');
116
        } else {
117
            // With no host or port, listen on FCGI_LISTENSOCK_FILENO (default)
118
            $this->daemon = $daemonFactory->createDaemon($this->kernel, $daemonOptions, (int) $fd);
0 ignored issues
show
$daemonOptions of type object<PHPFastCGI\FastCG...DaemonOptionsInterface> is not a sub-type of object<PHPFastCGI\FastCGIDaemon\DaemonOptions>. It seems like you assume a concrete implementation of the interface PHPFastCGI\FastCGIDaemon\DaemonOptionsInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
119
        }
120
121
        $this->daemon->run();
122
    }
123
124
    /**
125
     * Flag the daemon for shutdown.
126
     */
127
    public function flagShutdown()
128
    {
129
        if (null === $this->daemon) {
130
            throw new \RuntimeException('There is no daemon running');
131
        }
132
133
        $this->daemon->flagShutdown();
134
    }
135
}
136