Issues (1490)

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/Tools/Plugin/Irc.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
namespace Fabrica\Tools\Plugin;
4
5
use Fabrica\Tools\Builder;
6
use Fabrica\Models\Infra\Ci\Build;
7
use Fabrica\Tools\Plugin;
8
9
/**
10
 * IRC Plugin - Sends a notification to an IRC channel
11
 *
12
 * @author Ricardo Sierra <[email protected]>
13
 */
14
class Irc extends Plugin
15
{
16
    protected $message;
17
    protected $server;
18
    protected $port;
19
    protected $room;
20
    protected $nick;
21
22
    /**
23
     * @return string
24
     */
25
    public static function pluginName()
26
    {
27
        return 'irc';
28
    }
29
    
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function __construct(Builder $builder, Build $build, array $options = [])
34
    {
35
        parent::__construct($builder, $build, $options);
36
37
        $this->message = $options['message'];
38
        $buildSettings = $this->builder->getConfig('build_settings');
39
40 View Code Duplication
        if (isset($buildSettings['irc'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
            $irc = $buildSettings['irc'];
42
43
            $this->server = $irc['server'];
44
            $this->port   = $irc['port'];
45
            $this->room   = $irc['room'];
46
            $this->nick   = $irc['nick'];
47
        }
48
    }
49
50
    /**
51
     * Run IRC plugin.
52
     *
53
     * @return bool
54
     */
55
    public function execute()
56
    {
57
        $msg = $this->builder->interpolate($this->message);
58
59
        if (empty($this->server) || empty($this->room) || empty($this->nick)) {
60
            $this->builder->logFailure('You must configure a server, room and nick.');
61
        }
62
63
        if (empty($this->port)) {
64
            $this->port = 6667;
65
        }
66
67
        $sock = fsockopen($this->server, $this->port);
68
        stream_set_timeout($sock, 1);
69
70
        $connectCommands = [
71
            'USER ' . $this->nick . ' 0 * :' . $this->nick,
72
            'NICK ' . $this->nick,
73
        ];
74
        $this->executeIrcCommands($sock, $connectCommands);
75
        $this->executeIrcCommand($sock, 'JOIN ' . $this->room);
76
        $this->executeIrcCommand($sock, 'PRIVMSG ' . $this->room . ' :' . $msg);
77
78
        fclose($sock);
79
80
        return true;
81
    }
82
83
    /**
84
     * @param  resource $socket
85
     * @param  array    $commands
86
     * @return bool
87
     */
88
    private function executeIrcCommands($socket, array $commands)
89
    {
90
        foreach ($commands as $command) {
91
            fputs($socket, $command . "\n");
92
        }
93
94
        $pingBack = false;
95
96
        // almost all servers expect pingback!
97
        while ($response = fgets($socket)) {
98
            $matches = [];
99
            if (preg_match('/^PING \\:([A-Z0-9]+)/', $response, $matches)) {
100
                $pingBack = $matches[1];
101
            }
102
        }
103
104
        if ($pingBack) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $pingBack of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false 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...
105
            $command = 'PONG :' . $pingBack . "\n";
106
            fputs($socket, $command);
107
        }
108
    }
109
110
    /**
111
     *
112
     * @param  resource $socket
113
     * @param  string   $command
114
     * @return bool
115
     */
116
    private function executeIrcCommand($socket, $command)
117
    {
118
        return $this->executeIrcCommands($socket, [$command]);
119
    }
120
}
121