Issues (20)

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.

Stanza/Error.php (1 issue)

Severity

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
 * Nucleus - XMPP Library for PHP
4
 *
5
 * Copyright (C) 2016, Some rights reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Xmpp\Stanza;
17
18
19
use Kadet\Xmpp\Exception\InvalidArgumentException;
20
use Kadet\Xmpp\Exception\NotImplementedException;
21
use Kadet\Xmpp\Xml\XmlElement;
22
use Kadet\Xmpp\Utils\filter;
23
24
use function Kadet\Xmpp\Utils\helper\format;
25
26
/**
27
 * Class Error
28
 * @package Kadet\Xmpp\Stanza
29
 * @see     http://xmpp.org/rfcs/rfc6120.html#stanzas-error
30
 *
31
 * @property string $type      Error type, describes how to deal with event
32
 * @property string $by        Error generator name
33
 * @property string $condition Error defined condition, equivalent of code
34
 * @property string $text      Textual description of error
35
 */
36
class Error extends XmlElement
37
{
38
    const XMLNS = 'urn:ietf:params:xml:ns:xmpp-stanzas';
39
40
    /**
41
     * @return string
42
     */
43
    public function getBy(): string
44
    {
45
        return $this->getAttribute('by');
46
    }
47
48
    /**
49
     * @param string $by
50
     */
51
    public function setBy(string $by)
52
    {
53
        $this->setAttribute('by', $by);
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getType(): string
60
    {
61
        return $this->getAttribute('type');
62
    }
63
64
    /**
65
     * @param string $type
66
     */
67
    public function setType(string $type)
68
    {
69
        if(!in_array($type, ['auth', 'cancel', 'continue', 'modify', 'wait'])) {
70
            throw new InvalidArgumentException(
71
                format("Error type must be 'auth', 'cancel', 'continue', 'modify' or 'wait', '{type}' given.", [
72
                    'type' => $type
73
                ])
74
            );
75
        }
76
77
        $this->setAttribute('type', $type);
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getCondition(): string
84
    {
85
        return $this->get(filter\all(
86
            filter\element\xmlns(self::XMLNS),
87
            filter\not(filter\element\name('text'))
88
        ))->localName;
89
    }
90
91
    /**
92
     * @param string $condition
93
     */
94
    public function setCondition(string $condition)
0 ignored issues
show
The parameter $condition is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
    {
96
        throw new NotImplementedException("Condition setting awaits for implementation"); // todo: implement
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getText(): string
103
    {
104
        return (string)$this->get(filter\all(
105
            filter\element\xmlns(self::XMLNS),
106
            filter\element\name('text')
107
        ));
108
    }
109
110
    /**
111
     * @param string $text
112
     */
113
    public function setText(string $text)
114
    {
115
        if(!$this->text) {
116
            $this->append(new XmlElement('text', self::XMLNS));
117
        }
118
119
        $this->get(filter\all(
120
            filter\element\xmlns('urn:ietf:params:xml:ns:xmpp-stanzas'),
121
            filter\element\name('text')
122
        ))->innerXml = $text;
123
    }
124
125
    /**
126
     * XmlElement constructor
127
     * @param string|XmlElement $condition
128
     * @param string $description
129
     * @param array  $options
130
     */
131
    public function __construct(string $condition, string $description = null, array $options = [])
132
    {
133
        $content = [
134
            !$condition instanceof XmlElement ? $this->_definedCondition($condition) : $condition
135
        ];
136
137
        if($description !== null) {
138
            $content[] = new XmlElement('text', self::XMLNS, ['content' => $description]);
139
        }
140
141
        parent::__construct('error', null, array_merge_recursive($options, [
142
            'content' => $content
143
        ]));
144
    }
145
146
    private function _definedCondition(string $condition) : XmlElement
147
    {
148
        if(!in_array($condition, [
149
            'bad-request', 'conflict', 'feature-not-implemented', 'forbidden',
150
            'gone', 'internal-server-error', 'item-not-found', 'jid-malformed',
151
            'not-acceptable', 'not-allowed', 'not-authorized', 'policy-violation',
152
            'recipient-unavailable', 'redirect', 'registration-required',
153
            'remote-server-not-found', 'remote-server-timeout', 'resource-constraint',
154
            'service-unavailable', 'subscription-required', 'undefined-condition'
155
        ])) {
156
            throw new InvalidArgumentException('Condition must be one of conditions specified by RFC 6120: http://xmpp.org/rfcs/rfc6120.html#stanzas-error-conditions');
157
        }
158
159
        return new XmlElement($condition, self::XMLNS);
160
    }
161
}
162