Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't count range download in download limit #35324

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions apps/files_sharing/lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,14 @@
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
$originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());

$isVideoAudio = false;

// Single file share
if ($share->getNode() instanceof \OCP\Files\File) {
$node = $share->getNode();
// Single file download
$this->singleFileDownloaded($share, $share->getNode());
$this->singleFileDownloaded($share, $node);
$isVideoAutio = str_starts_with($node->getMimeType(), 'video/') || str_starts_with($node->getMimeType(), 'audio/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$isVideoAutio = str_starts_with($node->getMimeType(), 'video/') || str_starts_with($node->getMimeType(), 'audio/');
$isVideoAudio = str_starts_with($node->getMimeType(), 'video/') || str_starts_with($node->getMimeType(), 'audio/');

}
// Directory share
else {
Expand All @@ -398,8 +401,10 @@
$originalSharePath = $userFolder->getRelativePath($node->getPath());

if ($node instanceof \OCP\Files\File) {
$node = $share->getNode();
// Single file download
$this->singleFileDownloaded($share, $share->getNode());
$this->singleFileDownloaded($share, $node);
$isVideoAutio = str_starts_with($node->getMimeType(), 'video/') || str_starts_with($node->getMimeType(), 'audio/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$isVideoAutio = str_starts_with($node->getMimeType(), 'video/') || str_starts_with($node->getMimeType(), 'audio/');
$isVideoAudio = str_starts_with($node->getMimeType(), 'video/') || str_starts_with($node->getMimeType(), 'audio/');

} else {
try {
if (!empty($files_list)) {
Expand Down Expand Up @@ -427,11 +432,15 @@
&& !isset($downloadStartSecret[32])
&& preg_match('!^[a-zA-Z0-9]+$!', $downloadStartSecret) === 1) {
// FIXME: set on the response once we use an actual app framework response
setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/');

Check failure on line 435 in apps/files_sharing/lib/Controller/ShareController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-security

TaintedCookie

apps/files_sharing/lib/Controller/ShareController.php:435:35: TaintedCookie: Detected tainted cookie (see https://psalm.dev/257)

Check failure on line 435 in apps/files_sharing/lib/Controller/ShareController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-security

TaintedCookie

apps/files_sharing/lib/Controller/ShareController.php:435:35: TaintedCookie: Detected tainted cookie (see https://psalm.dev/257)
}

$this->emitAccessShareHook($share);
$this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD);

// Ensure download limit is counted unless we are streaming a video or audio file
if (!isset($_SERVER['HTTP_RANGE']) || !$isVideoAudio) {

Check failure on line 441 in apps/files_sharing/lib/Controller/ShareController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

apps/files_sharing/lib/Controller/ShareController.php:441:41: RedundantCondition: Operand of type true is always truthy (see https://psalm.dev/122)

Check failure on line 441 in apps/files_sharing/lib/Controller/ShareController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

apps/files_sharing/lib/Controller/ShareController.php:441:41: RedundantCondition: Type false for $isVideoAudio is always falsy (see https://psalm.dev/122)

Check failure on line 441 in apps/files_sharing/lib/Controller/ShareController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

apps/files_sharing/lib/Controller/ShareController.php:441:41: RedundantCondition: Operand of type true is always truthy (see https://psalm.dev/122)

Check failure on line 441 in apps/files_sharing/lib/Controller/ShareController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

apps/files_sharing/lib/Controller/ShareController.php:441:41: RedundantCondition: Type false for $isVideoAudio is always falsy (see https://psalm.dev/122)

Check failure

Code scanning / Psalm

RedundantCondition Error

Operand of type true is always truthy

Check failure

Code scanning / Psalm

RedundantCondition Error

Type false for $isVideoAudio is always falsy
$this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD);
}

$server_params = [ 'head' => $this->request->getMethod() === 'HEAD' ];

Expand Down
Loading