Issues (9)

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.

tests/Functional/HookTest.php (2 issues)

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 Tests\Functional;
4
5
class HookTest extends AbstractTestCase
6
{
7
8
	public static function setUpBeforeClass()
9
	{
10
		self::setPath('/');
11
		self::setSecurityHeader('X-Gitlab-Token');
12
	}
13
14
15
    public function testDeploy()
16
    {
17
		$this->simpleTest(__DIR__ . '/data/pipeline.json',
18
		[
19
			'HOOK_PROJECT_PATH' => 'gitlab-org/gitlab-test',
20
			'HOOK_BUILD_ID' => 379,
21
			'HOOK_BUILD_REF' => 'bcbb5ec396a2c0f828686f14fac9b80b780504f2',
22
			'HOOK_ENV_NAME' => 'staging'
23
		], [
0 ignored issues
show
array('bash /testing-dir...ash do-something-else') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
			'bash /testing-dir/script.bash deploy',
25
			'bash do-something-else'
26
		]);
27
    }
28
29
30
    public function testPush()
31
    {
32
		$this->simpleTest(__DIR__ . '/data/push.json', [
33
			'HOOK_PROJECT_PATH' => 'gitlab-org/gitlab-test',
34
			'HOOK_REF' => 'refs/heads/master',
35
			'HOOK_BRANCH' => 'master',
36
			'HOOK_BUILD_REF' => 'da1560886d4f094c3e6c9ef40349f7d38b5d27d7'
37
		], [
0 ignored issues
show
array('cwd' => '/testing...-dir/script.bash push') is of type array<string,string,{"cw...g","command":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
			'cwd' => '/testing-dir',
39
			'command' => 'bash /testing-dir/script.bash push'
40
		]);
41
    }
42
43
44
	public function testPushTag()
45
	{
46
		$this->simpleTest(__DIR__ . '/data/tag.json',
47
			[
48
				'HOOK_PROJECT_PATH' => 'jsmith/example',
49
				'HOOK_REF' => 'refs/tags/v1.0.0',
50
				'HOOK_TAG' => 'v1.0.0',
51
				'HOOK_BUILD_REF' => '82b3d5ae55f7080f1e6022629cdb57bfae7cccc7'
52
			],
53
			'bash test.bash xcasdzcxzsdda'
54
		);
55
	}
56
57
58
	public function testExecutorPushTag()
59
	{
60
		$result = shell_exec("bash -c \"echo abc\"");
61
		if ($result === "abc\n") {
62
			if (file_exists(__DIR__ . '/log')) {
63
				unlink(__DIR__ . '/log');
64
			}
65
66
			$response = $this->runApp(file_get_contents(__DIR__ . '/data/tag.json') , [
67
				'scripts' => [
68
					'jsmith/example' => [
69
						'tag' => [
70
							'cwd' => __DIR__,
71
							'bash test.bash ABC',
72
							'bash test.bash CDE'
73
						]
74
					]
75
				]
76
			]);
77
			$logFile = file_get_contents(__DIR__ . '/log');
78
			$this->assertEquals(
79
				"jsmith/example refs/tags/v1.0.0 v1.0.0 82b3d5ae55f7080f1e6022629cdb57bfae7cccc7 ABC\n" .
80
				"jsmith/example refs/tags/v1.0.0 v1.0.0 82b3d5ae55f7080f1e6022629cdb57bfae7cccc7 CDE\n",
81
				$logFile
82
			);
83
84
			$this->assertEquals(200, $response->getStatusCode());
85
86
			unlink(__DIR__ . '/log');
87
		}
88
	}
89
90
91
	public function testExecutorSinglePushTag()
92
	{
93
		$result = shell_exec("bash -c \"echo abc\"");
94
		if ($result === "abc\n") {
95
			if (file_exists(__DIR__ . '/log')) {
96
				unlink(__DIR__ . '/log');
97
			}
98
99
			$oldDir = getcwd();
100
			chdir(__DIR__);
101
102
			$response = $this->runApp(file_get_contents(__DIR__ . '/data/tag.json') , [
103
				'scripts' => [
104
					'jsmith/example' => [
105
						'tag' => 'bash test.bash DEF'
106
					]
107
				]
108
			]);
109
			$logFile = file_get_contents(__DIR__ . '/log');
110
			$this->assertEquals(
111
				"jsmith/example refs/tags/v1.0.0 v1.0.0 82b3d5ae55f7080f1e6022629cdb57bfae7cccc7 DEF\n",
112
				$logFile
113
			);
114
115
			$this->assertEquals(200, $response->getStatusCode());
116
117
			chdir($oldDir);
118
			unlink(__DIR__ . '/log');
119
		}
120
	}
121
122
123
	public function testNo()
124
	{
125
		$response = $this->runInvalid();
126
127
		$this->assertEquals(500, $response->getStatusCode());
128
	}
129
130
131
	public function testUnsecured()
132
	{
133
		$response = $this->runUnsecured();
134
135
		$this->assertEquals(403, $response->getStatusCode());
136
	}
137
138
139
	public function testNotHandled()
140
	{
141
		$response = $this->runNotHandled();
142
143
		$this->assertEquals(404, $response->getStatusCode());
144
	}
145
146
147
	/**
148
	 * @param string $file
149
	 * @param array $env
150
	 * @param string $command
151
	 */
152
	protected function simpleTest($file, array $env, $command)
153
	{
154
		$response = $this->runAppMocked(file_get_contents($file), $env, $command);
155
		$this->assertEquals(200, $response->getStatusCode());
156
	}
157
158
}
159