mirror of
https://github.com/iflytek/skillhub.git
synced 2026-11-16 09:21:18 +00:00
fix(deploy): align device URI preflight validation
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
This commit is contained in:
parent
bec838b618
commit
0e7dcecf40
4 changed files with 51 additions and 5 deletions
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue