From 0e7dcecf403d784f0b50e56a8acd64806ea213d9 Mon Sep 17 00:00:00 2001 From: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:30:19 +0800 Subject: [PATCH] fix(deploy): align device URI preflight validation Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com> --- scripts/tests/validate-release-config-test.sh | 15 ++++++++ scripts/validate-release-config.sh | 36 +++++++++++++++++-- .../config/DeviceAuthConfigurationTest.java | 3 +- .../auth/device/DeviceAuthService.java | 2 +- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/scripts/tests/validate-release-config-test.sh b/scripts/tests/validate-release-config-test.sh index 6bf95d134..062f74995 100755 --- a/scripts/tests/validate-release-config-test.sh +++ b/scripts/tests/validate-release-config-test.sh @@ -113,6 +113,21 @@ assert environment["SKILLHUB_PUBLIC_BASE_URL"] == "https://skillhub.example.com/ PY done +for device_override in '' ' ' '/portal/device' 'https://login.example.com/custom/device?source=cli#confirm'; do + device_env="$tmp/device-valid.env" + write_env "$device_env" "release-download-secret-32-bytes-minimum" + printf 'DEVICE_AUTH_VERIFICATION_URI=%s\n' "$device_override" >>"$device_env" + "$SCRIPT" "$device_env" >/dev/null +done + +for device_override in 'javascript:alert(1)' '//login.example.com/device' 'https:///device' \ + 'https://user:secret@example.com/device' 'https://skills.example.com/invalid path'; do + device_env="$tmp/device-invalid.env" + write_env "$device_env" "release-download-secret-32-bytes-minimum" + printf 'DEVICE_AUTH_VERIFICATION_URI=%s\n' "$device_override" >>"$device_env" + expect_fail "$device_env" "DEVICE_AUTH_VERIFICATION_URI" +done + valid_feishu_env="$tmp/valid-feishu.env" write_env "$valid_feishu_env" "release-download-secret-32-bytes-minimum" cat >>"$valid_feishu_env" <<'EOF' diff --git a/scripts/validate-release-config.sh b/scripts/validate-release-config.sh index f84cbb4e1..71d3f7b76 100755 --- a/scripts/validate-release-config.sh +++ b/scripts/validate-release-config.sh @@ -98,6 +98,38 @@ validate_url() { esac } +validate_device_auth_verification_uri() { + device_uri=${DEVICE_AUTH_VERIFICATION_URI:-} + # Unlike a base URL, this is a complete destination. Blank means derive it + # in the backend; custom destinations may include query/fragment components. + if [ -z "$(printf '%s' "$device_uri" | tr -d '[:space:]')" ]; then + return 0 + fi + case "$device_uri" in + *[[:space:]]*|*'\'*) + error "DEVICE_AUTH_VERIFICATION_URI must be a valid HTTP(S) URL or root-relative path" + return 0 + ;; + //*) + error "DEVICE_AUTH_VERIFICATION_URI must not be a scheme-relative URL" + return 0 + ;; + /*) return 0 ;; + esac + case "$device_uri" in + [hH][tT][tT][pP]://*|[hH][tT][tT][pP][sS]://*) + device_authority=${device_uri#*://} + device_authority=${device_authority%%[/?#]*} + case "$device_authority" in + ""|:*|*@*) + error "DEVICE_AUTH_VERIFICATION_URI must include a host without credentials" + ;; + esac + ;; + *) error "DEVICE_AUTH_VERIFICATION_URI must be an HTTP(S) URL or root-relative path" ;; + esac +} + validate_web_api_base_url() { var_name="$1" eval "var_value=\${$var_name:-}" @@ -369,9 +401,7 @@ validate_web_base_path_format validate_public_base_path_alignment validate_api_base_path_alignment -if [ -n "${DEVICE_AUTH_VERIFICATION_URI:-}" ]; then - validate_url DEVICE_AUTH_VERIFICATION_URI -fi +validate_device_auth_verification_uri if [ "${SESSION_COOKIE_SECURE:-true}" != "true" ]; then warn "SESSION_COOKIE_SECURE is not true; only acceptable behind plain HTTP during temporary local verification" diff --git a/server/skillhub-app/src/test/java/com/iflytek/skillhub/config/DeviceAuthConfigurationTest.java b/server/skillhub-app/src/test/java/com/iflytek/skillhub/config/DeviceAuthConfigurationTest.java index 68bd5dd7b..a70cc51ea 100644 --- a/server/skillhub-app/src/test/java/com/iflytek/skillhub/config/DeviceAuthConfigurationTest.java +++ b/server/skillhub-app/src/test/java/com/iflytek/skillhub/config/DeviceAuthConfigurationTest.java @@ -54,7 +54,8 @@ class DeviceAuthConfigurationTest { @ParameterizedTest @ValueSource(strings = {"javascript:alert(1)", "//other.example.com/device", "https:///device", - "https://user:secret@example.com/device", "https://skills.example.com/invalid path"}) + "https://user:secret@example.com/device", "https://skills.example.com/invalid path", + "https://skills.example.com:65536/device"}) void invalidOverrideFailsContextWithoutEchoingItsValue(String override) throws IOException { run(Map.of("DEVICE_AUTH_VERIFICATION_URI", override), context -> { assertThat(context).hasFailed(); diff --git a/server/skillhub-auth/src/main/java/com/iflytek/skillhub/auth/device/DeviceAuthService.java b/server/skillhub-auth/src/main/java/com/iflytek/skillhub/auth/device/DeviceAuthService.java index 397ba595f..ed05be880 100644 --- a/server/skillhub-auth/src/main/java/com/iflytek/skillhub/auth/device/DeviceAuthService.java +++ b/server/skillhub-auth/src/main/java/com/iflytek/skillhub/auth/device/DeviceAuthService.java @@ -76,7 +76,7 @@ public class DeviceAuthService { throw new IllegalArgumentException(error); } boolean absolute = ("http".equalsIgnoreCase(uri.getScheme()) || "https".equalsIgnoreCase(uri.getScheme())) - && StringUtils.hasText(uri.getHost()) && uri.getRawUserInfo() == null; + && StringUtils.hasText(uri.getHost()) && uri.getRawUserInfo() == null && uri.getPort() <= 65535; boolean relative = allowRelative && !uri.isAbsolute() && uri.getRawAuthority() == null && value.startsWith("/") && !value.startsWith("//"); if (!absolute && !relative) {