How can I prevent paths built with Path.Combine
to end up being outside of a given root directory?
E.g.
string root = Path.Combine("/some", "dir");
string okay = Path.Combine(root, "sub"); // /some/dir/sub
string bad = Path.Combine(root, "sub/../../evil.exe"); // /evil.exe
Is there any functionality to easily ensure this while building paths? Or a built-in way to at least test it?
(I wouldn't be suprised if there is a duplicate question, but obviously I was unable to find the proper search terms. I would appreciate both answers and links to similar questions, thank you