Skip to content
Merged
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions lib/generic-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ async function validateAttachment(req) {

if (scanEnabled) {
if (status !== "Clean") {
cds.spawn(async () => {
try {
const srv = await cds.connect.to("attachments")
await srv.emit("AttachmentDownloadRejected", {
target: req.target.name,
keys: { ID: attachmentId },
status,
})
} catch (err) {
LOG.error("Failed to emit AttachmentDownloadRejected", err)
}
})
req.reject(403, "UnableToDownloadAttachmentScanStatusNotClean")
}

Expand Down Expand Up @@ -263,6 +275,21 @@ async function validateAttachmentSize(req, validateContentLength = false) {
.from(req.target)
.where({ up__ID: req.data.up__ID })

cds.spawn(async () => {
try {
const AttachmentsSrv = await cds.connect.to("attachments")
await AttachmentsSrv.emit("AttachmentSizeExceeded", {
target: req.target.name,
keys: req.data.ID ? { ID: req.data.ID } : {},
filename: attachmentRef?.filename ?? "n/a",
fileSize: length,
maxFileSize,
})
} catch (err) {
LOG.error("Failed to emit AttachmentSizeExceeded", err)
}
})

req.reject({
status: 413,
message: "AttachmentSizeExceeded",
Expand All @@ -289,6 +316,21 @@ function validateAttachmentMimeType(req) {
const acceptableMediaTypes =
req.target.elements.content["@Core.AcceptableMediaTypes"] || "*/*"
if (!checkMimeTypeMatch(acceptableMediaTypes, mimeType)) {
cds.spawn(async () => {
try {
const AttachmentsSrv = await cds.connect.to("attachments")
await AttachmentsSrv.emit("AttachmentUploadRejected", {
target: req.target.name,
keys: req.data.ID ? { ID: req.data.ID } : {},
filename: req.data.filename,
mimeType,
acceptableMediaTypes,
reason: `MIME type '${mimeType}' is not in @Core.AcceptableMediaTypes`,
})
} catch (err) {
LOG.error("Failed to emit AttachmentUploadRejected", err)
}
})
req.reject(400, "AttachmentMimeTypeDisallowed", {
mimeType: mimeType,
})
Expand Down
Loading
Loading