Server-side Blazor Protection
Shield provides comprehensive protection for Blazor Server applications, securing your server-side .NET code while maintaining optimal performance and compatibility.
Understanding Blazor Server Security Model
Blazor Server uses a different execution model than Blazor WebAssembly:
- Application logic runs on the server
- UI updates are sent to the client via SignalR
- The client runs a small JavaScript file that maintains the connection and updates the DOM
This architecture provides inherent security benefits since your code remains on the server. However, Shield adds multiple protection layers to prevent reverse engineering and tampering with your server-side assemblies.
Protection Strategy for Blazor Server
Shield applies several protection techniques optimized for Blazor Server applications:
- Assembly Protection: Secures your server-side assemblies against decompilation and analysis
- SignalR Message Protection: Ensures the integrity of communication between server and client
- Method Invocation Protection: Secures the method calls that might be exposed through SignalR
- Reference Hiding: Obfuscates references between components and services
- Server-side Performance Optimization: Maintains responsive UI updates while providing strong protection
Implementation
Prerequisites
- ByteHide Shield (Team, Scale, or Enterprise edition)
- Blazor Server project
Configuration
Create a shield.config.json
file in the root of your Blazor Server project:
{
"preset": "custom",
"protections": {
"rename": {
"rename_public": false
},
"control_flow_advance": {},
"virtualization": {},
"constants_encryption": {},
"constants_mutation": {}
}
}
Shield will automatically detect that your assembly is a Blazor Server application and apply the necessary optimizations.
Integration with MSBuild
Add Shield to your Blazor Server project using the NuGet package:
dotnet add package ByteHide.Shield
Recommended Protections
For Blazor Server applications, these protections provide the best balance of security and performance:
Protection | Recommendation | Notes |
---|---|---|
Renamer | ✓ Essential | Use rename_public: false to maintain component discovery |
Control Flow | ✓ Recommended | Provides strong protection for server-side logic |
Virtualization | ✓ Recommended | Secures all the code |
Anti-Debug | ✓ Recommended | Prevents unauthorized debugging of server code |
Constants Encryption | ✓ Recommended | Secures sensitive values and strings |
Constants Mutation | ✓ Recommended | Adds additional security to constant values |
Special Considerations
Component Discovery
Blazor Server relies on component discovery for routing and rendering. Shield automatically detects and preserves Blazor component names through its built-in analyzer. To ensure your application works correctly:
- Set
rename_public: false
in the Renamer protection - Use
[Obfuscation(Exclude = true)]
attribute on components that use routing - Consider excluding the
OnInitialized
andOnParametersSet
methods from control flow protection - Avoid renaming public members that are used by Blazor's component system
SignalR Communication
Shield automatically applies protection to the SignalR communication channel, ensuring:
- Message integrity validation
- Circuit tampering protection
- Enhanced security for remote method invocation
Testing Protected Applications
After applying Shield protection to your Blazor Server application:
- Build your application in Release mode
- Verify all routes and navigation work correctly
- Test component initialization and parameter passing
- Verify real-time updates and SignalR communication
- Check performance under typical user loads
Blazor Server applications benefit from Shield's server-side protections while maintaining the security advantage of keeping your code on the server. This combination provides robust protection against reverse engineering.
Compatibility Considerations
Shield's Blazor Server protection is compatible with:
- Blazor Server 3.2+
- All modern browsers (Chrome, Firefox, Safari, Edge)
- Component libraries like Telerik, Syncfusion, and Radzen
- Authentication providers including Identity, Auth0, and Azure AD
- Hosting on Windows, Linux, and macOS