Commit c463c65
authored
fix: prevent hardlink path traversal via process CWD (GHSA-fxhp-mv3v-67qp) (#1232)
## Summary
Backport of the `main`-branch fix (b11f777) to the **v2** release line
for **GHSA-fxhp-mv3v-67qp / CVE-2026-50163**.
`ensureLinkPath` validated `TypeLink` (hardlink) targets by resolving
relative paths against the link file's directory, but returned the
*original, unresolved* target string. The caller passed this to
`os.Link`, which resolves relative paths against the process **CWD** via
`link(2)` — not the link file's directory. A crafted OCI artifact could
exploit this to hardlink a CWD file into the extract tree, creating a
shared inode with an arbitrary file outside the extraction directory.
The fix landed on `main` (now the v3 module) but was never carried to
the v2 line, so v2.6.1 and earlier remain vulnerable. This PR closes
that gap.
## Fix
Explicitly resolve relative hardlink targets against `filepath.Dir` of
the link file before calling `os.Link`. Symlink handling is unaffected
since `os.Symlink` stores the path verbatim and resolves at access time.
## Test
Adds a regression test that sets the process CWD to a directory
containing a sentinel file and verifies that a tar `TypeLink` entry with
a relative `Linkname` cannot hardlink that file into the extract tree.
The test fails without the fix ("hardlink escaped extract dir") and
passes with it.
Suggested release: **v2.6.2**.
Signed-off-by: Terry Howe <terrylhowe@gmail.com>1 parent 91c04ab commit c463c65
2 files changed
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
191 | 196 | | |
192 | 197 | | |
193 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
379 | 434 | | |
380 | 435 | | |
381 | 436 | | |
| |||
0 commit comments