Issues (4)

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/PregFunctions/MatchFunctions.php (1 issue)

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
namespace Mcustiel\PhpSimpleRegex\PregFunctions;
3
4
use Mcustiel\PhpSimpleRegex\MatchResult;
5
use Mcustiel\PhpSimpleRegex\Match;
6
7
trait MatchFunctions
8
{
9
    /**
10
     * Searches for all matches for the given pattern.
11
     *
12
     * @param string|\VerbalExpressions\PHPVerbalExpressions\VerbalExpressions|SelvinOrtiz\Utils\Flux\Flux|MarkWilson\VerbalExpression
13
     *          $pattern
14
     * @param string
15
     *          $subject
16
     * @param number
17
     *          $offset
18
     *
19
     * @throws \RuntimeException
20
     * @throws \InvalidArgumentException
21
     *
22
     * @return \Mcustiel\PhpSimpleRegex\MatchResult
23
     */
24 6
    public function getAllMatches($pattern, $subject, $offset = 0)
25
    {
26 6
        $matches = array();
27 6
        $result = @preg_match_all(
28 6
            $this->getPatternByType($pattern),
29 5
            $subject,
30 5
            $matches,
31 5
            PREG_SET_ORDER | PREG_OFFSET_CAPTURE,
32 5
            $offset
33
        );
34
35 5
        $this->checkResultIsOkOrThrowException($result, $pattern);
36
37 5
        return new MatchResult($matches);
0 ignored issues
show
It seems like $matches can also be of type null; however, Mcustiel\PhpSimpleRegex\MatchResult::__construct() does only seem to accept array, 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...
38
    }
39
40
    /**
41
     * Searches for matches for the given pattern and returns the first match.
42
     *
43
     * @param string|\VerbalExpressions\PHPVerbalExpressions\VerbalExpressions|SelvinOrtiz\Utils\Flux\Flux|MarkWilson\VerbalExpression
44
     *          $pattern
45
     * @param string
46
     *          $subject
47
     * @param number
48
     *          $offset
49
     *
50
     * @throws \RuntimeException
51
     * @throws \InvalidArgumentException
52
     *
53
     * @return \Mcustiel\PhpSimpleRegex\Match|NULL
54
     */
55 2
    public function getOneMatch($pattern, $subject, $offset = 0)
56
    {
57 2
        $matches = array();
58 2
        $pattern = $this->getPatternByType($pattern);
59 2
        $result = @preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, $offset);
60 2
        $this->checkResultIsOkOrThrowException($result, $pattern);
61 2
        return $result? new Match($matches) : null;
62
    }
63
64
    /**
65
     * Checks weather the string matches the given pattern.
66
     *
67
     * @param string|\VerbalExpressions\PHPVerbalExpressions\VerbalExpressions|SelvinOrtiz\Utils\Flux\Flux|MarkWilson\VerbalExpression
68
     *          $pattern
69
     * @param string
70
     *          $subject
71
     * @param number
72
     *          $offset
73
     *
74
     * @throws \RuntimeException
75
     * @throws \InvalidArgumentException
76
     *
77
     * @return boolean
78
     */
79 3
    public function match($pattern, $subject, $offset = 0)
80
    {
81 3
        $matches = [];
82 3
        $result = @preg_match(
83 3
            $this->getPatternByType($pattern),
84 3
            $subject,
85 3
            $matches,
86 3
            0,
87 3
            $offset
88
        );
89 3
        $this->checkResultIsOkOrThrowException($result, $pattern);
90 2
        return (boolean) $result;
91
    }
92
93
    /**
94
     * @param mixed $pattern
95
     * @throws \InvalidArgumentException
96
     * @return string
97
     */
98
    abstract protected function getPatternByType($pattern);
99
100
    /**
101
     * @param mixed  $result
102
     * @param string $pattern
103
     *
104
     * @throws \RuntimeException
105
     */
106
    abstract protected function checkResultIsOkOrThrowException($result, $pattern);
107
}
108