Issues (1)

Security Analysis    no request data  

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/Logger.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 Facile\Sentry\Log;
4
5
use Facile\Sentry\Common\Sanitizer\Sanitizer;
6
use Facile\Sentry\Common\Sanitizer\SanitizerInterface;
7
use Facile\Sentry\Common\Sender\Sender;
8
use Facile\Sentry\Common\Sender\SenderInterface;
9
use Psr\Log\InvalidArgumentException;
10
use Psr\Log\LoggerInterface;
11
use Psr\Log\LoggerTrait;
12
use Psr\Log\LogLevel;
13
use Raven_Client;
14
15
/**
16
 * Class Logger.
17
 */
18
class Logger implements LoggerInterface
19
{
20
    use LoggerTrait;
21
22
    /** @var Raven_Client */
23
    protected $client;
24
25
    /** @var SenderInterface */
26
    private $sender;
27
28
    /** @var SanitizerInterface */
29
    private $sanitizer;
30
31
    /** @var array */
32
    protected $psrPriorityMap = [
33
        LogLevel::EMERGENCY => Raven_Client::FATAL,
34
        LogLevel::ALERT => Raven_Client::ERROR,
35
        LogLevel::CRITICAL => Raven_Client::ERROR,
36
        LogLevel::ERROR => Raven_Client::ERROR,
37
        LogLevel::WARNING => Raven_Client::WARNING,
38
        LogLevel::NOTICE => Raven_Client::INFO,
39
        LogLevel::INFO => Raven_Client::INFO,
40
        LogLevel::DEBUG => Raven_Client::DEBUG,
41
    ];
42
43
    /**
44
     * Logger constructor.
45
     *
46
     * @param Raven_Client            $client
47
     * @param SenderInterface|null    $sender
48
     * @param SanitizerInterface|null $sanitizer
49
     */
50 5
    public function __construct(
51
        Raven_Client $client,
52
        SenderInterface $sender = null,
53
        SanitizerInterface $sanitizer = null
54
    ) {
55 5
        $this->client = $client;
56 5
        if (! $sender) {
57 2
            $sender = new Sender($client, $sanitizer);
58 2
            $sender->getStackTrace()->addIgnoreBacktraceNamespace(__NAMESPACE__);
0 ignored issues
show
Deprecated Code introduced by
The method Facile\Sentry\Common\Sta...oreBacktraceNamespace() has been deprecated.

This method has been deprecated.

Loading history...
59
        }
60 5
        $this->sender = $sender;
61 5
        $this->sanitizer = $sanitizer ?: new Sanitizer();
62 5
    }
63
64
    /**
65
     * Logs with an arbitrary level.
66
     *
67
     * @param string        $level
68
     * @param string|object $message
69
     * @param array         $context
70
     *
71
     * @throws InvalidArgumentException
72
     *
73
     * @return void
74
     */
75 5
    public function log($level, $message, array $context = []): void
76
    {
77 5
        if (! \array_key_exists($level, $this->psrPriorityMap)) {
78 1
            throw new InvalidArgumentException(\sprintf(
79 1
                '$level must be one of PSR-3 log levels; received %s',
80 1
                \var_export($level, true)
81
            ));
82
        }
83
84 4
        if (\is_object($message)) {
85 2
            if (! \method_exists($message, '__toString')) {
86 1
                throw new InvalidArgumentException(
87 1
                    '$message must implement magic __toString() method'
88
                );
89
            }
90
91 1
            $messageStr = $message->__toString();
92
        } else {
93 2
            $messageStr = $message;
94
        }
95
96 3
        $priority = $this->psrPriorityMap[$level];
97 3
        $message = $this->interpolate($messageStr, $context);
98
99 3
        $this->sender->send($priority, $message, $context);
100 3
    }
101
102
    /**
103
     * @param string $message
104
     * @param array  $context
105
     *
106
     * @return string
107
     */
108 3
    protected function interpolate(string $message, array $context = []): string
109
    {
110 3
        $replace = [];
111
        /** @var array $context */
112 3
        $context = $this->sanitizer->sanitize($context);
113 3
        foreach ($context as $key => $val) {
114 3
            if (\is_array($val)) {
115 1
                continue;
116
            }
117 3
            $replace['{' . $key . '}'] = (string) $val;
118
        }
119
120 3
        return \strtr($message, $replace);
121
    }
122
}
123