diff --git a/Cargo.lock b/Cargo.lock index 15f41d6..cfc4033 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -214,7 +214,7 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "auth" -version = "2.6.3" +version = "2.6.4" dependencies = [ "anyhow", "block2", @@ -705,7 +705,7 @@ dependencies = [ [[package]] name = "common" -version = "2.6.3" +version = "2.6.4" [[package]] name = "compile-time" @@ -1732,7 +1732,7 @@ dependencies = [ [[package]] name = "gpapi" -version = "2.6.3" +version = "2.6.4" dependencies = [ "anyhow", "base64 0.22.1", @@ -1776,7 +1776,7 @@ dependencies = [ [[package]] name = "gpauth" -version = "2.6.3" +version = "2.6.4" dependencies = [ "anyhow", "auth", @@ -1796,7 +1796,7 @@ dependencies = [ [[package]] name = "gpclient" -version = "2.6.3" +version = "2.6.4" dependencies = [ "anyhow", "askama", @@ -1825,7 +1825,7 @@ dependencies = [ [[package]] name = "gpgui-helper" -version = "2.6.3" +version = "2.6.4" dependencies = [ "anyhow", "clap", @@ -1843,7 +1843,7 @@ dependencies = [ [[package]] name = "gpservice" -version = "2.6.3" +version = "2.6.4" dependencies = [ "anyhow", "axum", @@ -3191,7 +3191,7 @@ dependencies = [ [[package]] name = "openconnect" -version = "2.6.3" +version = "2.6.4" dependencies = [ "autotools", "cc", diff --git a/Cargo.toml b/Cargo.toml index 1682909..8d4a4c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ [workspace.package] rust-version = "1.89" -version = "2.6.3" +version = "2.6.4" authors = ["Kevin Yue "] homepage = "https://github.com/yuezk/GlobalProtect-openconnect" edition = "2024" diff --git a/changelog.md b/changelog.md index b77f1a5..807d0cc 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2.6.4 + +### Fixed + +- Fixed gateway login MFA OTP retries sending duplicate `passwd` form fields, which could cause authentication to fail with HTTP 512 after 2.6.0 (fix [#626](https://github.com/yuezk/GlobalProtect-openconnect/issues/626)). + ## 2.6.3 ### Fixed diff --git a/crates/gpapi/src/params/gateway_login.rs b/crates/gpapi/src/params/gateway_login.rs index 7f4a66b..303003b 100644 --- a/crates/gpapi/src/params/gateway_login.rs +++ b/crates/gpapi/src/params/gateway_login.rs @@ -39,7 +39,7 @@ pub(crate) fn build(input: &GatewayLoginInput) -> RequestParams { input.gp_params.input_str().unwrap_or_default().into(), )); if let Some(otp) = input.gp_params.otp() { - body.push(("passwd".into(), otp.into())); + set_body_param(&mut body, "passwd", otp); } if let Some(os_version) = input.gp_params.os_version() { body.push(("os-version".into(), os_version.into())); @@ -99,6 +99,15 @@ pub(crate) fn build(input: &GatewayLoginInput) -> RequestParams { RequestParams { body, query: vec![] } } +fn set_body_param(body: &mut Vec<(String, String)>, key: &str, value: impl Into) { + let value = value.into(); + if let Some(pos) = body.iter().position(|(k, _)| k == key) { + body[pos].1 = value; + } else { + body.push((key.to_string(), value)); + } +} + /// Resolve the gateway server to an IPv4 address if the profile requires it. /// /// Falls back to the original gateway host if resolution fails. @@ -153,6 +162,40 @@ mod tests { Credential::Password(PasswordCredential::new("alice", "secret")) } + fn passwd_values(body: &[(String, String)]) -> Vec<&str> { + body + .iter() + .filter(|(k, _)| k == "passwd") + .map(|(_, v)| v.as_str()) + .collect() + } + + #[test] + fn otp_retry_replaces_passwd_instead_of_appending_duplicate() { + let mut gp_params = make_gp_params(); + gp_params.set_input_str("challenge-token"); + gp_params.set_otp("123456"); + + let cred = make_credential(); + let input = GatewayLoginInput { + gp_params: &gp_params, + cred: &cred, + gateway_host: "vpn.example.com", + context: None, + client_ip: None, + extend_lifetime: false, + }; + + let result = build(&input); + + assert_eq!(passwd_values(&result.body), vec!["123456"]); + + let encoded = serde_urlencoded::to_string(&result.body).expect("form body should encode"); + assert_eq!(encoded.matches("passwd=").count(), 1); + assert!(encoded.contains("passwd=123456")); + assert!(!encoded.contains("passwd=secret")); + } + #[test] fn build_without_context_includes_identity_fields() { let profile = test_profile(ClientOs::Linux); diff --git a/flake.nix b/flake.nix index 88cdae9..d0acd2c 100644 --- a/flake.nix +++ b/flake.nix @@ -26,7 +26,7 @@ cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); pname = "globalprotect-openconnect"; version = cargoToml.workspace.package.version; - releaseTag = "v2.6.3"; + releaseTag = "v2.6.4"; toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;