Issues (3948)

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.

app/Helpers/TextHelper.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
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Helper;
13
14
use Jitamin\Foundation\Base;
15
use Jitamin\Foundation\Markdown;
16
17
/**
18
 * Text Helpers.
19
 */
20
class TextHelper extends Base
21
{
22
    /**
23
     * HTML escaping.
24
     *
25
     * @param string $value Value to escape
26
     *
27
     * @return string
28
     */
29
    public function e($value)
30
    {
31
        return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false);
32
    }
33
34
    /**
35
     * Markdown transformation.
36
     *
37
     * @param string $text
38
     * @param bool   $isPublicLink
39
     *
40
     * @return string
41
     */
42
    public function markdown($text, $isPublicLink = false)
43
    {
44
        $parser = new Markdown($this->container, $isPublicLink);
45
        $parser->setMarkupEscaped(MARKDOWN_ESCAPE_HTML);
46
47
        return $parser->text($text);
48
    }
49
50
    /**
51
     * Escape Markdown text that need to be stored in HTML attribute.
52
     *
53
     * @param string $text
54
     *
55
     * @return mixed
56
     */
57
    public function markdownAttribute($text)
58
    {
59
        return htmlentities($this->markdown($text), ENT_QUOTES, 'UTF-8');
60
    }
61
62
    /**
63
     * Format a file size.
64
     *
65
     * @param int $size      Size in bytes
66
     * @param int $precision Precision
67
     *
68
     * @return string
69
     */
70
    public function bytes($size, $precision = 2)
71
    {
72
        $base = log($size) / log(1024);
73
        $suffixes = ['', 'k', 'M', 'G', 'T'];
74
75
        return round(pow(1024, $base - floor($base)), $precision).$suffixes[(int) floor($base)];
76
    }
77
78
    /**
79
     * Get the number of bytes from PHP size.
80
     *
81
     * @param int $val PHP size (example: 2M)
82
     *
83
     * @return int
84
     */
85
    public function phpToBytes($val)
86
    {
87
        $val = trim($val);
88
        $last = strtolower($val[strlen($val) - 1]);
89
90
        switch ($last) {
91
            case 'g':
0 ignored issues
show
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
92
                $val *= 1024;
93
            case 'm':
0 ignored issues
show
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
94
                $val *= 1024;
95
            case 'k':
96
                $val *= 1024;
97
        }
98
99
        return $val;
100
    }
101
102
    /**
103
     * Return true if needle is contained in the haystack.
104
     *
105
     * @param string $haystack Haystack
106
     * @param string $needle   Needle
107
     *
108
     * @return bool
109
     */
110
    public function contains($haystack, $needle)
111
    {
112
        return strpos($haystack, $needle) !== false;
113
    }
114
115
    /**
116
     * Return a value from a dictionary.
117
     *
118
     * @param mixed  $id            Key
119
     * @param array  $listing       Dictionary
120
     * @param string $default_value Value displayed when the key doesn't exists
121
     *
122
     * @return string
123
     */
124
    public function in($id, array $listing, $default_value = '?')
125
    {
126
        if (isset($listing[$id])) {
127
            return $this->helper->text->e($listing[$id]);
0 ignored issues
show
The property helper does not exist on object<Jitamin\Helper\TextHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
128
        }
129
130
        return $default_value;
131
    }
132
}
133