Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proto
20 changes: 18 additions & 2 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub(crate) mod register_mfa;

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

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

let version = parts
.headers
.get(CLIENT_VERSION_HEADER)
.and_then(|v| v.to_str().ok())
.map(str::to_string);
let platform = parts
.headers
.get(CLIENT_PLATFORM_HEADER)
.and_then(|v| v.to_str().ok())
.map(str::to_string);

let ip_address = forwarded_for_ip
.or(insecure_ip)
.map(|v| v.to_string())
.map_err(|_| ApiError::Unexpected("Missing client IP".to_string()))?;

Ok(DeviceInfo {
Ok(Self {
ip_address,
user_agent,
version,
platform,
})
}
}
Expand Down Expand Up @@ -84,9 +99,10 @@ pub(crate) async fn get_core_response(rx: Receiver<Payload>) -> Result<Payload,

#[cfg(test)]
mod tests {
use super::*;
use axum::{body::Body, http::Request};

use super::*;

static VALID_USER_AGENTS: &[&str] = &[
// desktop
"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",
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ pub(crate) mod proto {
extern crate tracing;

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