Skip to content

GordonRudman/BlazorWasmAntivirusProtection

 
 

Repository files navigation

Blazor Wasm Antivirus Protection

Nuget (with prereleases) Donate

This package attempts to guard against false positives from antiviruses that flag Blazor Wasm as malware, until (or if) Microsoft gives us an official solution.

Confirmed success against:

  1. BitDefender Total Security (v26.0.10.45)
  2. BitDefender Endpoint Security Tool (v7.4.3.146)
  3. Smoothwall Firewall - Confirmed by peterthorpe81
  4. Sophos Endpoint Agent - Confirmed by peterthorpe81
  5. Forcepoint Firewall - Confirmed by egil

📣 If you have used this package and has helped you bypass any false positives from other security software, please consider creating an issue with your experience to contribute to this list.

🛡️ You can use virustotal's online scanner for some indication of how various antiviruses view your site.

What does this package do ?

This package injects some custom MSBuild tasks that do the following during publishing:

  1. Obfuscates all client assemblies so that firewalls and antiviruses don't see them as executables. Obfuscation methods supported:
    • Using a key to XOR all client assemblies (default).
    • OR
    • Changing the MZ header of all client assemblies to BZ, a custom header (less aggressive - more info here)
  2. Renames the extension of all client assemblies from .dll to .bin
  3. Adds a lib.module.js that contains a beforeStart blazor initialization method (more info here), that uses a custom loadBootResource function to restore the obfuscation of the assemblies after downloaded, but before loaded by dotnet.wasm

How to use

  1. Add the nuget package in your Client (wasm) AND your Server (if using blazor wasm hosted) projects
dotnet add package BlazorWasmAntivirusProtection
  1. (Progressive Web Applications only): If you are using the Blazor Wasm PWA template, update the following line in your service-worker.published.js file to include .bin files:
const offlineAssetsInclude = [/\.bin$/, /\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/, /\.blat$/, /\.dat$/ ];
  1. Publish your app in Release mode and test it!
dotnet publish Server\BlazorHostedSampleApp.Server.csproj -c Release

Nuget package page can be found here.

Configuration

The following options allow you to customize the tasks executed by this package.

Custom dll rename extension

If you want to use a different extension for renaming dlls, for example ".blz", add the following property in the published project's .csproj file (Server project if using blazor hosted).

<RenameDllsTo>blz</RenameDllsTo>

Disable dll rename

You can disable dll renaming by adding the following property in the published project's .csproj file (Server project if using blazor hosted).

<DisableRenamingDlls>true</DisableRenamingDlls>

Changing or disabling dll obfuscation

You can change or disable dll obfuscation by adding the following property in your Client project's .csproj file. Supported values:

  • None
  • ChangeHeaders
  • Xor (default)
<!-- Disables dll obfuscation -->
<ObfuscationMode>None</ObfuscationMode> 

Changing the XOR obfuscation key

You can change the key that is used for the XOR obfuscation adding the following property in your Client project's .csproj file.

<!-- Changes the dll obfuscation xor key -->
<XorKey>mykey</XorKey>

Samples / Demo

You can find a sample app using this package here.

You can see the its virus total scan result here.

Special Thanks

This work was inspired by the post in dotnet/aspnetcore#31048 (comment) by github user tedd

Release Notes

1.6
  • Fix for publishing twice before cleaning (regression) #13
1.5
  • Added support for multiple dll obfuscations, changing the default to XORing the dlls instead of just changing the headers.
1.4
  • Added support for Multiple Blazor Wasm apps under the same Server project #8
1.3
  • Added support for Blazor Wasm PWA apps
1.2
  • Fixed sequential publishing issue.
1.0
  • Added customization options.
0.1
  • Initial release.

About

Antivirus protection for Blazor Wasm projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 34.8%
  • HTML 28.2%
  • CSS 20.8%
  • JavaScript 10.8%
  • PowerShell 5.4%