diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2026-06-08 23:50:14 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2026-07-02 19:42:48 +0200 |
| commit | 5e0b68f3737ec29595bf92c8ce209702f5bd80be (patch) | |
| tree | 426050e74fe0635ebc6364c8dd09fe4b876287c5 /tests/substitute.scm | |
| parent | 26fe5af3e39405b19b8b52f6e3263cd9d1cb8653 (diff) | |
narinfo: Reject narinfos where store file names are invalid.
This change safeguards against narinfos that would advertise
“StorePath: /gnu/store/…-foo/../../../etc/passwd” or similar, which could
otherwise propagate down the line and lead to attempts to overwrite said file,
should ‘guix-daemon’ be running as root.
* guix/narinfo.scm (narinfo-maker): Validate ‘path’, ‘references’, and
‘deriver’ and return #f upon failure.
(read-narinfo, string->narinfo): Adjust docstring accordingly.
* guix/substitutes.scm (fetch-narinfos): Remove check for ‘narinfo-path’
prefix; instead check whether ‘read-narinfo’ returned true.
(cached-narinfo): Check whether ‘string->narinfo’ returned true.
* tests/substitute.scm ("query narinfo that contains invalid store path"): New
test.
Change-Id: I0be2ea88b7f762144fca35373363364df3264b5a
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests/substitute.scm')
| -rw-r--r-- | tests/substitute.scm | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/substitute.scm b/tests/substitute.scm index 6837e7e868e..8f32bfa7281 100644 --- a/tests/substitute.scm +++ b/tests/substitute.scm | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2014 Nikita Karetnikov <nikita@karetnikov.org> | 2 | ;;; Copyright © 2014 Nikita Karetnikov <nikita@karetnikov.org> |
| 3 | ;;; Copyright © 2014-2015, 2017-2019, 2021-2023 Ludovic Courtès <ludo@gnu.org> | 3 | ;;; Copyright © 2014-2015, 2017-2019, 2021-2023, 2026 Ludovic Courtès <ludo@gnu.org> |
| 4 | ;;; | 4 | ;;; |
| 5 | ;;; This file is part of GNU Guix. | 5 | ;;; This file is part of GNU Guix. |
| 6 | ;;; | 6 | ;;; |
| @@ -333,6 +333,30 @@ Deriver: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo.drv") | |||
| 333 | (lambda () | 333 | (lambda () |
| 334 | (guix-substitute "--query"))))))))) | 334 | (guix-substitute "--query"))))))))) |
| 335 | 335 | ||
| 336 | (test-equal "query narinfo that contains invalid store path" | ||
| 337 | ;; The signature covers the StorePath/NarHash/References tuple, so it is | ||
| 338 | ;; valid, but the 'StorePath' field is invalid (contains forbidden | ||
| 339 | ;; characters). | ||
| 340 | "" | ||
| 341 | |||
| 342 | (let ((prefix (string-append "StorePath: " (%store-prefix) | ||
| 343 | "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo/../../../etc/passwd | ||
| 344 | NarHash: sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | ||
| 345 | References: bar baz\n"))) | ||
| 346 | (with-narinfo (string-append prefix | ||
| 347 | "Signature: " (signature-field prefix) " | ||
| 348 | URL: example.nar | ||
| 349 | Compression: none | ||
| 350 | NarSize: 42 | ||
| 351 | Deriver: foo.drv") | ||
| 352 | (string-trim-both | ||
| 353 | (with-output-to-string | ||
| 354 | (lambda () | ||
| 355 | (with-input-from-string (string-append "have " (%store-prefix) | ||
| 356 | "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo") | ||
| 357 | (lambda () | ||
| 358 | (guix-substitute "--query"))))))))) | ||
| 359 | |||
| 336 | (test-equal "query narinfo signed with authorized key" | 360 | (test-equal "query narinfo signed with authorized key" |
| 337 | (string-append (%store-prefix) "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo") | 361 | (string-append (%store-prefix) "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo") |
| 338 | 362 | ||
