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

Feature/malware info #362

Merged
merged 6 commits into from
Mar 20, 2024
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
5 changes: 5 additions & 0 deletions src/Altinn.Broker.API/Controllers/ResourceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public async Task<ActionResult> UpdateMaxFileTransferSize([FromBody] ResourceExt
{
return BadRequest("Max upload size cannot be negative");
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
}
if (resourceExt.MaxFileTransferSize == 0)
{
return BadRequest("Max upload size cannot be zero");
}

if (resourceExt.MaxFileTransferSize == resource.MaxFileTransferSize)
{
return BadRequest("Max upload size is already set to the requested value");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

using System.Text.Json;

using Altinn.Broker.Application.ExpireFileTransferCommand;
using Altinn.Broker.Core.Application;
using Altinn.Broker.Core.Domain;
using Altinn.Broker.Core.Repositories;
using Altinn.Broker.Core.Services;
using Altinn.Broker.Core.Services.Enums;

using Hangfire;

using Microsoft.Extensions.Logging;

using OneOf;
Expand All @@ -18,17 +21,20 @@ public class MalwareScanningResultHandler : IHandler<ScanResultData, Task>
private readonly IFileTransferRepository _fileTransferRepository;
private readonly IEventBus _eventBus;
private readonly ILogger<MalwareScanningResultHandler> _logger;
private readonly IBackgroundJobClient _backgroundJobClient;

public MalwareScanningResultHandler(
IFileTransferStatusRepository fileTransferStatusRepository,
IFileTransferRepository fileTransferRepository,
IEventBus eventBus,
ILogger<MalwareScanningResultHandler> logger)
ILogger<MalwareScanningResultHandler> logger,
IBackgroundJobClient backgroundJobClient)
{
_fileTransferStatusRepository = fileTransferStatusRepository;
_fileTransferRepository = fileTransferRepository;
_eventBus = eventBus;
_logger = logger;
_backgroundJobClient = backgroundJobClient;
}

public async Task<OneOf<Task, Error>> Process(ScanResultData data, CancellationToken cancellationToken)
Expand All @@ -55,8 +61,13 @@ public async Task<OneOf<Task, Error>> Process(ScanResultData data, CancellationT
}

_logger.LogWarning("Suspicious scan result for file transfer {fileTransferId} with body {body}", fileTransferId, JsonSerializer.Serialize(data));
await _fileTransferStatusRepository.InsertFileTransferStatus(fileTransferId, Core.Domain.Enums.FileTransferStatus.Failed, $"Malware scan failed: {data.ScanResultType}", cancellationToken);
await _fileTransferStatusRepository.InsertFileTransferStatus(fileTransferId, Core.Domain.Enums.FileTransferStatus.Failed, $"Malware scan failed: {data.ScanResultType}. Extra details: " + JsonSerializer.Serialize(data.ScanResultDetails), cancellationToken);
await _eventBus.Publish(AltinnEventType.UploadFailed, fileTransfer.ResourceId, fileTransferIdFromUri, fileTransfer.Sender.ActorExternalId, cancellationToken);
_backgroundJobClient.Enqueue<ExpireFileTransferCommandHandler>(handler => handler.RescheduleExpireEvent(new ExpireFileTransferCommandRequest
{
FileTransferId = fileTransfer.FileTransferId,
Force = true
}, CancellationToken.None));
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public class ScanResultDetails
{
public List<string> MalwareNamesFound { get; set; } = new List<string>();
public string Sha256 { get; set; } = string.Empty;
public string NotScannedReason { get; set; } = string.Empty;
}
}
Loading