Issues (14)

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/Dashbot.php (4 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
namespace Apix\Log;
4
5
use Apix\Log\Emitter\EmitterInterface as LogEmitter;
6
use Psr\Log\InvalidArgumentException;
7
8
/**
9
 * Dashbot logger for Apix Log.
10
 *
11
 * @see https://www.dashbot.io/sdk/generic
12
 */
13
class Dashbot extends AbstractTracker
14
{
15
    const TRACKER_URL =
16
        'https://tracker.dashbot.io/track?platform=%s&v=%s&type=%s&apiKey=%s';
17
18
    const TRANSPORTER_CMD =
19
        'curl -X POST -d %1$s \'%2$s\' -H \'Content-Type: application/json\'';
20
21
    // const DEFAULT_PARAMS = array(
22
    private $DEFAULT_PARAMS = array(
23
        'platform' => 'generic',    // Either generic, facebook, slack, kik
24
        'v' => '0.7.4-rest',        // API Version
25
        'type' => null,             // Hit type (required)
26
        'apiKey' => null,           // API key (required)
27
    );
28
29
    /**
30
     * Constructor.
31
     *
32
     * @param
33
     */
34 60
    public function __construct(
35
        $mixed, LogEmitter $emitter = null, LogFormatter $formatter = null
36
    ) {
37 60
        $this->setEmitter(
38 60
            $emitter ? $emitter : new Emitter\Async(self::TRANSPORTER_CMD),
39 60
            $formatter ? $formatter : new LogFormatter\Json()
40 45
        );
41 60
        $this->emitter->setParams($this->DEFAULT_PARAMS);
42
43 60
        if (is_array($mixed) && isset($mixed['apiKey'])) {
44 60
            $this->emitter->addParams($mixed);
45 47
        } elseif (is_string($mixed)) {
46 4
            $this->emitter->setParam('apiKey', $mixed);
47 3
        } else {
48 4
            throw new InvalidArgumentException(sprintf(
49 4
                '%s expects `apiKey` to be set, got: %s.',
50 4
                __CLASS__, json_encode($mixed)
51 3
            ));
52
        }
53 60
    }
54
55
    /**
56
     * Sets the platform (format).
57
     *
58
     * @see https://www.dashbot.io/sdk/template
59
     *
60
     * @param string $platform Either 'generic', 'facebook', 'slack', 'kik'
61
     *
62
     * @return self
63
     */
64 16
    public function setPlatform($platform)
65
    {
66 16
        $this->emitter->setParam('platform', $platform);
67
68 16
        return $this;
69
    }
70
71
    /**
72
     * Sets a global tag (used to combined metrics).
73
     *
74
     * @see https://www.dashbot.io/sdk/template
75
     *
76
     * @param array  $entries
0 ignored issues
show
There is no parameter named $entries. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
77
     * @param string $local_tag
0 ignored issues
show
There is no parameter named $local_tag. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
78
     *
79
     * @return self
80
     */
81 4
    public function setGlobalTag($global_tag = null)
82
    {
83 4
        $this->emitter->setParam('dashbotTemplateId', $global_tag);
84
85 4
        return $this;
86
    }
87
88
    /**
89
     * Rewrite the dashbot template Id.
90
     *
91
     * @see https://www.dashbot.io/sdk/template
92
     *
93
     * @param array $entries
94
     * @param array $params
95
     *
96
     * @return array
97
     */
98 32
    public function rewriteTemplateId(array $entries, array $params)
99
    {
100 32
        if (isset($entries['json']) && $params['platform'] == 'facebook') {
101
            if ($tpl_id = // get from entries (local) then params (global).
102 8
                $entries['dashbotTemplateId'] ?: $params['dashbotTemplateId'] ?: false
103 6
            ) {
104 8
                $entries['json']['dashbotTemplateId'] = $tpl_id;
105
                // remove from `entries` (local) to avoid duplicate.
106 8
                unset($entries['dashbotTemplateId']);
107 6
            }
108 6
        }
109
110 32
        return $entries;
111
    }
112
113
    /**
114
     * Returns the named tracking dataset.
115
     *
116
     * @param string $type
117
     * @param array  $entries
118
     * @param string $local_tag
119
     *
120
     * @return array
121
     */
122 32
    public function get($type, array $entries, $local_tag = null)
123
    {
124 32
        if ($local_tag) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $local_tag of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
125 4
            $entries['dashbotTemplateId'] = $local_tag;
126 3
        }
127
128 32
        $entries = $this->rewriteTemplateId(
129 32
            $entries, $this->emitter->getParams()
130 24
        );
131
132 32
        $this->emitter->setParam('type', $type);
133 32
        $this->emitter->setUrl(self::TRACKER_URL);
134
135 32
        $this->data= [ $type, $entries ];
0 ignored issues
show
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
136
137 32
        return (array) $entries;
138
    }
139
140
    /**
141
     * Returns an incoming tracking dataset.
142
     *
143
     * @param array  $entries
144
     * @param string $local_tag
145
     *
146
     * @return array
147
     */
148 20
    public function incoming(array $entries, $local_tag = null)
149
    {
150 20
        return $this->get(__FUNCTION__, $entries, $local_tag);
151
    }
152
153
    /**
154
     * Returns an outgoing tracking dataset.
155
     *
156
     * @param array  $entries
157
     * @param string $local_tag
158
     *
159
     * @return array
160
     */
161 8
    public function outgoing(array $entries, $local_tag = null)
162
    {
163 8
        return $this->get(__FUNCTION__, $entries, $local_tag);
164
    }
165
}
166