Issues (213)

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/features/bootstrap/FeatureContext.php (9 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
require __DIR__ . '/../../vendor/autoload.php';
3
4
use Behat\Behat\Context\Context;
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Psr7\Response;
7
use PHPUnit\Framework\Assert;
8
9
class FeatureContext implements Context
10
{
11
12
	use \JuliusHaertl\NextcloudBehat\FilesSharingContextTrait;
13
	use \JuliusHaertl\NextcloudBehat\FilesDavContextTrait;
14
	use \JuliusHaertl\NextcloudBehat\UserContextTrait;
15
	use \JuliusHaertl\NextcloudBehat\UserWebContextTrait;
16
17
	/**
18
	 * Initializes context.
19
	 *
20
	 * Every scenario gets its own context instance.
21
	 * You can also pass arbitrary arguments to the
22
	 * context constructor through behat.yml.
23
	 */
24
	public function __construct($baseUrl)
25
	{
26
		$this->setBaseUrl($baseUrl);
27
	}
28
29
	/**
30
	 * @When User :user opens :file
31
	 */
32
	public function userOpens($user, $file)
33
	{
34
		// get file id
35
		$davClient = $this->getSabreClient($user);
36
		$path = $this->makeSabrePath($user, $file);
37
		$result = $davClient->propFind($path, ['{http://owncloud.org/ns}fileid']);
38
		$fileId = $result['{http://owncloud.org/ns}fileid'];
39
40
		$this->usingWebAsUser($user);
41
42
		$client = new Client();
43
		$result = $client->get($this->baseUrl . 'index.php/apps/richdocuments/index?fileId=' . $fileId, $this->getWebOptions());
44
		$contents =$result->getBody()->getContents();
45
		$re = '/var richdocuments_([A-z]+) = (.*);/m';
46
		preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0);
47
		$result = [];
48 View Code Duplication
		foreach ($matches as $match) {
0 ignored issues
show
The expression $matches of type null|array<integer,array<integer,string>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
			$result[$match[1]] = str_replace("'", "", $match[2]);
50
		}
51
52
		$this->fileId = $result['fileId'];
53
		$this->wopiToken = $result['token'];
54
	}
55
56
57
	/**
58
	 * @Then a guest opens the share link
59
	 */
60
	public function aGuestOpensTheShareLink()
61
	{
62 View Code Duplication
		if (count($this->lastShareData->data->element) > 0){
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
			$token = $this->lastShareData->data[0]->token;
64
		} else {
65
			$token = $this->lastShareData->data->token;
66
		}
67
68
69
		// 	public function publicPage($shareToken, $fileName, $fileId) {
70
		$client = new Client();
71
		$result = $client->get($this->baseUrl . 'index.php/apps/richdocuments/public?shareToken=' . $token, $this->getWebOptions());
72
		$contents =$result->getBody()->getContents();
73
		$re = '/var richdocuments_([A-z]+) = (.*);/m';
74
		preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0);
75
		$result = [];
76 View Code Duplication
		foreach ($matches as $match) {
0 ignored issues
show
The expression $matches of type null|array<integer,array<integer,string>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
			$result[$match[1]] = str_replace("'", "", $match[2]);
78
		}
79
80
		$this->fileId = $result['fileId'];
81
		$this->wopiToken = $result['token'];
82
	}
83
84
	/**
85
	 * @Then a guest opens the share link as :user
86
	 */
87
	public function aGuestOpensTheShareLinkAs($user)
88
	{
89 View Code Duplication
		if (count($this->lastShareData->data->element) > 0){
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
			$token = $this->lastShareData->data[0]->token;
91
		} else {
92
			$token = $this->lastShareData->data->token;
93
		}
94
95
		$cookieJar = \GuzzleHttp\Cookie\CookieJar::fromArray([
96
			'guestUser' => $user
97
		], 'localhost');
98
99
100
		// 	public function publicPage($shareToken, $fileName, $fileId) {
101
		$client = new Client();
102
		$result = $client->get($this->baseUrl . 'index.php/apps/richdocuments/public?shareToken=' . $token, array_merge($this->getWebOptions(), [
103
			'cookies' => $cookieJar
104
		]));
105
		$contents = $result->getBody()->getContents();
106
		$re = '/var richdocuments_([A-z]+) = (.*);/m';
107
		preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0);
108
		$result = [];
109 View Code Duplication
		foreach ($matches as $match) {
0 ignored issues
show
The expression $matches of type null|array<integer,array<integer,string>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
			$result[$match[1]] = str_replace("'", "", $match[2]);
111
		}
112
113
		$this->fileId = $result['fileId'];
114
		$this->wopiToken = $result['token'];
115
	}
116
117
	/**
118
	 * @Then Collabora fetches checkFileInfo
119
	 */
120
	public function collaboraFetchesCheckfileinfo() {
121
		$client = new Client();
122
		$options = [];
123
		$result = $client->get($this->baseUrl . 'index.php/apps/richdocuments/wopi/files/' . $this->fileId . '?access_token=' . $this->wopiToken, $options);
124
		$this->checkFileInfoResult = json_decode($result->getBody()->getContents(), true);
125
	}
126
127
	/**
128
	 * @Then Collabora puts :source
129
	 */
130
	public function collaboraPuts($source)
131
	{
132
		$file = \GuzzleHttp\Psr7\stream_for(fopen($source, 'r'));
133
		$client = new Client();
134
		$options = [
135
			'data' => $file,
136
			'headers' => [
137
				'X-LOOL-WOPI-Timestamp' => $this->checkFileInfoResult['LastModifiedTime']
138
			]
139
		];
140
		try {
141
			$result = $client->post($this->baseUrl . 'index.php/apps/richdocuments/wopi/files/' . $this->fileId . '/contents?access_token=' . $this->wopiToken, $options);
142
			$this->checkFileInfoResult = json_decode($result->getBody()->getContents(), true);
143
		} catch (\GuzzleHttp\Exception\ClientException $e) {
0 ignored issues
show
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
144
			$this->response = $e->getResponse();
145
		}
146
	}
147
148
	/**
149
	 * @Then /^the HTTP status code should be "([^"]*)"$/
150
	 * @param int $statusCode
151
	 */
152
	public function theHTTPStatusCodeShouldBe($statusCode) {
153
		Assert::assertEquals($statusCode, $this->response->getStatusCode());
154
	}
155
156
157
	/**
158
	 * @Then checkFileInfo :arg1 is ":arg2"
159
	 */
160
	public function checkfileinfoIs($arg1, $arg2)
161
	{
162
		\PHPUnit\Framework\Assert::assertEquals($arg2, $this->checkFileInfoResult[$arg1]);
163
	}
164
165
166
	/**
167
	 * @Then checkFileInfo :arg1 matches ":arg2"
168
	 */
169
	public function checkfileinfoMatches($arg1, $arg2)
170
	{
171
		\PHPUnit\Framework\Assert::assertRegExp($arg2, $this->checkFileInfoResult[$arg1]);
172
	}
173
174
	/**
175
	 * @Then checkFileInfo :arg1 is true
176
	 */
177
	public function checkfileinfoIsTrue($arg1)
178
	{
179
		\PHPUnit\Framework\Assert::assertTrue($this->checkFileInfoResult[$arg1]);
180
	}
181
182
	/**
183
	 * @Then checkFileInfo :arg1 is false
184
	 */
185
	public function checkfileinfoIsFalse($arg1)
186
	{
187
		\PHPUnit\Framework\Assert::assertFalse($this->checkFileInfoResult[$arg1]);
188
	}
189
190
}
191