While working on frontend security projects, I encountered Blazor - here's what I learned.
Have questions? Feel free to ask in the comments section below.
正文
Low-level software protection engineer with 20+ years in native and managed code security. Creator of ArmDot, protecting commercial .NET applications since 2014.
Blazor WebAssembly Obfuscation: Protecting Client-Side .NET Code
Open the network tab in Chrome DevTools while loading a Blazor WebAssembly application. You will see a sequence of file requests - the .NET runtime, the application assemblies, the dependencies. Every one of those files is being downloaded to the browser. Every one of them contains your compiled .NET code. Every one of them can be saved, opened in ILSpy, and read.
This is not a misconfiguration or a security oversight. It is the fundamental architecture of how Blazor WebAssembly works. Understanding what that means for your application is the starting point for protecting it.
Blazor Server is a completely different story A note on the platform itself
Blazor-specific failure modes when applying obfuscation
When a user opens a Blazor WebAssembly application, the browser bootstraps a .NET runtime implemented in WebAssembly, then downloads your compiled assemblies to run them client-side. The entire application - your business logic, your algorithms, your string literals, your component hierarchy - executes in the browser rather than on a server.
In .NET 7 and earlier, the assemblies were served as standard
files. Any browser developer tool or download manager could save them directly.
In .NET 8 and later, Microsoft changed the delivery format. Assemblies are now packaged as
files using the Webcil format - a WebAssembly wrapper around the standard .NET assembly. The file extension changed. The content did not. A
file from a Blazor application can still be loaded into a .NET decompiler. The IL is still there, the metadata is still there, the string literals are still there.
The exposure is the same. The packaging is different.
Blazor WebAssembly supports ahead-of-time (AOT) compilation, which compiles the IL directly to native WebAssembly bytecode before deployment. This is sometimes cited as making the assembly exposure less relevant.
It does not. Even with AOT compilation enabled, the original .NET DLL files are still shipped alongside the compiled WebAssembly. This is documented by Microsoft: Blazor requires the DLLs for reflection metadata and to support certain .NET runtime features. The AOT-compiled
More Details
There are a few more points worth noting. First, browser compatibility varies across different browsers. Second, performance optimization is crucial when handling large amounts of data. Finally, key management is also an important consideration.
That's all for this comprehensive guide. I hope you found it helpful! Feel free to leave comments if you have questions.
Reference: Blazor WebAssembly Obfuscation: Protect Client-Side .NET