Skip to content

Commit 09aa2a3

Browse files
authored
Basic client version reporting (#209)
* client-version-checking * update min core version * Update proto
1 parent 46367f9 commit 09aa2a3

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

proto

src/handlers/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub(crate) mod register_mfa;
1818

1919
// Timeout for awaiting response from Defguard Core.
2020
const CORE_RESPONSE_TIMEOUT: Duration = Duration::from_secs(5);
21+
const CLIENT_VERSION_HEADER: &str = "defguard-client-version";
22+
const CLIENT_PLATFORM_HEADER: &str = "defguard-client-platform";
2123

2224
impl<S> FromRequestParts<S> for DeviceInfo
2325
where
@@ -39,14 +41,27 @@ where
3941
// sanitize user-agent
4042
.filter(|agent| !ammonia::is_html(agent));
4143

44+
let version = parts
45+
.headers
46+
.get(CLIENT_VERSION_HEADER)
47+
.and_then(|v| v.to_str().ok())
48+
.map(str::to_string);
49+
let platform = parts
50+
.headers
51+
.get(CLIENT_PLATFORM_HEADER)
52+
.and_then(|v| v.to_str().ok())
53+
.map(str::to_string);
54+
4255
let ip_address = forwarded_for_ip
4356
.or(insecure_ip)
4457
.map(|v| v.to_string())
4558
.map_err(|_| ApiError::Unexpected("Missing client IP".to_string()))?;
4659

47-
Ok(DeviceInfo {
60+
Ok(Self {
4861
ip_address,
4962
user_agent,
63+
version,
64+
platform,
5065
})
5166
}
5267
}
@@ -84,9 +99,10 @@ pub(crate) async fn get_core_response(rx: Receiver<Payload>) -> Result<Payload,
8499

85100
#[cfg(test)]
86101
mod tests {
87-
use super::*;
88102
use axum::{body::Body, http::Request};
89103

104+
use super::*;
105+
90106
static VALID_USER_AGENTS: &[&str] = &[
91107
// desktop
92108
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.10 Safari/605.1.1 43.03",

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ pub(crate) mod proto {
1717
extern crate tracing;
1818

1919
pub static VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), "+", env!("VERGEN_GIT_SHA"));
20-
pub const MIN_CORE_VERSION: Version = Version::new(1, 5, 0);
20+
pub const MIN_CORE_VERSION: Version = Version::new(1, 6, 0);

0 commit comments

Comments
 (0)