diff options
author | Daniel GarcĂa <[email protected]> | 2020-04-11 23:34:37 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-11 23:34:37 +0200 |
commit | e3feba2a2cc928e05d4f7372913741029f095dce (patch) | |
tree | 4625d293f99037b1f4801667bf6766e0ca15503c | |
parent | 4be8dae626e641cad20f5b0c49f18e0bac9ff67a (diff) | |
parent | 0a68de6c24a51e4e221ae5afb43d2cfc6b48dac1 (diff) | |
download | vaultwarden-1.14.2.tar.gz vaultwarden-1.14.2.zip |
Merge pull request #960 from jjlin/admin-token1.14.2
Warn on empty `ADMIN_TOKEN` instead of bailing out
-rw-r--r-- | src/api/admin.rs | 2 | ||||
-rw-r--r-- | src/config.rs | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/api/admin.rs b/src/api/admin.rs index 7014c43c..e9873112 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -17,7 +17,7 @@ use crate::mail; use crate::CONFIG; pub fn routes() -> Vec<Route> { - if CONFIG.admin_token().is_none() && !CONFIG.disable_admin_token() { + if !CONFIG.disable_admin_token() && !CONFIG.is_admin_token_set() { return routes![admin_disabled]; } diff --git a/src/config.rs b/src/config.rs index 0d79b215..7492950b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -430,7 +430,8 @@ fn validate_config(cfg: &ConfigItems) -> Result<(), Error> { if let Some(ref token) = cfg.admin_token { if token.trim().is_empty() && !cfg.disable_admin_token { - err!("`ADMIN_TOKEN` is enabled but has an empty value. To enable the admin page without token, use `DISABLE_ADMIN_TOKEN`") + println!("[WARNING] `ADMIN_TOKEN` is enabled but has an empty value, so the admin page will be disabled."); + println!("[WARNING] To enable the admin page without a token, use `DISABLE_ADMIN_TOKEN`."); } } @@ -617,6 +618,13 @@ impl Config { } } + /// Tests whether the admin token is set to a non-empty value. + pub fn is_admin_token_set(&self) -> bool { + let token = self.admin_token(); + + !token.is_none() && !token.unwrap().trim().is_empty() + } + pub fn render_template<T: serde::ser::Serialize>( &self, name: &str, |