r/Blazor • u/Personal_Peak9589 • Apr 05 '23
Blazor WASM to Server - protect the code
Hi there, here is my story. I created WASM app as internal tool for my company. I choosen WASM because app is working with confidential documents so it cannot leave the company network. Later I realized I also want to protect the code (dont want to comment reasons). I was thinking to obfuscate the code but I know its still not enough. Then I was thinking to convert to blazor server but dont want to waste time with migrating whole app to server. I dont know what I want I was just wondering if anyone would have idea how to handle this. Is there any way that that WASM would be just embedded to server? Or should I ship it as .exe? Btw even with server its problem how to ship it as I dont have access to any internal server so I would be just running the server app on my PC for time being and then maybe request for access to some VM where only I have access. Dont know. Sorry I know It doesnt make sense at some point what I am asking here but maybe someone will comp up with an idea. Thanks.
4
u/botterway Apr 05 '23
If you're shipping the code to somebody else, it doesn't matter if it's WASM or Server - the code will still be vulnerable. Can you elaborate on how/where you're deploying the code?
1
u/Personal_Peak9589 Apr 05 '23
Sure, sorry. So thats a thing I dont know. Firstly I wanted to deploy to static pages. Thats actually separate issue I still didnt resolve. Company firewall or settings are blocking .dlls for WASM. After some time trying I found bypass by using prerendering nuget package and deploying to github pages (again problem with code exposure that github pages can be deployed only with public repo if I am not paying for github). I tried to do the same with netlify but even with “bypass” its still blocking dlls. Next would be azure web app but I stopped trying.
Next option would be host it on server but it cannot be any server outside organization because app is using uploading documents as I mentioned earlier. I would have to get som VM from company in this case.
Next option would be to ship it as .exe or .msix but I am not sure if the security would even allow it to install.
So thats why I am searching for doable option.
4
u/VirtualPAH Apr 05 '23
For the dll blocking issue, they've started looking into using .webcil files instead of dlls, available as an experimental status with .Net 8 Preview 1:
https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-8-preview-1/
In some environments, firewalls and anti-virus tools block the download or use of .dll files, which prevents the use of web apps based on .NET assemblies, like Blazor WebAssembly apps. To address this issue, the wasm-experimental workload now supports a new .webcil
file format that can be used to package .NET assemblies for
browser-based web apps. Currently the Webcil format is only available
for the experimental WebAssembly Browser Apps, but we plan to enable it
for Blazor WebAssembly apps in a future update.As for code privacy, only put code on the client that you don't care about being scrutinised and assume if it's important enough someone will bother to take the steps to access it.
If it's business or IP sensitive code, keep it on a secure server accessed via an API so you can control who can access it and what they can retrieve as output from it, then it's more like a black box with the inner workings kept private.
3
u/Personal_Peak9589 Apr 05 '23
Thats good to know! I was feeling like its happening to me only (blocking dlls).
6
u/-Defkon1- Apr 05 '23
Any software installed/shipped to the customers can be decompiled, deal with it.
If you want, you can download a .NET free decompiler (like Telerik JustDecompile) and try it by yourself.
You can use some kind of obfuscator (I like Babel Obfuscator, but I don't know if it works fine with Blazor WASM), but it is a palliative.
The only way to secure your software is to separate business logic (that should remains on your server, behind strong APIs) and UI (that can be shipped to the customers)
3
u/botterway Apr 05 '23
Sounds to me like you need to convert it to Blazor Server (pretty easy, if you already have Blazor WASM) and then host it on an internal server to the company.
If it's a sensitive/secure site that allows people to upload documents into your company's network, the only answer is to use Blazor Server.
1
u/Personal_Peak9589 Apr 05 '23
Thanks everyone for contribution! From what I read and learned I dont have much of an option if I want to secure my code without relying on obfuscation, just to try get some VM and deploy Blazor server app.
2
u/crandeezy13 Apr 05 '23
I have no experience with this, but I would wager it would translate over pretty smoothly. All markup code should transfer immediately and the code behind is really more of a refactoring job to create injected services as a layer between your front end and the database/logic
I built an internal tools website at my company using blazor server and I am running a local vm on the on-premise server with IIS and then pointing a public company subdomain to my internal server. I don't have direct admin access to the VM but I do have a remote desktop login so I can manage my deployment myself. maybe you could ask your IT department to do something like that. give you user access without being an admin.
2
u/elyl Apr 05 '23
Any code in the client can be decompiled, even if obfuscated. If you have critical code that's doing something really important, it needs to run on the server. If you just don't want people stealing your super cool code, then don't worry about it, it's not that cool.
1
1
u/FluxyDude Apr 05 '23
You can for sure do that all of the above. Disclaimer this code is some of the oldest code I wrote so it's not amazing (other reddtors be kind).
I had a similar scenario were I had UI and I wanted to share the UI with an Android Tablet, Windows Desktop app (exe), A Blazor WASM Website and a Blazor Server website. I achieved this by creating an interface that I put all my DB calls into. I moved all my Razor files into an RCL.
in the razor file
@inject ICustomerInfoDBService CustomerInfoDBServicevar RESP = await CustomerInfoDBService.LocationSMSLog(PhoneNumber);
then simply match up the HTTP request names with the Method names, so it stays all easy to manage
public async Task<List<SMSModel>> LocationSMSLog(string locphone)
{
HttpClient Http = new();
var GetThoesDeets = await Http.GetFromJsonAsync<List<SMSModel>>($"{nameof(LocationSMSLog)}?locphone={locphone}");
return GetThoesDeets;
}and then on the API side (using azure functions isolated)
[Function(nameof(LocationSMSLog))]
public async Task<HttpResponseData> LocationSMSLog(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestData req)
{
NameValueCollection query = HttpUtility.ParseQueryString(req.Url.Query);
string LocPhone = query["locphone"];
var responseMessage = await CustomerInfoDBService.LocationSMSLog(LocPhone);
HttpResponseData responce3 = req.CreateResponse(HttpStatusCode.OK);
await responce3.WriteAsJsonAsync(responseMessage);
return responce3;
}has the same name and calls the same interface with the same name and that the round trip. All you gotta do is write the 2 different implementations for the Interface and i should line up. Doing this will allow you to place the razor UI in either a Server app or a WASM app or even a MAUI app to create a windows desktop or android app using the same UI.
1
u/hevilhuy Apr 05 '23
Don't focus on the wrong problem. You certainly don't need to protect the code.
1
u/tidus4400_ Apr 05 '23
Make a blazor hybrid app (like wpf + blazor wasm via BlazorWebView) and compile it as single exe. I can assure you that it works like a charm and you have the best of both worlds (native + web)
0
u/kantank-r-us Apr 05 '23
I believe you can use Electron to convert it to a desktop app. Never did it myself but I know it’s possible.

17
u/Quango2009 Apr 05 '23
Bit puzzled, going from WASM to Server should be fairly easy: it’s the other way that’s harder.
Blazor Server does not send any code to the client, it just sends HTML. Hence the name.
Sounds like you don’t understand the two modes?