From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id C19F8B978; Wed, 26 Nov 2025 19:42:22 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 054EBB8D1; Wed, 26 Nov 2025 19:42:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DMARC_PASS,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=4.0.1 Received: from mail-yx1-xb130.google.com (mail-yx1-xb130.google.com [IPv6:2607:f8b0:4864:20::b130]) by atuin.qyliss.net (Postfix) with ESMTPS id C878AB7DE for ; Wed, 26 Nov 2025 19:41:57 +0000 (UTC) Received: by mail-yx1-xb130.google.com with SMTP id 956f58d0204a3-640d0895d7cso225204d50.1 for ; Wed, 26 Nov 2025 11:41:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764186115; x=1764790915; darn=spectrum-os.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2TOBE4ZPTHK3B9LZd1pCRhAdx8FqzzUqlcoLcRtpCu8=; b=TAeB3BY1AphwYSaV6HH5ByV1/K0v8fgthVzXI3r5CR3Q0SYlVUW7n73vnEXeYVzxAu 9U3hhlfw224il+8hhX3uU+BjqBb3odeJyxULFyAvaSnTCSMtL75a5z0Xo2uiFJG8oo4t D1ymM+6InWVjQ9gaeoKnrKJ6yeve3fPSWmvB9jFDAQOU0HzCmk4+ivRP/MYIcpj7iaGK gHMvw4ARKE2nXqhitPesOR0GODoaowOZ8Cv3Lbmfb3juH9kjsLH91mqIMoHsFMQAxQMc xei43jE+RF8SvvLnTenAQ0t+SAnvlkIwjQ7ZspoeHQyqKn9TUWHRd+wUS9s+Wk8Z9wDZ 4vkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764186115; x=1764790915; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=2TOBE4ZPTHK3B9LZd1pCRhAdx8FqzzUqlcoLcRtpCu8=; b=OVnuxz0xaa67ZUxMEmeZWtNooW+WOf0WHYUBDHOIMYtYpi9GeDIhZDtcvQSB+gRdvq SapYtJqV1DBUJpNOCsqF7X8awVQYTD7XEchchsGlj9CYpiadstqtgdOBpHg6X9HyvGFG kQae/kGO10n4DuFlqr1nGF3zPA3Kcw0/BSy5Z6k8MgOFGYD6swubFGV+heLzU9ONLh38 j+eVMbAGZ52dF2jvB2npCngVDXp9uZ7EvOIup1MUkXbaMq+7fNcfwH7WbI76Ag8ucSmD P0aM9QWhUgSXAR2MKsWAteXg/vtYGr3CRTJHHw4Aa2uABb3LWgDfTocHn/kZTKRly9lN BANw== X-Gm-Message-State: AOJu0Yzx6vE1oXkc4t1sN/jrAjFnmYO+xlf39BXy5Pm0dIYVhIU4/emz YjSXYRTNpTY0vvuNJSnmGEnc2W9o04P+DD83hNFDhuksKodUCfhL6zfUr1Vahw== X-Gm-Gg: ASbGncvg1CZWaRGPCdACWCgl3JPNx54oqgo8aW3YT9fQit1sfLjRiOpIroCpEUCV2zD HvjyhMqQyIxZCTSkKxN7hS5MPwWcPgHcdJpbb0A9dfTqGABP78wM53/p57pzDCDcLRJnOLRK4wV qgqaKe8d1AyUhKjxlp1AuCe+MfjvST+ZWsG3yIhr/5IziLHqHYgH+eiNg3CdiEWgu+jTZzwaE3Q dpY3pgiL77qph3u7XDPMjiXG/u8o3Nony+xJsJXZlxp2jhKzAo8ycWLWWINzv0W80f4GuAE/NHP scljHV7dvDD5NsCioiAeZy9bEQ+v5tp29TAkwe12WYuWORTppJfMkT+msLPlWa7SX2KzjWfrQQ7 ab4RmqZ3yhE8cffVmivL4m+3aQ8JB19pGkKFhWfOSqJI6e4l5S9jpqmOZE2GrPw8XE0w0yOy++2 YcMiMpoFdYWZxnBv8YgB6H2Rpzi1RCqTo+WoK5tC5fcMAD+Lbcyw9r1nGGa57KZM5vz1F6V1dDt ZI+sOzUyElXxTri4jV6g1UF7D4CauS56FY= X-Google-Smtp-Source: AGHT+IEMbKiigKYDzbCpEwjaXG2zsvGeHr5ycyQT5yYwjzLWRAEFcHS44wEDl8RozjgIvjdlfk18dQ== X-Received: by 2002:a05:690e:1443:b0:63f:a4ca:dc21 with SMTP id 956f58d0204a3-642f8e2e343mr16176039d50.19.1764186115442; Wed, 26 Nov 2025 11:41:55 -0800 (PST) Received: from localhost.localdomain (h96-60-249-169.cncrtn.broadband.dynamic.tds.net. [96.60.249.169]) by smtp.gmail.com with UTF8SMTPSA id 956f58d0204a3-642f70a6aa3sm7654618d50.8.2025.11.26.11.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 11:41:54 -0800 (PST) From: Demi Marie Obenour Date: Wed, 26 Nov 2025 14:40:53 -0500 Subject: [PATCH v5 13/13] Validate configuration parameters MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251126-updates-v5-13-fd746748febd@gmail.com> References: <20251126-updates-v5-0-fd746748febd@gmail.com> In-Reply-To: <20251126-updates-v5-0-fd746748febd@gmail.com> To: Spectrum OS Development X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1764186041; l=3051; i=demiobenour@gmail.com; s=20250729; h=from:subject:message-id; bh=4qeSZCGVEMcE58WwVm7qv3LgKOyHUrvnZXT3Z92ZtzA=; b=iViBdrR18q4p3w9SyJb7EBLZByQ9mRXm/ueCrYByECFrQsTlHPtNWHwtbNs6GWJ+zaiX8ibst U75/H4O0+fUCINtEyR/Sxzy0WJB65ev+/5S0oeogkzfIyjZ9lg5hKor X-Developer-Key: i=demiobenour@gmail.com; a=ed25519; pk=X57Q4/YQDj9t4SBeKaDwvXYKB6quZJVx/DE2Ly2out0= Message-ID-Hash: AB234V5NWCG5VXK72U4MM5KHZ5B5YKSV X-Message-ID-Hash: AB234V5NWCG5VXK72U4MM5KHZ5B5YKSV X-MailFrom: demiobenour@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-devel.spectrum-os.org-0; header-match-devel.spectrum-os.org-1; header-match-devel.spectrum-os.org-2; header-match-devel.spectrum-os.org-3; header-match-devel.spectrum-os.org-4; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Demi Marie Obenour , Alyssa Ross X-Mailman-Version: 3.3.9 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Wrong values for the version or update URL will cause very confusing build-time or runtime errors. Provide a better user experience by validating them up-front. The update URL validator is loose. It rejects only URLs that cannot possibly work: either appending /SHA256SUMS to them doesn't append to the path, or they will definitely be rejected by curl due to being malformed. The version validator is in lib/config.nix, as the version number is used in many places. It checks that the version only uses characters that are permitted by systemd's version number specification [1] and that will not break code that uses them in shell or sed commands. [1]: https://uapi-group.org/specifications/specs/version_format_specification Signed-off-by: Demi Marie Obenour --- Changes since v4: - Drop compression level. - Centralize validation. - Use camelCase for Nix identifiers. - Clean up formatting. Changes since v3: - Validate compression level. Changes since v2: - Use loose URL validation: allow anything that might work. - Only reject versions that violate the specification. Signed-off-by: Demi Marie Obenour --- lib/config.nix | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/config.nix b/lib/config.nix index e437cdbe9aa22dd0f9c8d7052ac331c8fccf6ce6..e641642de07c1549e69fc12e91c4e80e2f82d035 100644 --- a/lib/config.nix +++ b/lib/config.nix @@ -17,6 +17,31 @@ let callConfig = config: if builtins.typeOf config == "lambda" then config { inherit default; } else config; + finalConfig = default // callConfig config; + # Use builtins.fromJSON because it supports \uXXXX escapes. + # This is the same regex used by check-url.awk in the update VM. + # The update code is careful to escape any metacharacters, but some + # simply cannot be made to work. Concatenating the URL with /SHA256SUMS + # must append to the path portion of the URL, and the URL must be one + # that libcurl will accept. + urlRegex = builtins.fromJSON "\"^[^\\u0001- #?\\u007F]+$\""; in -default // callConfig config +# Version is used in many files, so validate it here. +# See https://uapi-group.org/specifications/specs/version_format_specification +# for allowed version strings. +if builtins.match "[[:alnum:]_.~^-]+" finalConfig.version == null then + builtins.abort '' + Version ${builtins.toJSON finalConfig.version} has forbidden characters. + Only ASCII alphanumerics, ".", "_", "~", "^", "+", and "-" are allowed. + See . + '' +else +if builtins.match urlRegex finalConfig.updateUrl == null then + builtins.abort '' + Update URL ${builtins.toJSON finalConfig.updateUrl} has forbidden characters. + Query strings, and fragment specifiers are not supported. + ASCII control characters and whitespace must be %-encoded. + '' +else +finalConfig -- 2.52.0