Issues (3)

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/Converter.php (3 issues)

Labels
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
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
/**
4
 * This file is part of the Base64 Handler library.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * PHP Version 7
10
 *
11
 * LICENSE: This source file is subject to the MIT license that is available
12
 * through the world-wide-web at the following URI:
13
 * http://opensource.org/licenses/mit-license.php
14
 *
15
 * @category Src
16
 * @package  Normeno\Base64Hanlder
17
 * @author   Nicolas Ormeno <[email protected]>
18
 * @license  http://opensource.org/licenses/mit-license.php MIT License
19
 * @link     https://github.com/normeno/base64_handler
20
 */
21
namespace Normeno\Base64Handler;
22
23
/**
24
 * Checker Class
25
 *
26
 * @category src
27
 * @package  Normeno\Base64Handler
28
 * @author   Nicolas Ormeno <[email protected]>
29
 * @license  http://opensource.org/licenses/mit-license.php MIT License
30
 * @link     https://github.com/normeno/base64_handler
31
 */
32
class Converter
33
{
34
    /**
35
     * Convert image to base64
36
     *
37
     * @param string $file image's path
38
     * @see https://stackoverflow.com/a/13758760/2901396
39
     *
40
     * @return bool|string
41
     */
42
    public static function imageToBase64($file)
43
    {
44
        try {
45
            $type = pathinfo($file, PATHINFO_EXTENSION);
46
            $data = file_get_contents($file);
47
            $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
48
            return $base64;
49
        } catch (\Exception $e) {
50
            return false;
51
        }
52
    }
53
54
    /**
55
     * Convert base64 to image
56
     *
57
     * @param string $base64    Base64 string
58
     * @param string $dest      destination path
59
     *
60
     * @return array|string
61
     */
62
    public static function base64ToImage(string $base64, string $dest = '')
63
    {
64
        try {
65
            if ($dest == '') {
66
                $dest = getcwd() . '/src/tmp';
67
            }
68
69
            $base64 = Utils::clearString($base64);
70
71
            $resp = Utils::getExtFromBase64($base64);
0 ignored issues
show
It seems like $base64 defined by \Normeno\Base64Handler\Utils::clearString($base64) on line 69 can also be of type boolean; however, Normeno\Base64Handler\Utils::getExtFromBase64() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
72
            $filename = md5(time().uniqid()) . '.' . $resp['ext'];
73
            $base64 = Utils::clearString($base64);
0 ignored issues
show
It seems like $base64 defined by \Normeno\Base64Handler\Utils::clearString($base64) on line 73 can also be of type boolean; however, Normeno\Base64Handler\Utils::clearString() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
74
            $resp['path'] = $dest . '/' . $filename;
75
76
            file_put_contents($resp['path'], base64_decode($base64));
77
            unlink($resp['path']);
78
79
            return $resp;
80
        } catch (\Exception $e) {
81
            return "{$e->getMessage()}: ({$e->getCode()})";
82
        }
83
    }
84
85
    /**
86
     * Convert base64 to image
87
     *
88
     * @param string $base64    Base64 string
89
     * @param string $ext       File's extension
90
     * @param string $dest      destination path
91
     *
92
     * @return array|string
93
     */
94
    public static function base64ToFile(string $base64, string $ext = '', string $dest = '')
95
    {
96
        try {
97
            if ($dest == '') {
98
                $dest = getcwd() . '/src/tmp';
99
            }
100
101
            $base64 = Utils::clearString($base64);
102
103
            $resp = Utils::getExtFromBase64($base64);
0 ignored issues
show
It seems like $base64 defined by \Normeno\Base64Handler\Utils::clearString($base64) on line 101 can also be of type boolean; however, Normeno\Base64Handler\Utils::getExtFromBase64() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
104
105
            $resp['ext'] = !empty($ext) ? $ext : $resp['ext'];
106
107
            $filename = md5(time().uniqid()) . '.' . $resp['ext'];
108
            $resp['path'] = $dest . '/' . $filename;
109
110
            file_put_contents($resp['path'], base64_decode($base64));
111
            unlink($resp['path']);
112
113
            return $resp;
114
        } catch (\Exception $e) {
115
            return "{$e->getMessage()}: ({$e->getCode()})";
116
        }
117
    }
118
}