Issues (19)

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/PlaceholderContainer.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 ArjanSchouten\HtmlMinifier;
4
5
use Illuminate\Support\Collection;
6
7
class PlaceholderContainer extends Collection
8
{
9
    /**
10
     * Hash used in placeholders.
11
     *
12
     * @var string
13
     */
14
    protected $replacementHash;
15
16
    /**
17
     * Create a new placeholdercontainer.
18
     *
19
     * @param array $items
20
     */
21 28
    public function __construct($items = [])
22
    {
23 28
        $replacementHashLimit = 32;
24 28
        $this->replacementHash = str_limit(md5(time()), $replacementHashLimit);
25 28
        parent::__construct($items);
26 28
    }
27
28
    /**
29
     * @param string $contents
30
     *
31
     * @return string
32
     */
33 4
    public function restorePlaceholders($contents)
34
    {
35 4
        foreach ($this->all() as $placeholder => $original) {
36 1
            $contents = str_replace($placeholder, $original, $contents);
37
        }
38
39 4
        return $contents;
40
    }
41
42
    /**
43
     * Replace ```$value``` with a placeholder and store it in the container.
44
     *
45
     * @param string $value
46
     * @param string $content
47
     *
48
     * @return string $contents
49
     */
50 3
    public function addPlaceholder($value, $content)
51
    {
52 3
        $placeholder = $this->createPlaceholder($value);
53
54 3
        return str_replace($value, $placeholder, $content);
55
    }
56
57
    /**
58
     * Create a unique placeholder for the given contents.
59
     *
60
     * @param string $value
61
     *
62
     * @return string $placeholder
0 ignored issues
show
Should the return type not be integer|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
63
     */
64 5
    public function createPlaceholder($value)
65
    {
66 5
        if (($key = array_search($value, $this->all()))) {
67
            $placeholder = $key;
68
        } else {
69 5
            $placeholder = $this->createUniquePlaceholder();
70
        }
71
72 5
        $value = $this->removeNestedPlaceholders($value);
73 5
        $this->items[$placeholder] = $value;
74
75 5
        return $placeholder;
76
    }
77
78
    /**
79
     * Calculate the byte size of the placeholders.
80
     *
81
     * @param string $contentsWithPlaceholders
82
     * @return int
0 ignored issues
show
Should the return type not be integer|double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
83
     */
84 4
    public function getContentSize($contentsWithPlaceholders)
85
    {
86
        $placeholderSize = $this->map(function ($value, $key) use (&$contentsWithPlaceholders){
87 1
            $count = substr_count($contentsWithPlaceholders, $key);
88
89 1
            return strlen($key) * $count - strlen($value) * $count;
90 4
        })->sum();
91
92 4
        return strlen($contentsWithPlaceholders) - $placeholderSize;
93
    }
94
95
    /**
96
     * Create an unique placeholder.
97
     *
98
     * @return string
99
     */
100 5
    protected function createUniquePlaceholder()
101
    {
102 5
        return '[['.$this->replacementHash.$this->count().']]';
103
    }
104
105
    /**
106
     * Remove nested placeholders so no nested placholders remain in the original contents.
107
     *
108
     * @param string $originalContent
109
     *
110
     * @return string
111
     */
112
    protected function removeNestedPlaceholders($originalContent)
113
    {
114 5
        return preg_replace_callback('/'.Constants::PLACEHOLDER_PATTERN.'/', function ($match) {
115 1
            return $this->pull($match[0]);
116 5
        }, $originalContent);
117
    }
118
}
119