Skip to content

Commit

Permalink
rename pow section in settings to captcha and add options to configure
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
realaravinth committed Dec 3, 2021
1 parent 032f604 commit 42544ec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 7 additions & 1 deletion config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ domain = "localhost"
proxy_has_tls = false
#url_prefix = ""

[pow]
[captcha]
# Please set a unique value, your mCaptcha instance's security depends on this being
# unique
salt = "asdl;kjfhjawehfpa;osdkjasdvjaksndfpoanjdfainsdfaijdsfajlkjdsaf;ajsdfweroire"
# garbage collection period to manage mCaptcha system
# leave untouched if you don't know what you are doing
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]
# This section deals with the database location and how to access it
# Please note that at the moment, we have support for only postgresqa.
Expand Down
4 changes: 2 additions & 2 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl SystemGroup {

fn new_system<A: Save, B: MasterTrait>(m: Addr<B>, c: Addr<A>) -> System<A, B> {
let pow = PoWConfigBuilder::default()
.salt(SETTINGS.pow.salt.clone())
.salt(SETTINGS.captcha.salt.clone())
.build()
.unwrap();

Expand All @@ -128,7 +128,7 @@ impl SystemGroup {
SystemGroup::Redis(captcha)
}
None => {
let master = EmbeddedMaster::new(SETTINGS.pow.gc).start();
let master = EmbeddedMaster::new(SETTINGS.captcha.gc).start();
let cache = HashCache::default().start();
let captcha = Self::new_system(master, cache);

Expand Down
11 changes: 10 additions & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ pub struct Server {
pub struct Captcha {
pub salt: String,
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)]
Expand Down Expand Up @@ -102,7 +111,7 @@ pub struct Settings {
pub database: Database,
pub redis: Option<Redis>,
pub server: Server,
pub pow: Captcha,
pub captcha: Captcha,
pub source_code: String,
pub smtp: Option<Smtp>,
pub allow_registration: bool,
Expand Down

0 comments on commit 42544ec

Please sign in to comment.