Basically I’m trying to open a URL in my .NET application. This can be achieved easily by doing :
Process.Start('http://www.google.com')
However in my case the URL can be controlled by external users, therefore I don’t want them to execute commands in the system by injecting meta characters etc.
So safe way would be :
- Read registry and see what’s the default browser
- Creating
New Process()with the default browser’s executable - Supply the URL as argument
- Start the process
Before implementing this, I just want to be sure I’m not making this overcomplicated. What do you think?
I’m not keen on implementing filtering on the input, it’s just a dirty solution
Why not instead make sure it’s a valid HTTP url by parsing it?
Note that this example does not use the userSupplied string to create the process. It lets the Uri class format the string passed to the Start call.
You can extend the Scheme check to include all schemes that you feel are valid (FTP for instance).