Skip to content

Commit 9f302d9

Browse files
committed
oidc use localhost for redirect config instead of 0.0.0.0 by default
1 parent 8e07bab commit 9f302d9

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/webserver/oidc.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,7 @@ impl TryFrom<&AppConfig> for OidcConfig {
4040
"The \"oidc_client_secret\" setting is required to authenticate with the OIDC provider",
4141
))?;
4242

43-
let app_host = config
44-
.host
45-
.as_ref()
46-
.or_else(|| config.https_domain.as_ref())
47-
.cloned()
48-
.unwrap_or_else(|| {
49-
let host = config.listen_on().to_string();
50-
log::warn!(
51-
"No host or https_domain provided in the configuration, using \"{}\" as the app host to build the redirect URL. This will only work locally. Disable this warning by providing a value for the \"host\" setting.",
52-
host
53-
);
54-
host
55-
});
43+
let app_host = get_app_host(config);
5644

5745
Ok(Self {
5846
issuer_url: issuer_url.clone(),
@@ -68,6 +56,31 @@ impl TryFrom<&AppConfig> for OidcConfig {
6856
}
6957
}
7058

59+
fn get_app_host(config: &AppConfig) -> String {
60+
if let Some(host) = &config.host {
61+
return host.clone();
62+
}
63+
if let Some(https_domain) = &config.https_domain {
64+
return https_domain.clone();
65+
}
66+
67+
let socket_addr = config.listen_on();
68+
let ip = socket_addr.ip();
69+
let host = if ip.is_unspecified() || ip.is_loopback() {
70+
format!("localhost:{}", socket_addr.port())
71+
} else {
72+
socket_addr.to_string()
73+
};
74+
log::warn!(
75+
"No host or https_domain provided in the configuration, \
76+
using \"{}\" as the app host to build the redirect URL. \
77+
This will only work locally. \
78+
Disable this warning by providing a value for the \"host\" setting.",
79+
host
80+
);
81+
host
82+
}
83+
7184
pub struct OidcMiddleware {
7285
pub config: Option<Arc<OidcConfig>>,
7386
app_state: web::Data<AppState>,
@@ -79,7 +92,6 @@ impl OidcMiddleware {
7992
match &config {
8093
Ok(config) => {
8194
log::debug!("Setting up OIDC with issuer: {}", config.issuer_url);
82-
// contains secrets
8395
}
8496
Err(Some(err)) => {
8597
log::error!("Invalid OIDC configuration: {err}");

0 commit comments

Comments
 (0)