Issues (45)

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/Native/NativeFileInfo.php (5 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
/**
3
 * Copyright (c) 2014 Robin Appelman <[email protected]>
4
 * This file is licensed under the Licensed under the MIT license:
5
 * http://opensource.org/licenses/MIT
6
 */
7
8
namespace Icewind\SMB\Native;
9
10
use Icewind\SMB\ACL;
11
use Icewind\SMB\Exception\Exception;
12
use Icewind\SMB\IFileInfo;
13
14
class NativeFileInfo implements IFileInfo {
15
	/** @var string */
16
	protected $path;
17
	/** @var string */
18
	protected $name;
19
	/** @var NativeShare */
20
	protected $share;
21
	/** @var array{"mode": int, "size": int, "write_time": int}|null */
22
	protected $attributeCache = null;
23
24
	public function __construct(NativeShare $share, string $path, string $name) {
25
		$this->share = $share;
26
		$this->path = $path;
27
		$this->name = $name;
28
	}
29
30
	public function getPath(): string {
31
		return $this->path;
32
	}
33
34
	public function getName(): string {
35
		return $this->name;
36
	}
37
38
	/**
39 210
	 * @return array{"mode": int, "size": int, "write_time": int}
0 ignored issues
show
The doc-type array{"mode": could not be parsed: Unknown type name "array{"mode":" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
40 210
	 */
41 210
	protected function stat(): array {
42 210
		if (is_null($this->attributeCache)) {
43 210
			$rawAttributes = explode(',', $this->share->getAttribute($this->path, 'system.dos_attr.*'));
44
			$attributes = [];
45
			foreach ($rawAttributes as $rawAttribute) {
46
				list($name, $value) = explode(':', $rawAttribute);
47
				$name = strtolower($name);
48 184
				if ($name == 'mode') {
49 184
					$attributes[$name] = (int)hexdec(substr($value, 2));
50
				} else {
51
					$attributes[$name] = (int)$value;
52
				}
53
			}
54
			if (!isset($attributes['mode'])) {
55 98
				throw new Exception("Invalid attribute response");
56 98
			}
57
			if (!isset($attributes['size'])) {
58
				throw new Exception("Invalid attribute response");
59
			}
60
			if (!isset($attributes['write_time'])) {
61
				throw new Exception("Invalid attribute response");
62 210
			}
63 210
			$this->attributeCache = $attributes;
64 210
		}
65 190
		return $this->attributeCache;
66 190
	}
67 190
68 190
	public function getSize(): int {
69 190
		$stat = $this->stat();
70 190
		return $stat['size'];
71
	}
72 190
73
	public function getMTime(): int {
74
		$stat = $this->stat();
75
		return $stat['write_time'];
76 190
	}
77
78
	/**
79
	 * On "mode":
80
	 *
81
	 * different smbclient versions seem to return different mode values for 'system.dos_attr.mode'
82 82
	 *
83 82
	 * older versions return the dos permissions mask as defined in `IFileInfo::MODE_*` while
84 62
	 * newer versions return the equivalent unix permission mask.
85
	 *
86
	 * Since the unix mask doesn't contain the proper hidden/archive/system flags we have to assume them
87
	 * as false (except for `hidden` where we use the unix dotfile convention)
88
	 */
89
90 2
	protected function getMode(): int {
91 2
		$mode = $this->stat()['mode'];
92 2
93
		// Let us ignore the ATTR_NOT_CONTENT_INDEXED for now
94
		$mode &= ~0x00002000;
95
96
		return $mode;
97
	}
98
99 View Code Duplication
	public function isDirectory(): bool {
0 ignored issues
show
This method seems to be duplicated in 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...
100
		$mode = $this->getMode();
101
		if ($mode > 0x1000) {
102
			return (bool)($mode & 0x4000); // 0x4000: unix directory flag
103
		} else {
104
			return (bool)($mode & IFileInfo::MODE_DIRECTORY);
105
		}
106
	}
107
108 View Code Duplication
	public function isReadOnly(): bool {
0 ignored issues
show
This method seems to be duplicated in 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...
109
		$mode = $this->getMode();
110 184
		if ($mode > 0x1000) {
111 184
			return !(bool)($mode & 0x80); // 0x80: owner write permissions
112
		} else {
113
			return (bool)($mode & IFileInfo::MODE_READONLY);
114 184
		}
115
	}
116 184
117
	public function isHidden(): bool {
118
		$mode = $this->getMode();
119
		if ($mode > 0x1000) {
120
			return strlen($this->name) > 0 && $this->name[0] === '.';
121
		} else {
122 184
			return (bool)($mode & IFileInfo::MODE_HIDDEN);
123 184
		}
124 184
	}
125
126 View Code Duplication
	public function isSystem(): bool {
0 ignored issues
show
This method seems to be duplicated in 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...
127 184
		$mode = $this->getMode();
128
		if ($mode > 0x1000) {
129
			return false;
130
		} else {
131
			return (bool)($mode & IFileInfo::MODE_SYSTEM);
132
		}
133
	}
134 2
135 2 View Code Duplication
	public function isArchived(): bool {
0 ignored issues
show
This method seems to be duplicated in 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...
136 2
		$mode = $this->getMode();
137
		if ($mode > 0x1000) {
138
			return false;
139 2
		} else {
140
			return (bool)($mode & IFileInfo::MODE_ARCHIVE);
141
		}
142
	}
143
144
	/**
145
	 * @return ACL[]
146 12
	 */
147 12
	public function getAcls(): array {
148 12
		$acls = [];
149
		$attribute = $this->share->getAttribute($this->path, 'system.nt_sec_desc.acl.*+');
150
151 12
		foreach (explode(',', $attribute) as $acl) {
152
			list($user, $permissions) = explode(':', $acl, 2);
153
			$user = trim($user, '\\');
154
			list($type, $flags, $mask) = explode('/', $permissions);
155
			$mask = hexdec($mask);
156
157
			$acls[$user] = new ACL((int)$type, (int)$flags, (int)$mask);
158
		}
159
160
		return $acls;
161
	}
162
}
163