Issues (10)

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.

tests/unit/RegexHelperTest.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
3
namespace Asparagus\Tests;
4
5
use Asparagus\RegexHelper;
6
7
/**
8
 * @covers Asparagus\RegexHelper
9
 *
10
 * @license GNU GPL v2+
11
 * @author Bene* < [email protected] >
12
 */
13
class RegexHelperTest extends \PHPUnit_Framework_TestCase {
14
15
	/**
16
	 * @dataProvider provideMatchingExpressions
17
	 */
18
	public function testMatchesRegex_matching( $regex, $expression ) {
19
		$regexHelper = new RegexHelper();
20
21
		$this->assertTrue( $regexHelper->matchesRegex( $regex, $expression ) );
22
	}
23
24
	public function provideMatchingExpressions() {
25
		return array(
26
			array( '\{variable}', '?abc' ),
27
			array( '\{variable}', '$abc' ),
28
			array( 'AS \{variable}', 'AS ?nyan' ),
29
			array( '\{iri}', 'http://www.example.com/test#' ),
30
			array( '\{prefix}', 'foo_bar42' ),
31
			array( '\{name}', 'foo_bar42' ),
32
			array( '\{prefixed_iri}', '<http://www.example.com/test#>' ),
33
			array( '\{prefixed_iri}', 'nyan:cat' ),
34
			array( '\{native}', '123' ),
35
			array( '\{native}', '"foo bar"' ),
36
			array( '\{path}', 'nyan:cat' ),
37
			array( '\{path}', '^nyan:cat' ),
38
			array( '\{path}', 'nyan:cat' ),
39
			array( '\{path}', 'nyan:cat/nyan:kitten' ),
40
			array( '\{path}', 'nyan:cat/nyan:kitten/cat:kitten' ),
41
			array( '\{path}', 'nyan:cat|nyan:kitten' ),
42
			array( '\{path}', 'nyan:cat*' ),
43
			array( '\{path}', 'nyan:cat+' ),
44
			array( '\{path}', 'nyan:cat?' ),
45
			array( '\{path}', '!nyan:cat' ),
46
			array( '\{path}', '!(nyan:cat|nyan:kitten)' ),
47
			array( '\{path}', '!^nyan:cat' ),
48
			array( '\{path}', '!(^nyan:cat|^nyan:kitten)' ),
49
			array( '\{path}', '(nyan:cat)' ),
50
			array( '\{function}', 'COUNT (?x)' ),
51
			array( '\{function}', '?x + ?y' ),
52
			array( '\{function}', '!BOUND (?x)' ),
53
			array( '\{function}', '<http://www.example.com/test#nyan>' ),
54
		);
55
	}
56
57
	/**
58
	 * @dataProvider provideNonMatchingExpressions
59
	 */
60
	public function testMatchesRegex_nonMatching( $regex, $expression ) {
61
		$regexHelper = new RegexHelper();
62
63
		$this->assertFalse( $regexHelper->matchesRegex( $regex, $expression ) );
64
	}
65
66
	public function provideNonMatchingExpressions() {
67
		return array(
68
			array( '\{variable}', 'foobar' ),
69
			array( '\{variable}', '?foo bar' ),
70
			array( 'AS \{variable}', 'AS ?nyan foobar' ),
71
			array( '\{iri}', '<http://www.example.com/test#>' ),
72
			array( '\{iri}', 'http://www.example.com/te>st#' ),
73
			array( '\{iri}', 'http://www.example.com/te}st#' ),
74
			array( '\{iri}', 'http://www.example.com/te st#' ),
75
			array( '\{prefix}', 'nyan cat' ),
76
			array( '\{prefix}', 'nyan:cat' ),
77
			array( '\{name}', 'nyan cat' ),
78
			array( '\{name}', 'nyan:cat' ),
79
			array( '\{prefixed_iri}', 'http://www.example.com/test#nyan' ),
80
			array( '\{prefixed_iri}', 'nyan:cat:kitten' ),
81
			array( '\{native}', '"abc' ),
82
			array( '\{native}', 'ab123' ),
83
			array( '\{path}', 'foobar' ),
84
			array( '\{path}', '?foobar' ),
85
			array( '\{path}', '^!nyan:cat' ),
86
			array( '\{path}', '!!!nyan:cat' ),
87
			array( '\{path}', '()' ),
88
			array( '\{function}', 'FOO BAR' ),
89
			array( '\{function}', '(COUNT (?x))' )
90
		);
91
	}
92
93
	/**
94
	 * @dataProvider provideGetMatches
95
	 */
96
	public function testGetMatches( $regex, $expression, $matches ) {
97
		$regexHelper = new RegexHelper();
98
99
		$this->assertEquals( $matches, $regexHelper->getMatches( $regex, $expression ) );
100
	}
101
102
	public function provideGetMatches() {
103
		return array(
104
			array( '\{variable}', ' ?abc nyan $def ', array( 'abc', 'def' ) ),
105
			array( 'AS \{variable}', 'FOO (?x) AS ?nyan', array( 'nyan' ) ),
106
			array( 'AS \{variable}', 'FOO (<http://www.example.com/test?kitten> = "X AS ?kitten") AS ?nyan', array( 'nyan' ) )
107
		);
108
	}
109
110
	/**
111
	 * @dataProvider provideEscapeSequences
112
	 */
113
	public function testEscapeSequences( $expression, array $matches ) {
114
		$regexHelper = new RegexHelper();
115
		$escaped = $regexHelper->escapeSequences( $expression, $replacements );
116
117
		$this->assertEquals( $matches, array_values( $replacements ) );
118
		$this->assertEquals( $expression, strtr( $escaped, $replacements ) );
0 ignored issues
show
It seems like $replacements can also be of type null; however, strtr() 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...
119
	}
120
121
	public function provideEscapeSequences() {
122
		return array(
123
			array( 'foo bar', array() ),
124
			array( 'cat " kitten', array() ),
125
			array( 'I\'m a "nyan cat" and this is cool', array( '"nyan cat"' ) ),
126
			array( 'This is "so sweet" and it\'s a "nyan" cat', array( '"so sweet"', '"nyan"' ) ),
127
			array( 'This <iri> is cool', array( '<iri>' ) ),
128
			array( 'This <iri> is > confusing', array( '<iri>' ) ),
129
			array( 'A "nyan cat" with <iri> 42', array( '"nyan cat"', '<iri>' ) ),
130
			array( 'A "nyan <iri> cat" with 42', array( '"nyan <iri> cat"' ) ),
131
			array( 'A "nyan <iri cat" with <iri> 42', array( '"nyan <iri cat"', '<iri>' ) )
132
		);
133
	}
134
135
}
136