Skip to content

Commit 1f8f95d

Browse files
miaulalalabackportbot[bot]
authored andcommitted
fix: only write activites for actualy public uploads
Currently, any file activity without a proper session is interpreted to be a public upload. Now, the share token is compared and the activity is only written when the share token belongs to a public folder Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent 26f61f8 commit 1f8f95d

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

lib/CurrentUser.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,31 @@ public function getCloudId() {
102102
return $this->cloudId;
103103
}
104104

105+
/**
106+
* Check if the current request is via a public share link
107+
*/
108+
public function isPublicShareToken(): bool {
109+
/** @psalm-suppress NoInterfaceProperties */
110+
if (!empty($this->request->server['PHP_AUTH_USER'])) {
111+
$token = $this->request->server['PHP_AUTH_USER'];
112+
try {
113+
$share = $this->shareManager->getShareByToken($token);
114+
return $share->getShareType() === IShare::TYPE_LINK
115+
|| $share->getShareType() === IShare::TYPE_EMAIL;
116+
} catch (ShareNotFound $e) {
117+
// No share found for this token
118+
}
119+
}
120+
121+
return false;
122+
}
123+
105124
/**
106125
* Get the cloud ID from the sharing token
107126
* @return string|null
108127
*/
109128
protected function getCloudIDFromToken() {
129+
/** @psalm-suppress NoInterfaceProperties */
110130
if (!empty($this->request->server['PHP_AUTH_USER'])) {
111131
$token = $this->request->server['PHP_AUTH_USER'];
112132
/**

lib/FilesHooks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function fileCreate($path) {
8282
return;
8383
}
8484

85-
if ($this->currentUser->getUserIdentifier() !== '') {
85+
if ($this->currentUser->getUserIdentifier() !== '' || !$this->currentUser->isPublicShareToken()) {
8686
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, 'created_self', 'created_by');
8787
} else {
8888
$this->addNotificationsForFileAction($path, Files_Sharing::TYPE_PUBLIC_UPLOAD, '', 'created_public');

tests/FilesHooksTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ protected function getUserMock(string $uid): IUser {
176176

177177
public static function dataFileCreate(): array {
178178
return [
179-
['user', 'created_self', 'created_by', Files::TYPE_SHARE_CREATED],
180-
['', '', 'created_public', Files_Sharing::TYPE_PUBLIC_UPLOAD],
179+
['user', false, 'created_self', 'created_by', Files::TYPE_SHARE_CREATED],
180+
['', true, '', 'created_public', Files_Sharing::TYPE_PUBLIC_UPLOAD],
181+
['', false, 'created_self', 'created_by', Files::TYPE_SHARE_CREATED],
181182
];
182183
}
183184

0 commit comments

Comments
 (0)