-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support SafeJoinPath and SafeJoinFilepath #23441
Conversation
modules/util/path.go
Outdated
if len(elem) > 0 && !strings.HasPrefix(elem[0], separator) { | ||
return filepath.Join(elems...)[1:] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For windows: C:\foo
=> :\foo
?
I do not think Gitea has Windows servers to run tests .... so the test code for Windows never runs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I thought the CI would run tests on Windows ...
I will fix it and run the tests on Windows to ensure it works.
I don't think this is as helpful as you think it will be or as safe as you think it will be. a) Do we really have that many places where we join multiple user provided paths? Given that #23371 is IMO unsafe I think this needs more thought. |
Although #23371 doesn't look good, I think we need some util functions for paths.
So, IMO:
|
Relaced by #23495 |
Follow #23371.
Introduce
SafeJoinPath
to replaceCleanPath
.CleanPath
could be misused asCleanPath(path.Join("/tmp", "../etc/passwd"))
, and the result will be "/etc/passwd", when the right way ispath.Join("/tmp", CleanPath("../etc/passwd"))
.However, it will be annoying if there are many paths like
path.Join("/tmp", CleanPath(input1), CleanPath(input2), CleanPath(input3))
. SoSafeJoinPath
could do it more simply:SafeJoinPath("/tmp", input1, input2, input3)
.If we really want something like
CleanPath
, we can just useSafeJoinPath
:CleanPath(p) == SafeJoinPath(p)
.Also introduce
SafeJoinFilepath
forfilepath.Join