How to avoid code injection security problem blazor?

Viewed 25

I have Blazor WebAssembly project and security team told me there is a problem with code injection

The application's Main method receives and dynamically executes user-controlled code using RunAsync The attacker can inject the executed code via user input, args, which is retrieved by the application in the Main method

public static async Task Main(string[] args) { .... await builder.Build().RunAsync(); }

what can I do to avoid such problem? All examples I saw is written in this way

1 Answers

The string[] args parameter is not mandatory, you can remove it:

public static async Task Main()
{
    var builder = WebAssemblyHostBuilder.CreateDefault(Array.Empty<string>());
    ...
    await builder.Build().RunAsync(); 
}
Related