Issues (7)

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/PHPHtmlDom/PHPHtmlDom.php (3 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
namespace PHPTools\PHPHtmlDom;
3
4
/**
5
* Esta es la clas eque el usuario debe inicializar para convertir un texto html en un objeto DOM.
6
*/
7
class PHPHtmlDom
8
{
9
    /**
10
     * Objeto que permite convertir un selector css en un path.
11
     * @var \Symfony\Component\CssSelector\CssSelector
12
     */
13
    private $selector;
14
15
    /**
16
     * Objeto que permite escribir logs.
17
     * @var \PHPTools\PHPHtmlDom\Core\PHPHtmlDomLog
18
     */
19
    private $logger;
20
21
    /**
22
     * Objeto nativo de php que permite crear un documento DOM.
23
     * @var \DOMDocument
24
     */
25
    private $dom;
26
27
    /**
28
     * Objeto nativo de php que permite buscar un xpath dentro de un documento DOM.
29
     * @var \DOMXPath
30
     */
31
    private $xpath;
32
33
    /**
34
     * Objeto que permite importar el contennido html.
35
     * @var \PHPTools\PHPHtmlDom\Core\PHPHtmlDomImportHtml
36
     */
37
    private $importer;
38
39
    /**
40
     * Contenido crudo html.
41
     * @var string
42
     */
43
    private $html_content; 
44
45
    public function __construct()
46
    {
47
        $this->selector = new \Symfony\Component\CssSelector\CssSelectorConverter;
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Symfony\Component\C...\CssSelectorConverter() of type object<Symfony\Component...r\CssSelectorConverter> is incompatible with the declared type object<Symfony\Component\CssSelector\CssSelector> of property $selector.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
        $this->logger = new \PHPTools\PHPHtmlDom\Core\PHPHtmlDomLog;
49
        $this->dom = new \DOMDocument;
50
        $this->importer = new \PHPTools\PHPHtmlDom\Core\PHPHtmlDomImportHtml;
51
        $this->html_content = NULL;
52
53
        $this->dom->preserveWhiteSpace = false;
54
        $this->dom->validateOnParse = true;
55
    }
56
57
    /**
58
     * Metodo que importa y convierte el contenido html en un objeto DOM.
59
     * @param  string $text_html Cadena de texto con la url, path, texto html.
60
     * @return boolean
61
     */
62
    final public function importHTML($text_html)
63
    {
64
        $content = $this->importer->import($text_html);
65
66
        if(!!is_null($content))
67
        {
68
            $this->logger->logError('E001', array($text_html));
69
        }
70
        else if(!$content)
71
        {
72
            $this->logger->logWarn('W001', array($text_html));
73
        }
74
        else
75
        {
76
            $this->html_content = $content;
0 ignored issues
show
Documentation Bug introduced by
It seems like $content can also be of type boolean. However, the property $html_content is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
77
        }
78
79
        return !!$this->domImport();
80
    }
81
82
    /**
83
     * Metodo que permite buscar elementos hijos a partir de un selector css.
84
     * @param  string $css_selector Cadena de texto con el selector css.
85
     * @return PHPTools\PHPHtmlDom\Core\PHPHtmlDomList
86
     */
87
    final public function e($css_selector)
88
    {
89
        $xpath = $this->toXPath($css_selector);
90
91
        if(!!$xpath)
0 ignored issues
show
Bug Best Practice introduced by
The expression $xpath 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...
92
        {
93
            return new \PHPTools\PHPHtmlDom\Core\PHPHtmlDomList($this->xpath->query($xpath));
94
        }
95
    }
96
97
    /**
98
     * Permite importar el contenido dom del texto html.
99
     * @return boolean
100
     */
101
    private function domImport()
102
    {
103
        $dom_import = @$this->dom->loadHTML($this->html_content);
104
105
        if(!!$dom_import)
106
        {
107
            $this->xpath = new \DOMXPath($this->dom);
108
        }
109
        else
110
        {
111
            $this->logger->logError('E002', array($this->html_content));
112
        }
113
114
        return $dom_import;
115
    }
116
117
    /**
118
     * Metodo que convierte un selector css en un xpath
119
     * @param  string $css_selector Cadena de texto con el selector css.
120
     * @return string|NULL          Devuelve una cadena de texto con formato xpath si la converción e sposible o NULL en caso contrario.
121
     */
122
    private function toXPath($css_selector)
123
    {
124
        $xpath = Null;
125
126
        try
127
        {
128
            $xpath = $this->selector->toXPath($css_selector);
129
        }
130
        catch (\Exception $e)
131
        {
132
            $this->logger->logError('E003', array($css_selector));
133
            $this->logger->logError('E000', array($e->getMessage()));
134
        }
135
136
        return $xpath;
137
    }
138
}
139