WebAssembly Obfuscation Strategy
Shield employs specialized obfuscation techniques designed specifically for WebAssembly applications, ensuring strong protection while maintaining compatibility with browser environments.
WebAssembly Obfuscation Challenges
WebAssembly presents unique obfuscation challenges compared to traditional .NET applications:
- WebAssembly has a simpler instruction set than .NET IL
- The structured control flow of WebAssembly limits traditional control flow obfuscation
- Browser validation enforces strict requirements on WebAssembly modules
- Performance considerations are critical in browser environments
- The JavaScript interop layer requires special attention
Shield addresses these challenges with WebAssembly-specific obfuscation techniques.
Multi-Layer Obfuscation Approach
Shield applies obfuscation at multiple layers in WebAssembly applications:
1. .NET IL Obfuscation
Before compilation to WebAssembly, Shield applies compatible transformations to the .NET IL code:
- Name obfuscation of internal methods, types, and fields
- Control flow transformations that work with the WebAssembly compiler
- String and constant encryption with WebAssembly-compatible decoding
2. WebAssembly Binary Obfuscation
After WebAssembly compilation, Shield applies additional binary-level transformations:
- Function reordering and restructuring
- Export name obfuscation for non-essential exports
- Custom section protection and metadata hiding
3. JavaScript Layer Obfuscation
The JavaScript code that interacts with WebAssembly is also protected:
- Interop function name obfuscation
- Call site obfuscation
- Anti-tampering measures
Specialized WebAssembly Techniques
WASM-Compatible Name Obfuscation
Shield uses specialized name obfuscation that preserves WebAssembly functionality:
{
"wasm": {
"nameObfuscation": {
"internalFunctions": true,
"exports": "preserveRequired",
"imports": "compatible"
}
}
}{
"wasm": {
"nameObfuscation": {
"internalFunctions": true,
"exports": "preserveRequired",
"imports": "compatible"
}
}
}WebAssembly Control Flow Obfuscation
Shield adapts control flow obfuscation to work within WebAssembly's structured control flow requirements:
{
"wasm": {
"controlFlow": {
"mode": "structured",
"intensity": 7
}
}
}{
"wasm": {
"controlFlow": {
"mode": "structured",
"intensity": 7
}
}
}String and Constant Protection
String constants are protected using WebAssembly-compatible encoding:
{
"wasm": {
"stringProtection": {
"encoding": "wasm-compatible",
"dynamicDecoding": true
}
}
}{
"wasm": {
"stringProtection": {
"encoding": "wasm-compatible",
"dynamicDecoding": true
}
}
}Blazor WebAssembly-Specific Obfuscation
For Blazor WebAssembly applications, Shield provides additional specialized techniques:
Component Protection
Blazor components require special handling:
{
"wasm": {
"blazor": {
"componentProtection": "compatible",
"preserveRouting": true
}
}
}{
"wasm": {
"blazor": {
"componentProtection": "compatible",
"preserveRouting": true
}
}
}Razor Page Protection
Shield can protect Razor pages while maintaining functionality:
{
"wasm": {
"blazor": {
"razorProtection": true,
"preserveComponentNames": "routing-only"
}
}
}{
"wasm": {
"blazor": {
"razorProtection": true,
"preserveComponentNames": "routing-only"
}
}
}Optimizing Obfuscation for Performance
WebAssembly applications are particularly sensitive to performance impacts. Shield provides options to balance security and performance:
Performance-Focused Configuration
{
"wasm": {
"obfuscation": {
"performanceProfile": "balanced", // Options: "performance", "balanced", "security"
"startupImpact": "minimal"
}
}
}{
"wasm": {
"obfuscation": {
"performanceProfile": "balanced", // Options: "performance", "balanced", "security"
"startupImpact": "minimal"
}
}
}Selective Protection
Apply stronger protection to critical parts of your application:
{
"wasm": {
"selectiveProtection": {
"criticalNamespaces": ["MyApp.Core.Security", "MyApp.Licensing"],
"criticalProtectionLevel": "maximum"
}
}
}{
"wasm": {
"selectiveProtection": {
"criticalNamespaces": ["MyApp.Core.Security", "MyApp.Licensing"],
"criticalProtectionLevel": "maximum"
}
}
}Advanced Obfuscation Techniques
Code Splitting and Lazy Loading Protection
For applications that use code splitting and lazy loading:
{
"wasm": {
"codeSplitting": {
"protectLazyLoadedModules": true,
"consistentObfuscation": true
}
}
}{
"wasm": {
"codeSplitting": {
"protectLazyLoadedModules": true,
"consistentObfuscation": true
}
}
}Dead Code Injection
Shield can inject decoy code to further confuse analysis:
{
"wasm": {
"deadCodeInjection": {
"enabled": true,
"complexity": "medium"
}
}
}{
"wasm": {
"deadCodeInjection": {
"enabled": true,
"complexity": "medium"
}
}
}Custom Watermarking
Add invisible watermarks to track your protected code:
{
"wasm": {
"watermarking": {
"enabled": true,
"includeMetadata": false
}
}
}{
"wasm": {
"watermarking": {
"enabled": true,
"includeMetadata": false
}
}
}Integration with Browser Features
Source Map Handling
Control how source maps are handled:
{
"wasm": {
"sourceMapHandling": "remove", // Options: "remove", "obfuscate", "protect"
"produceDebugSymbols": false
}
}{
"wasm": {
"sourceMapHandling": "remove", // Options: "remove", "obfuscate", "protect"
"produceDebugSymbols": false
}
}Content Security Policy Integration
Shield can work with Content Security Policy (CSP):
{
"wasm": {
"cspCompatibility": true,
"noncedResources": true
}
}{
"wasm": {
"cspCompatibility": true,
"noncedResources": true
}
}Best Practices for WebAssembly Obfuscation
- Start with standard protections: Apply the basic protections before adding WebAssembly-specific ones
- Test incrementally: Add protections gradually and test after each step
- Balance performance: Monitor the impact on startup time and runtime performance
- Test across browsers: Verify that protections work in all target browsers
- Defense in depth: Combine client-side obfuscation with server-side validation
Shield automatically adjusts its protection techniques based on your application's structure and the target browser environment. The default settings provide a good balance of security and performance for most applications.
For more information on browser security constraints, see Browser Security Context.