Skip to content

Commit ac19989

Browse files
nickvergessenbackportbot[bot]
authored andcommitted
fix(trashbin): Strip off ".d{timestamp}" in trashbin folders
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 768e9d2 commit ac19989

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

lib/Operation.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,20 @@ protected function isBlockablePath(IStorage $storage, string $path): bool {
107107
}
108108

109109
// '', admin, 'files', 'path/to/file.txt'
110-
$segment = explode('/', $fullPath, 4);
110+
// '', admin, 'files_trashbin', 'versions', 'path/to/file.txt'
111+
$segment = explode('/', $fullPath, 5);
111112

112113
if (isset($segment[2]) && $segment[1] === '__groupfolders' && $segment[2] === 'trash') {
113114
// Special case, a file was deleted inside a groupfolder
114115
return true;
115116
}
116117

118+
if (isset($segment[3]) && $segment[2] === 'files_trashbin'
119+
&& ($segment[3] === 'keys' || !isset($segment[4]))) {
120+
// Ignore encryption keys in trashbin and the files and version folder themselves
121+
return false;
122+
}
123+
117124
return isset($segment[2]) && in_array($segment[2], [
118125
'files',
119126
'thumbnails',
@@ -138,6 +145,25 @@ protected function translatePath(IStorage $storage, string $path): string {
138145
// Remove trailing ".v{timestamp}"
139146
$innerPath = substr($innerPath, 0, -12);
140147
}
148+
return 'files/' . $innerPath;
149+
} elseif ($folder === 'files_trashbin') {
150+
// 'files', 'path/to/file.txt'
151+
// 'versions', 'path/to/file.txt'
152+
$segments = explode('/', $innerPath, 2);
153+
if (isset($segments[1])) {
154+
$innerPath = $segments[1];
155+
}
156+
157+
if (preg_match('/.+\.d\d{10}$/', basename($innerPath))) {
158+
// Remove trailing ".d{timestamp}" of trashbin
159+
$innerPath = substr($innerPath, 0, -12);
160+
}
161+
162+
if ($folder === 'versions' && preg_match('/.+\.v\d{10}$/', basename($innerPath))) {
163+
// Remove trailing ".v{timestamp}" of versions inside trashbin
164+
$innerPath = substr($innerPath, 0, -12);
165+
}
166+
141167
return 'files/' . $innerPath;
142168
} elseif ($folder === 'thumbnails') {
143169
[$fileId,] = explode('/', $innerPath, 2);

tests/Integration/features/mimetypes.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,16 @@
8585
And The webdav response should have a status code "403"
8686
When User "test1" copies file "/hello" to "/hello.txt"
8787
And The webdav response should have a status code "403"
88+
89+
Scenario: Blocking by mimetype works in trashbin
90+
Given User "test1" uploads file "data/textfile.txt" to "/foobar.txt"
91+
And user "admin" creates global flow with 200
92+
| name | Admin flow |
93+
| class | OCA\FilesAccessControl\Operation |
94+
| entity | OCA\WorkflowEngine\Entity\File |
95+
| events | [] |
96+
| operation | deny |
97+
| checks-0 | {"class":"OCA\\\\WorkflowEngine\\\\Check\\\\FileMimeType", "operator": "!is", "value": "httpd/unix-directory"} |
98+
| checks-1 | {"class":"OCA\\\\WorkflowEngine\\\\Check\\\\FileMimeType", "operator": "!is", "value": "text/plain"} |
99+
When User "test1" deletes file "/foobar.txt"
100+
Then The webdav response should have a status code "204"

0 commit comments

Comments
 (0)