Issues (16)

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/XMLBuild.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
namespace Thruster\Component\XMLIterator;
4
5
use Traversable;
6
7
/**
8
 * Class XMLBuild
9
 *
10
 * @package Thruster\Component\XMLIterator
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13
abstract class XMLBuild
14
{
15
    /**
16
     * indentLines()
17
     *
18
     * this will add a line-separator at the end of the last line because if it was
19
     * empty it is not any longer and deserves one.
20
     *
21
     * @param string $lines
22
     * @param string $indent (optional)
23
     *
24
     * @return string
25
     */
26
    public static function indentLines($lines, $indent = '  ')
27
    {
28
        $lineSeparator = "\n";
29
        $buffer        = '';
30
        $line          = strtok($lines, $lineSeparator);
31
32
        while ($line) {
33
            $buffer .= $indent . $line . $lineSeparator;
34
            $line = strtok($lineSeparator);
35
        }
36
37
        strtok(null, null);
38
39
        return $buffer;
40
    }
41
42
    /**
43
     * @param string            $name
44
     * @param array|Traversable $attributes attributeName => attributeValue string pairs
45
     * @param bool              $emptyTag   create an empty element tag (commonly known as short tags)
46
     *
47
     * @return string
48
     */
49 1
    public static function startTag($name, $attributes, $emptyTag = false)
50
    {
51 1
        $buffer = '<' . $name;
52 1
        $buffer .= static::attributes($attributes);
53 1
        $buffer .= $emptyTag ? '/>' : '>';
54
55 1
        return $buffer;
56
    }
57
58
    /**
59
     * @param array|Traversable $attributes attributeName => attributeValue string pairs
60
     *
61
     * @return string
62
     */
63 1
    public static function attributes($attributes)
64
    {
65 1
        $buffer = '';
66 1
        foreach ($attributes as $name => $value) {
67 1
            $buffer .= ' ' . $name . '="' . static::attributeValue($value) . '"';
68
        }
69
70 1
        return $buffer;
71
    }
72
73
    /**
74
     * @param string $value
75
     *
76
     * @see XMLBuild::numericEntitiesSingleByte
77
     *
78
     * @return string
79
     */
80 1
    public static function attributeValue($value)
81
    {
82 1
        $buffer = $value;
83
        // REC-xml/#AVNormalize - preserve
84
        // REC-xml/#sec-line-ends - preserve
85 1
        $buffer = preg_replace_callback('~\r\n|\r(?!\n)|\t~', ['self', 'numericEntitiesSingleByte'], $buffer);
86
87 1
        return htmlspecialchars($buffer, ENT_QUOTES, 'UTF-8', false);
88
    }
89
90
    /**
91
     * @param string            $name
92
     * @param array|Traversable $attributes attributeName => attributeValue string pairs
93
     * @param string            $innerXML
94
     *
95
     * @return string
96
     */
97 1
    public static function wrapTag($name, $attributes, $innerXML)
98
    {
99 1
        if (!strlen($innerXML)) {
100 1
            return XMLBuild::startTag($name, $attributes, true);
101
        }
102
103
        return
104
            XMLBuild::startTag($name, $attributes)
105
            . "\n"
106
            . XMLBuild::indentLines($innerXML)
107
            . "</$name>";
108
    }
109
110
    /**
111
     * @param XMLReader $reader
112
     *
113
     * @return string
114
     */
115
    public static function readerNode(XMLReader $reader)
116
    {
117
        switch ($reader->nodeType) {
118
            case XMLREADER::NONE:
119
                return '%(0)%';
120
            case XMLReader::ELEMENT:
121
                return XMLBuild::startTag($reader->name, new AttributeIterator($reader));
122
            default:
123
                $node         = new Node($reader);
124
                $nodeTypeName = $node->getNodeTypeName();
125
                $nodeType     = $reader->nodeType;
126
127
                return sprintf('%%%s (%d)%%', $nodeTypeName, $nodeType);
128
        }
129
    }
130
131
    /**
132
     * @param array $matches
133
     *
134
     * @return string
135
     * @see attributeValue()
136
     */
137 1
    private static function numericEntitiesSingleByte($matches)
0 ignored issues
show
This method is not used, and could be removed.
Loading history...
138
    {
139 1
        $buffer = str_split($matches[0]);
140
141 1
        foreach ($buffer as &$char) {
142 1
            $char = sprintf('&#%d;', ord($char));
143
        }
144
145 1
        return implode('', $buffer);
146
    }
147
}
148