Skip to content

Commit 701130a

Browse files
committed
Don't allow download for e2e encrypted files
1 parent 25a3b87 commit 701130a

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

internal/webserver/api/Api.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ func apiDownloadSingle(w http.ResponseWriter, r requestParser, user models.User)
463463
sendError(w, http.StatusUnauthorized, "No permission to download file")
464464
return
465465
}
466+
if file.Encryption.IsEndToEndEncrypted {
467+
sendError(w, http.StatusBadRequest, "End-to-End encrypted files cannot be downloaded")
468+
return
469+
}
466470
if !request.PresignUrl {
467471
storage.ServeFile(file, w, request.WebRequest, true, request.IncreaseCounter)
468472
return
@@ -474,8 +478,9 @@ func apiDownloadSingle(w http.ResponseWriter, r requestParser, user models.User)
474478
}
475479
database.SavePresignedUrl(presignUrl)
476480
response := struct {
481+
Result string `json:"Result"`
477482
DownloadUrl string `json:"downloadUrl"`
478-
}{configuration.Get().ServerUrl + "downloadPresigned?key=" + presignUrl.Id + "&id=" + file.Id}
483+
}{"OK", configuration.Get().ServerUrl + "downloadPresigned?key=" + presignUrl.Id + "&id=" + file.Id}
479484
result, err := json.Marshal(response)
480485
helper.Check(err)
481486
_, _ = w.Write(result)
@@ -520,7 +525,7 @@ func apiDuplicateFile(w http.ResponseWriter, r requestParser, user models.User)
520525
request.UnlimitedTime,
521526
request.UnlimitedDownloads,
522527
false, // is not being used by storage.DuplicateFile
523-
0) // is not being used by storage.DuplicateFile
528+
0) // is not being used by storage.DuplicateFile
524529
newFile, err := storage.DuplicateFile(file, request.RequestedChanges, request.FileName, uploadRequest)
525530
if err != nil {
526531
sendError(w, http.StatusInternalServerError, err.Error())

internal/webserver/web/static/apidocumentation/openapi.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"files"
115115
],
116116
"summary": "Downloads file with optionally increasing the download counter",
117-
"description": "This API call downloads a file that is not expired and increasing its download counter is disabled by default. Can be set up to return a pre-signed URL instead of the file itself, which is valid for 30 seconds and can be accessed by any registered user. Returns 404 if an invalid/expired ID was passed. Requires API permission DOWNLOAD. To download files that were not uploaded by the user, the user needs to have the user permission LIST",
117+
"description": "This API call downloads a file that is not expired and increasing its download counter is disabled by default. Can be set up to return a pre-signed URL instead of the file itself, which is valid for 30 seconds and can be accessed by any registered user. End-to-end encrypted files cannot be downloaded. Returns 404 if an invalid/expired ID was passed. Requires API permission DOWNLOAD. To download files that were not uploaded by the user, the user needs to have the user permission LIST",
118118
"operationId": "downloadsingle",
119119
"parameters": [
120120
{
@@ -142,7 +142,7 @@
142142
"schema": {
143143
"type": "boolean"
144144
},
145-
"description": "Return a pre-signed URL instead of the actual file. Valid for 30 seconds and can only be used by logged in users"
145+
"description": "Return a pre-signed URL instead of the actual file. Valid for one download within 30 seconds and can only be used by logged in users"
146146
}
147147
],
148148
"security": [
@@ -176,7 +176,7 @@
176176
}
177177
},
178178
"400": {
179-
"description": "Invalid input"
179+
"description": "Invalid input or trying to download an end-to-end encrypted file"
180180
},
181181
"401": {
182182
"description": "Invalid API key provided for authentication or API key does not have the required permission"

internal/webserver/web/static/js/admin_ui_upload.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,9 @@ function createButtonGroup(item) {
799799
btnDownload.type = 'button';
800800
btnDownload.className = 'btn btn-outline-light btn-sm';
801801
btnDownload.title = 'Download';
802+
if (item.IsEndToEndEncrypted) {
803+
btnDownload.classList.add("disabled");
804+
}
802805

803806
const downloadIcon = document.createElement('i');
804807
downloadIcon.className = 'bi bi-download';

internal/webserver/web/static/js/min/admin.min.15.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/webserver/web/templates/html_admin.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
<button
199199
type="button"
200200
title="Download"
201-
class="btn btn-outline-light btn-sm"
201+
class="btn btn-outline-light btn-sm {{if .CurrentFile.IsEndToEndEncrypted}}disabled{{end}}"
202202
onclick="downloadFileWithPresign('{{.CurrentFile.Id }}', false);">
203203
<i class="bi bi-download"></i>
204204
</button>

openapi.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"files"
115115
],
116116
"summary": "Downloads file with optionally increasing the download counter",
117-
"description": "This API call downloads a file that is not expired and increasing its download counter is disabled by default. Can be set up to return a pre-signed URL instead of the file itself, which is valid for 30 seconds and can be accessed by any registered user. Returns 404 if an invalid/expired ID was passed. Requires API permission DOWNLOAD. To download files that were not uploaded by the user, the user needs to have the user permission LIST",
117+
"description": "This API call downloads a file that is not expired and increasing its download counter is disabled by default. Can be set up to return a pre-signed URL instead of the file itself, which is valid for 30 seconds and can be accessed by any registered user. End-to-end encrypted files cannot be downloaded. Returns 404 if an invalid/expired ID was passed. Requires API permission DOWNLOAD. To download files that were not uploaded by the user, the user needs to have the user permission LIST",
118118
"operationId": "downloadsingle",
119119
"parameters": [
120120
{
@@ -142,7 +142,7 @@
142142
"schema": {
143143
"type": "boolean"
144144
},
145-
"description": "Return a pre-signed URL instead of the actual file. Valid for 30 seconds and can only be used by logged in users"
145+
"description": "Return a pre-signed URL instead of the actual file. Valid for one download within 30 seconds and can only be used by logged in users"
146146
}
147147
],
148148
"security": [
@@ -176,7 +176,7 @@
176176
}
177177
},
178178
"400": {
179-
"description": "Invalid input"
179+
"description": "Invalid input or trying to download an end-to-end encrypted file"
180180
},
181181
"401": {
182182
"description": "Invalid API key provided for authentication or API key does not have the required permission"

0 commit comments

Comments
 (0)