{"id":15411497,"url":"https://github.com/csharpfritz/aspireantivirus","last_synced_at":"2025-10-15T17:46:38.340Z","repository":{"id":247482121,"uuid":"825965891","full_name":"csharpfritz/AspireAntivirus","owner":"csharpfritz","description":"Proof of concept showing how to add ClamAV antivirus detection to a .NET Aspire application","archived":false,"fork":false,"pushed_at":"2024-07-11T13:24:13.000Z","size":125,"stargazers_count":18,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-01T07:36:18.838Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csharpfritz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-08T21:13:53.000Z","updated_at":"2025-06-18T11:03:10.000Z","dependencies_parsed_at":"2024-07-11T15:17:09.055Z","dependency_job_id":"aff3c755-362b-454e-99e3-f1317194c90f","html_url":"https://github.com/csharpfritz/AspireAntivirus","commit_stats":null,"previous_names":["csharpfritz/aspireantivirus"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/csharpfritz/AspireAntivirus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csharpfritz%2FAspireAntivirus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csharpfritz%2FAspireAntivirus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csharpfritz%2FAspireAntivirus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csharpfritz%2FAspireAntivirus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csharpfritz","download_url":"https://codeload.github.com/csharpfritz/AspireAntivirus/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csharpfritz%2FAspireAntivirus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273549356,"owners_count":25125282,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T16:49:17.760Z","updated_at":"2025-10-15T17:46:38.237Z","avatar_url":"https://github.com/csharpfritz.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AspireAntivirus\n\nA proof of concept showing how to add ClamAV antivirus detection to a .NET Aspire application.  Blog post about this idea at: https://jeffreyfritz.com/2024/07/adding-antivirus-to-net-aspire-systems/\n\n## Purpose\n\nAt some point in our applications, we want our users to be able to submit content for others to work with.  This might be text and it might be some files.  If you want to enable file uploads for your projects, there are some great samples on Microsoft Learn.  However, they ALL [recommend that you inspect and test the files for malware](https://learn.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-8.0#security-considerations) before accepting and republishing their content.\n\nIn this sample, we've taken an original concept published by [Jeroen Verhaeghe on Medium](https://medium.com/@jeroenverhaeghe/building-a-malware-and-antivirus-scanner-in-net-core-e4309f2d429c) and extended it to work with .NET Aspire.  In Jeroen's original article, the [ClamAV antivirus scanner](https://www.clamav.net/) was introduced with the [nClam](https://github.com/tekmaven/nClam) library from [Ryan Hoffman](https://github.com/tekmaven).  Jeroen runs the ClamAV scanner in a Docker container, and in reading that I thought - why not let .NET Aspire manage the container for us?\n\nThat's what I did here. I've added a custom `ClamAvResource` to AppHost that will start the latest ClamAV container and pass the address for that container into the web project.\n\nAppHost/Program.cs\n```csharp\nvar builder = DistributedApplication.CreateBuilder(args);\n\nvar av = builder.AddClamAv(\"antivirus\");\n\nbuilder.AddProject\u003cProjects.AspireAvSample_Web\u003e(\"webfrontend\")\n\t\t.WithExternalHttpEndpoints()\n\t\t.WithReference(av);\n\nbuilder.Build().Run();\n```\n\nWe can then scan uploaded content as shown in Program_Services.cs:\n\n```csharp\n\nvar clamConfig = app.Configuration.GetConnectionString(\"antivirus\");\nif (string.IsNullOrEmpty(clamConfig)) throw new Exception(\"Missing antivirus configuration\");\nClamUri = new Uri(clamConfig);\n\n...\n\nvar clam = new ClamClient(ClamUri.Host, ClamUri.Port);\nvar scanResult = await clam.SendAndScanFileAsync(stream);\n\n...\n\nErrorMessage = scanResult.Result switch { \n\tClamScanResults.VirusDetected =\u003e $\"Virus {scanResult.InfectedFiles.First().VirusName} detected\",\n\tClamScanResults.Error =\u003e $\"Error with virus scanning.  Please try again\",\n\t_ =\u003e string.Empty\n},\n```\n\nYou can test the scanner with a standard antivirus sample available for researchers at https://www.eicar.org/download-anti-malware-testfile/  \n\nPlease read ALL warnings carefully when downloading antivirus samples to test with.  We are not responsible for your download of samples to test against.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsharpfritz%2Faspireantivirus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsharpfritz%2Faspireantivirus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsharpfritz%2Faspireantivirus/lists"}