rename pow section in settings to captcha and add options to configure

suggested difficulty factors for use in CAPTCHA configurations
estimates

The current CAPTCHA configuration panel requires the user to provide
difficulty factor <--> visitor threshold mapping, which can be tedious
if the user isn't familiar with those parameters. Also, it could lead to
ineffective limiting from mCaptcha's side, should it be configured
improperly.

So an estimate computed from well known statistics like peak, avg and
broke-my-site traffic could go a long way.
This commit is contained in:
realaravinth 2021-12-03 14:21:18 +05:30
parent 032f6040b8
commit 42544ec421
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
3 changed files with 19 additions and 4 deletions

View file

@ -21,7 +21,7 @@ domain = "localhost"
proxy_has_tls = false proxy_has_tls = false
#url_prefix = "" #url_prefix = ""
[pow] [captcha]
# Please set a unique value, your mCaptcha instance's security depends on this being # Please set a unique value, your mCaptcha instance's security depends on this being
# unique # unique
salt = "asdl;kjfhjawehfpa;osdkjasdvjaksndfpoanjdfainsdfaijdsfajlkjdsaf;ajsdfweroire" salt = "asdl;kjfhjawehfpa;osdkjasdvjaksndfpoanjdfainsdfaijdsfajlkjdsaf;ajsdfweroire"
@ -29,6 +29,12 @@ salt = "asdl;kjfhjawehfpa;osdkjasdvjaksndfpoanjdfainsdfaijdsfajlkjdsaf;ajsdfwero
# leave untouched if you don't know what you are doing # leave untouched if you don't know what you are doing
gc = 30 gc = 30
[captcha.default_difficulty_strategy]
avg_traffic_difficulty = 50000 # almost instant solution
peak_sustainable_traffic_difficulty = 3000000 # roughly 1.5s
broke_my_site_traffic_difficulty = 5000000 # greater than 3.5s
duration = 30 # cooldown period in seconds
[database] [database]
# This section deals with the database location and how to access it # This section deals with the database location and how to access it
# Please note that at the moment, we have support for only postgresqa. # Please note that at the moment, we have support for only postgresqa.

View file

@ -103,7 +103,7 @@ impl SystemGroup {
fn new_system<A: Save, B: MasterTrait>(m: Addr<B>, c: Addr<A>) -> System<A, B> { fn new_system<A: Save, B: MasterTrait>(m: Addr<B>, c: Addr<A>) -> System<A, B> {
let pow = PoWConfigBuilder::default() let pow = PoWConfigBuilder::default()
.salt(SETTINGS.pow.salt.clone()) .salt(SETTINGS.captcha.salt.clone())
.build() .build()
.unwrap(); .unwrap();
@ -128,7 +128,7 @@ impl SystemGroup {
SystemGroup::Redis(captcha) SystemGroup::Redis(captcha)
} }
None => { None => {
let master = EmbeddedMaster::new(SETTINGS.pow.gc).start(); let master = EmbeddedMaster::new(SETTINGS.captcha.gc).start();
let cache = HashCache::default().start(); let cache = HashCache::default().start();
let captcha = Self::new_system(master, cache); let captcha = Self::new_system(master, cache);

View file

@ -36,6 +36,15 @@ pub struct Server {
pub struct Captcha { pub struct Captcha {
pub salt: String, pub salt: String,
pub gc: u64, pub gc: u64,
pub default_difficulty_strategy: DefaultDifficultyStrategy,
}
#[derive(Debug, Clone, Deserialize)]
pub struct DefaultDifficultyStrategy {
pub avg_traffic_difficulty: u32,
pub broke_my_site_traffic_difficulty: u32,
pub peak_sustainable_traffic_difficulty: u32,
pub duration: u32,
} }
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
@ -102,7 +111,7 @@ pub struct Settings {
pub database: Database, pub database: Database,
pub redis: Option<Redis>, pub redis: Option<Redis>,
pub server: Server, pub server: Server,
pub pow: Captcha, pub captcha: Captcha,
pub source_code: String, pub source_code: String,
pub smtp: Option<Smtp>, pub smtp: Option<Smtp>,
pub allow_registration: bool, pub allow_registration: bool,