Using this code, any authenticated user who has the right to use this function can access the file system on the server. Access will be made using the credentials of the service account that runs the web application.
Depending on how the returned data is used, an attacker can obtain additional information or force the server to behave in a way that is not intended.
You must limit the set of valid paths to only the state of one or more carefully selected directories. Use the functions of the Path
class to concatenate strings in a path - they take care of things like the user c:\allowedpath\..\windows\system32
for you.
source share