From eedfc4c7a1137f72921f7cf527a2c658d689563d Mon Sep 17 00:00:00 2001 From: Matlink Date: Thu, 3 Aug 2023 14:28:40 +0200 Subject: [PATCH] implement server side default URI matching --- .env.template | 11 +++++++++++ src/api/core/ciphers.rs | 4 ++++ src/config.rs | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/.env.template b/.env.template index 6e164152..0f396a2e 100644 --- a/.env.template +++ b/.env.template @@ -97,6 +97,17 @@ ## If unset (the default), events are kept indefinitely and the scheduled job is disabled! # EVENTS_DAYS_RETAIN= +## Override the default URI matching when for all ciphers +## When users leave the default URI matching for a cipher, replace it by the given value. +## -1: user default, +## 0: base domain, +## 1: host, +## 2: begins with, +## 3: regular expression, +## 4: exact match, +## 5: never match. +# OVERRIDE_DEFAULT_URI_MATCHING=-1 + ## BETA FEATURE: Groups ## Controls whether group support is enabled for organizations ## This setting applies to organizations. diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 43702219..bfcd02bb 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -456,6 +456,10 @@ pub async fn update_cipher_from_data( if json_data.is_array() { json_data.as_array_mut().unwrap().iter_mut().for_each(|ref mut f| { f.as_object_mut().unwrap().remove("Response"); + // When user leaves the default "URI matching" and admin has it overridden + if CONFIG.override_default_uri_matching() >= 0 && f["Match"].is_null() { + f.as_object_mut().unwrap()["Match"] = Value::Number(CONFIG.override_default_uri_matching().into()); + } }); }; json_data diff --git a/src/config.rs b/src/config.rs index 7351b941..eba6bd84 100644 --- a/src/config.rs +++ b/src/config.rs @@ -494,6 +494,16 @@ make_config! { /// Events days retain |> Number of days to retain events stored in the database. If unset, events are kept indefently. events_days_retain: i64, false, option; + + /// Override default URI matching for all ciphers |> When users leave the default URI matching for a cipher, replace it by the given value. + /// -1: user default, + /// 0: base domain, + /// 1: host, + /// 2: begins with, + /// 3: regular expression, + /// 4: exact match, + /// 5: never match. + override_default_uri_matching: i8, true, def, -1; }, /// Advanced settings