Hi!
I want to check if a file is inside a directory (or a subdirectory).
Can I just check if the file's path begins with the directory's path?
Shoud I use filepath.Abs() or filepath.Clean()?
My use case is:
I have a variable named "root" which is a directory path.
I also have a file path, relative to "root".
I generate the "real" file path with filepath.Join(root, myfile).
The file path is given by the user, and I want to prevent the user to go "outside the root".
As far as I tested, using filepath.Join() and checking that the "real" file path begins with my "root" variable is OK.
Is there a security issue? (symlink...)
Thanks!