Issues (125)

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/Dispatcher.php (1 issue)

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
namespace Basis;
4
5
use Basis\Context;
6
use Exception;
7
use GuzzleHttp\Client;
8
use OpenTelemetry\Tracing\Tracer;
9
10
class Dispatcher
11
{
12
    use Toolkit;
13
14 1
    public function dispatch(string $job, array $params = [], string $service = null, $context = null)
15
    {
16 1
        return $this->dispatchAsync($job, $params, $service, $context)->wait();
17
    }
18
19 1
    public function dispatchAsync(string $job, array $params = [], string $service = null, $context = null)
20
    {
21 1
        if ($service === null) {
22 1
            $service = $this->getServiceName($job);
23
        }
24
25 1
        $url = $this->getUrl($service, $job);
26 1 View Code Duplication
        if (is_array($params) && array_key_exists('eventId', $params)) {
27
            $url .= '/'.$params['eventId'];
28
        }
29
30 1
        if (!$context) {
31 1
            $context = $this->getContext();
32
        }
33
34 1
        $span = $this->get(Tracer::class)
35 1
            ->getActiveSpan()
36 1
            ->getSpanContext();
37
38 1
        $response = $this->get(Client::class)->postAsync($url, [
39
            'multipart' => [
40
                [
41 1
                    'name' => 'rpc',
42
                    'contents' => json_encode([
43 1
                        'job'     => $job,
44 1
                        'params'  => $params,
45 1
                        'context' => $context,
46
                        'span' => [
47 1
                            'traceId' => $span->getTraceId(),
48 1
                            'spanId' => $span->getSpanId(),
49
                        ],
50
                    ])
51
                ]
52
            ]
53
        ]);
54
55
        return $response->then(function ($response) {
56 1
            $contents = $response->getBody();
57 1
            if (!$contents) {
58
                throw new Exception("Host $host ($service) is unreachable");
59
            }
60
    
61 1
            $result = json_decode($contents);
62 1
            if (!$result || !$result->success) {
63
                $exception = new Exception($result->message ?: $contents);
64
                if ($result->trace) {
65
                    $exception->remoteTrace = $result->trace;
0 ignored issues
show
The property remoteTrace does not seem to exist in Exception.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
66
                }
67
                throw $exception;
68
            }
69
    
70 1
            return $result->data;
71 1
        });
72
    }
73
74 1
    protected function getContext() : array
75
    {
76 1
        $context = get_object_vars($this->get(Context::class));
77
    
78 1
        if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) {
79
            $context['host'] = $_SERVER['HTTP_X_REAL_IP'];
80
        }
81
82 1
        if (array_key_exists('HTTP_X_SESSION', $_SERVER)) {
83
            $context['session'] = $_SERVER['HTTP_X_SESSION'];
84
        }
85
86 1
        return $context;
87
    }
88
89 1
    protected function getServiceName(string $job) : string
90
    {
91 1
        return explode('.', $job)[0];
92
    }
93
94 1
    protected function getUrl(string $service, string $job) : string
95
    {
96 1
        $host = $this->get(Service::class)->getHost($service)->address;
97 1
        return "http://$host/api/" . str_replace('.', '/', $job);
98
    }
99
100
    public function send(string $job, array $params = [], string $service = null, $context = null)
101
    {
102
        if ($service === null) {
103
            $service = $this->getServiceName($job);
104
        }
105
106
        $url = $this->getUrl($service, $job);
107 View Code Duplication
        if (is_array($params) && array_key_exists('eventId', $params)) {
108
            $url .= '/'.$params['eventId'];
109
        }
110
111
        if (!$context) {
112
            $context = $this->getContext();
113
        }
114
115
        $rpc = [
116
            'context' => $context,
117
            'job'     => $job,
118
            'params'  => $params,
119
        ];
120
121
        $content = 'rpc='.urlencode(json_encode($rpc));
122
123
        $parts = parse_url($url);
124
        $port = isset($parts['port']) ? $parts['port'] : 80;
125
        $fp = fsockopen($parts['host'], $port, $errno, $errstr, 30);
126
127
        if (!$fp) {
128
            return false;
129
        }
130
131
        $parts = [
132
            "POST " . $parts['path'] . " HTTP/1.1",
133
            "Host: " . $parts['host'],
134
        ];
135
136
        if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) {
137
            $parts[] = "X-Real-Ip: ".$_SERVER['HTTP_X_REAL_IP'];
138
        }
139
        if (array_key_exists('HTTP_X_SESSION', $_SERVER)) {
140
            $parts[] = "X-Session: ".$_SERVER['HTTP_X_SESSION'];
141
        }
142
143
        $parts = array_merge($parts, [
144
            "Content-Type: application/x-www-form-urlencoded",
145
            "Content-Length: " . strlen($content),
146
            "Connection: Close",
147
            "",
148
            isset($content) ? $content : '',
149
        ]);
150
151
        fwrite($fp, implode("\r\n", $parts));
152
        fclose($fp);
153
154
        return true;
155
    }
156
}
157