-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathDavisTemporaryFileFilterPlugin.php
More file actions
46 lines (39 loc) 路 1.55 KB
/
Copy pathDavisTemporaryFileFilterPlugin.php
File metadata and controls
46 lines (39 loc) 路 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace App\Plugins;
use Sabre\DAV\TemporaryFileFilterPlugin;
use Sabre\DAVACL\Plugin as AclPlugin;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Sabre\Uri;
/**
* sabre/dav's TemporaryFileFilterPlugin intercepts the junk files desktop clients
* write next to real files (.DS_Store, Thumbs.db, ._*, *.swp, ...) and stores them
* outside the DAV tree. Because those files never exist in the tree, the ACL plugin
* never checks anything for them: without this subclass, anybody (authenticated or
* not) could store, read and delete such files under any path.
*
* We make temporary files obey the privileges of the directory they would live in,
* exactly like a real file would.
*/
final class DavisTemporaryFileFilterPlugin extends TemporaryFileFilterPlugin
{
public function beforeMethod(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
if (false === $this->isTempFile($path)) {
return;
}
$acl = $this->server->getPlugin('acl');
if ($acl instanceof AclPlugin) {
[$parent] = Uri\split($path);
$privilege = match ($request->getMethod()) {
'PUT' => '{DAV:}bind',
'DELETE' => '{DAV:}unbind',
default => '{DAV:}read',
};
// Throws NotAuthenticated (401) for anonymous users and NeedPrivileges (403) otherwise
$acl->checkPrivileges($parent ?? '', $privilege);
}
return parent::beforeMethod($request, $response);
}
}