Repository navigation
fix tarfs absolute symlink test for Windows - #830
aliculPix4D wants to merge 1 commit into
Conversation
| It("does not modify absolute paths", func() { | ||
| linkname := "/absolute/path/file" | ||
| if runtime.GOOS == "windows" { | ||
| linkname = `C:\foo` |
There was a problem hiding this comment.
I'm not convinced this is enough / correct. The thing is that a path starting with a \ is somewhat absolute. It is rooted at the active drive, you just don't know which drive it is. So this could still be used to escape.
In python:
>>> pathlib.PureWindowsPath(r'\foo\bar').is_absolute()
False
>>> pathlib.PureWindowsPath(r'c:\foo\bar').is_absolute()
True
>>> pathlib.PureWindowsPath(r'C:\foo\bar', r'\escape\path')
PureWindowsPath('C:/escape/path')Unfortunately it's not clear to me if this is a Python specific behaviour or not.
There was a problem hiding this comment.
I'm not convinced this is enough / correct.
And now you understand where I lost all this time in my life :)
I very well understand all Windows path possibilities :) After all discussion that I had with @marco-m-pix4d conclusion was that we will not propose any changes to production code, only tests.
So we must fix this test, and this is a fix. We just test on 1 example on Windows (C:\foo) and 1 example on Linux (/absolute/path/file). And we can all agree (even filepath.IsAbs() will agree with us on this one), that C:\foo is an absolute path. So the test is correct now :) Goal achieved.
Note that I went and tried to introduce a new function (instead of filepath.IsAbs()) that would handle all kinds of possibilities on Windows, but my conclusion was: it's not our job to determine what is considered an absolute path on Windows. Rooted path is not considered an absolute path by any definition; who are we to try to change the definition?
And as a final conclusion... rooted or not... you end up in the same code path L134 creating the symlink :)
There was a problem hiding this comment.
Also, I think that we can all agree that what this PR proposes is more correct than: concourse@146ab33
There was a problem hiding this comment.
OK. I would still use:
| linkname = `C:\foo` | |
| linkname = `C:\absolute\path\file` |
There was a problem hiding this comment.
@odormond to be clear: I agree that on Windows a "rooted path", although not considered an "absolute path" (Python and Go isAbsolute() both return false), still escapes exactly as an absolute path, since it always result in a prepended drive letter.
Said in another way, outside of Unix, reasoning with isAbsolute() is just wrong. One should reason with a custom pathEscapesDir(), that would return true if any of the following is true: path is absolute, path is rooted.
For some reason I think @aliculPix4D confused the idea: nobody wants to define what is an absolute path on Windows. We want to define what is a path that escapes a given directory.
I think for the moment we want to extend test coverage only. As we understand it, the prod code is not vulnerable any more because all the decisions are taken, below, by os.Root (which had a bug as we know, which has been fixed, and the Concourse prod code has a fix also).
- expand the absolute-path symlink ExtractEntry case into a platform-aware table so Unix paths are skipped on Windows and a Windows absolute link (`C:\foo`) is covered there.
3f4272a to
9b3ccdf
Compare
|
Closing this one as the same PR was merged upstream. |
pci-4898 tarfs test fix absolute path symlink test
Why is concourse@146ab33 wrong fix?
Code path for absolute path
/absolute/path/fileon Linux:Code path for path
/absolute/path/fileon Windows:We must ensure we are testing the same code path on each platform. Hence, we must test an absolute path (
/absolute/path/file) on Unix and an absolute path on Windows (C:\foo).The fact that the test was green at the end (after
filepath.FromSlash(header.Linkname)manipulation ) is just due to the fact that at the end, by chance, in both cases, we end up calling the same L134 in production code: