Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string Resolve(string fileName)
- {
- string root = FileRoot();
- string ret = Path.GetFullPath(Path.Combine(root, fileName));
- if (ret.StartsWith(root.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar)) return ret;
- throw new ArgumentException("path resolved to out of accesable directroy");
- }
- public Boolean IsPathSafe(String rootPath, String relativePath)
- {
- return rootPath.EndsWith(Path.DirectorySeparatorChar.ToString()) &&
- Path.IsPathRooted(rootPath) &&
- Patch.Combine(rootPath, relativePath).GetFullPath().StartsWith(rootPath);
- }
Add Comment
Please, Sign In to add comment