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 676B8B5D0; Wed, 26 Nov 2025 19:37:30 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 4C7DBB52B; Wed, 26 Nov 2025 19:37:19 +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-xb12b.google.com (mail-yx1-xb12b.google.com [IPv6:2607:f8b0:4864:20::b12b]) by atuin.qyliss.net (Postfix) with ESMTPS id 1891EB434 for ; Wed, 26 Nov 2025 19:37:08 +0000 (UTC) Received: by mail-yx1-xb12b.google.com with SMTP id 956f58d0204a3-640d8b78608so110919d50.1 for ; Wed, 26 Nov 2025 11:37:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764185826; x=1764790626; 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=k60gjMdzgWwo+mkyap4+nbyMgbx6pGGaAFOeR9d3nD8RxMh2PV9YnxAQ/jZuG0Taem 74lx5V/PHYWSA0KYD03SbXY1Nv4e70CDt9mt2ff2CaLcnRpmWuUjDRJEnQ+N6diZ6VaU gdwKI5WoDEppEllnsmxOUgJsGyXz6+GBam/DpvXEqW2WVuCJ2J6770xBN3f5DYequDfd X8H5tc4x0SUuPg+fZFFOIypzk5I2Zv5ckFdpjIzAQSru3adOY4naZZkrndXY4cyvYjD2 Vz9UzbQDB8qOE5mXjqnM9y/BBFPLuIGfbju+bzlaEmdgL/+49p8TrTd4WmmbfbJn2Y7f 57fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764185826; x=1764790626; 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=m6cl036RzwVobfay+5YHQSRPIoW3JY8KtEQ/rGrOP/7rgS5Cpx+seo6MGSya1VaVpx CWhW7ytjVOQ43mhMiTq8xuwYuVRaygGCFoYbuO0Gc0eX0XpysBBlkJCfP/sIiN8Ne+wS t/Fou/UIEQZM/zKHl3VAg14vGBVQjWzP4lnMgBsrTfE9Y3pcQUKKe5rZaQrYYtqJpcv4 WX6inFaAcOnVF2FaRA3RlJL1rmi/XrG1ctkM5ZjdUls04pJXDj84MMkYFtRDACtm/yjF 23moXHY2Yi88bF0spB/rrUh7cV4SY9FLeIpB5XM23SQTPf682vDhkpQIJxt1ONFH46xn LnVQ== X-Gm-Message-State: AOJu0Yy3vnYBqjWBU0cswzgnMNdaDIgoAr9ZdQ5AWrJMZFZdT6KeydOD Vj5IRVGsPQmwUhXAEKizWXOJ0JNdQxO4LrpdkaM/xS0tdPd4mkn4kvZT9rzf6w== X-Gm-Gg: ASbGncsZ67JwFOIF5OzHHC5bvaMwbaBUiqitjdvxSNK4fI/F5WHpinv9CQyM33+qwWy PxZ64ofSxCSA5Gjrj6MhzQe+tM3qTbf0PFg9KyEs5EDde26Xt80DBpuVFIAfklsjyYReKDyDZYE WPLgawuYkME5Ta2YPPjvhPhn2DJGzBPfcPB8J6dr+AQGt3uMeo1o1k+IQNr6cesXSzaJ38J4h81 v4RUR1Xqyt1Ffo6a+TvRwEHXgWAa3DGb5de2HNae+8fi/fywTjP91GHBBR/98viyNtzirXC3Hpe GjxJWFjQ5A60FxGVidR28bV0ZU0kBFcjsRg4bI8SK8iJnLN1SBy6QqwZOVd/FM19de8bf5ohrD1 dOnPt4pmLC8tw5HrDQ3sZuYXvOa7gAJGx7FKNnToVD+lNQpUfhmROs7gHs5Mo618i2Z96smxdFz CV/C5QyGWfCvjyHmmZFQ2eltCgSo0OyvTL6vCT1wVKj0ieRg682FGBf/dtOUFnkEVFJ9Budva4A vaGcECYE3lqIHqLrW28Gf/iub2MMey2UNU= X-Google-Smtp-Source: AGHT+IFhFkcGZc2jS02jr/Io38cpsmccBmuz4g0TyOG/LA1e/4Bw7vQ6oVr57VbpQk07czdMq9Zm7A== X-Received: by 2002:a05:690e:3ce:b0:641:718:8a17 with SMTP id 956f58d0204a3-64302ab27f4mr11334510d50.53.1764185825366; Wed, 26 Nov 2025 11:37:05 -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-642f718b57bsm7576040d50.17.2025.11.26.11.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 11:37:04 -0800 (PST) From: Demi Marie Obenour Date: Wed, 26 Nov 2025 14:34:11 -0500 Subject: [PATCH v4 13/13] Validate configuration parameters MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251126-updates-v4-13-40c438d2dcaf@gmail.com> References: <20251126-updates-v4-0-40c438d2dcaf@gmail.com> In-Reply-To: <20251126-updates-v4-0-40c438d2dcaf@gmail.com> To: Spectrum OS Development X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1764185638; l=3051; i=demiobenour@gmail.com; s=20250729; h=from:subject:message-id; bh=4qeSZCGVEMcE58WwVm7qv3LgKOyHUrvnZXT3Z92ZtzA=; b=x3QdEIyaMLSVrhksfNLZ/afd5hCazvvhkii3wNrAM+M55M/a5H7jiPbA/KX8MUHgYCQ9r3wF7 U5l7/EQ/edOBK63Eh5GpxLasHurrpGnEJVSzw/8ZFEaY/U0DL/+fmja X-Developer-Key: i=demiobenour@gmail.com; a=ed25519; pk=X57Q4/YQDj9t4SBeKaDwvXYKB6quZJVx/DE2Ly2out0= Message-ID-Hash: VGRRPHSWTCA4FEPZNBAVL5RVL6D2CATP X-Message-ID-Hash: VGRRPHSWTCA4FEPZNBAVL5RVL6D2CATP 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