Skip to content

fix tarfs absolute symlink test for Windows - #830

Closed
aliculPix4D wants to merge 1 commit into
masterfrom
pci-4898-tarfs-test-fix-absolute-path-symlink-test
Closed

aliculPix4D wants to merge 1 commit into
masterfrom
pci-4898-tarfs-test-fix-absolute-path-symlink-test

Conversation

@aliculPix4D

@aliculPix4D aliculPix4D commented Jul 22, 2026 •

Copy link
Copy Markdown

pci-4898 tarfs test fix absolute path symlink test

Why is concourse@146ab33 wrong fix?

Code path for absolute path /absolute/path/file on Linux:

linux

Code path for path /absolute/path/file on Windows:

623207706-326c2525-12c6-4b7b-8ddc-f7272118954a

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:

err = root.Symlink(filepath.FromSlash(header.Linkname), filePath)

@aliculPix4D
aliculPix4D requested a review from a team as a code owner July 22, 2026 11:59
Comment thread go-archive/tarfs/extract_test.go Outdated
It("does not modify absolute paths", func() {
linkname := "/absolute/path/file"
if runtime.GOOS == "windows" {
linkname = `C:\foo`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@aliculPix4D aliculPix4D Jul 22, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think that we can all agree that what this PR proposes is more correct than: concourse@146ab33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I would still use:

Suggested change
linkname = `C:\foo`
linkname = `C:\absolute\path\file`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.
@aliculPix4D
aliculPix4D force-pushed the pci-4898-tarfs-test-fix-absolute-path-symlink-test branch from 3f4272a to 9b3ccdf Compare July 23, 2026 07:03
@aliculPix4D

Copy link
Copy Markdown
Author

Closing this one as the same PR was merged upstream.

@aliculPix4D
aliculPix4D deleted the pci-4898-tarfs-test-fix-absolute-path-symlink-test branch July 28, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants