From 78c0728ec06724051ca96a95cb6a60bedd12dee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 22:02:35 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test(password):=20the=20rule=20live?= =?UTF-8?q?s=20on=20the=20control,=20and=20punctuation=20is=20not=20a=20ru?= =?UTF-8?q?le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An invited member read "not your address or your name" and concluded the form would not take a `*`. Nothing in the policy mentions characters, so either the report was a coincidence or the wire was eating one — a form body is url-encoded, where `+` means space and `%` opens an escape. The test sets a password of `*+&%= ?#/\ tulip 42` through the join link and then signs in with it, so the round trip is the thing under test rather than my reading of the encoder. It passes: the refusal he saw was the rule it named. The length rule now rides the control. `MIN_PASSWORD_CHARS` is one constant that `check_password` compares against and the three new-password inputs carry as `minlength`, so the browser refuses a short one where it is being typed instead of the server explaining it after a round trip — and the number cannot drift between the two, which is what a `10` written in four places is for. --- crates/izlek-core/src/auth.rs | 9 +++++- crates/izlek-web/src/pages.rs | 2 ++ crates/izlek-web/src/settings.rs | 2 +- crates/izlek-web/tests/http.rs | 49 ++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/crates/izlek-core/src/auth.rs b/crates/izlek-core/src/auth.rs index 1a486d9..7abe465 100644 --- a/crates/izlek-core/src/auth.rs +++ b/crates/izlek-core/src/auth.rs @@ -25,6 +25,13 @@ pub const ARGON2_PARALLELISM: u32 = 1; /// How many bytes of randomness every token carries. pub const TOKEN_BYTES: usize = 16; +/// The shortest password this app accepts. +/// +/// Named because the form that takes a new password carries it too — as +/// `minlength`, so the browser enforces the rule where it is being broken +/// rather than the server explaining it afterwards. Two places, one number. +pub const MIN_PASSWORD_CHARS: usize = 10; + /// A password rule the person's choice broke. The wording is the wording on the /// first-sign-in screen. #[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)] @@ -155,7 +162,7 @@ pub fn check_password( ) -> Result<(), PasswordProblem> { // Counted in characters, not bytes: a ten-character password is ten // characters whatever alphabet it is in. - if password.chars().count() < 10 { + if password.chars().count() < MIN_PASSWORD_CHARS { return Err(PasswordProblem::TooShort); } diff --git a/crates/izlek-web/src/pages.rs b/crates/izlek-web/src/pages.rs index 65b3db7..8fc4344 100644 --- a/crates/izlek-web/src/pages.rs +++ b/crates/izlek-web/src/pages.rs @@ -117,6 +117,7 @@ async fn setup_card(cx: &Cx) -> Result { type="password" name="password" autocomplete="new-password" + minlength=(izlek_core::auth::MIN_PASSWORD_CHARS.to_string()) required="" > @@ -222,6 +223,7 @@ async fn join_card(cx: &Cx, token: &str, person: Invited) -> Result { type="password" name="password" autocomplete="new-password" + minlength=(izlek_core::auth::MIN_PASSWORD_CHARS.to_string()) required="" > diff --git a/crates/izlek-web/src/settings.rs b/crates/izlek-web/src/settings.rs index 17732e7..b80e2da 100644 --- a/crates/izlek-web/src/settings.rs +++ b/crates/izlek-web/src/settings.rs @@ -1311,7 +1311,7 @@ async fn settings_page(cx: &Cx) -> Result {
if let Some(refusal) = &password_refusal { diff --git a/crates/izlek-web/tests/http.rs b/crates/izlek-web/tests/http.rs index 7eefd4b..54e9e0a 100644 --- a/crates/izlek-web/tests/http.rs +++ b/crates/izlek-web/tests/http.rs @@ -536,6 +536,55 @@ async fn queued_join_token(app: &App, email: &str) -> String { } /// Invites someone in the given role and signs them in, returning their cookie. +#[tokio::test] +async fn a_password_may_be_made_of_punctuation() { + // An invited member reported "it would not accept the *". Nothing in the + // rules mentions characters, so if one is refused it is the wire eating + // it, not the policy: a form body is url-encoded, where `+` means space + // and `%` starts an escape, and a password that survives the round trip + // in a test is a password that survives it in a browser. + let app = App::open().await; + let admin_cookie = admin(&app).await; + let email = "punct@izlek.sh"; + let answer = app + .post( + "/api/invite_member", + Some(&admin_cookie), + &[("email", email), ("display_name", "Pat"), ("role", "member")], + ) + .await; + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); + let token = queued_join_token(&app, email).await; + + let password = "*+&%= ?#/\\ tulip 42"; + let answer = app + .post( + "/api/redeem_link", + None, + &[("token", &token), ("password", password)], + ) + .await; + assert_eq!(answer.status, StatusCode::SEE_OTHER, "{}", answer.body); + assert_eq!(answer.body, "null", "the punctuation password was refused"); + + // And it is the same password on the way back in — an encoding that ate a + // character on the way in would let them set one thing and sign in with + // another. + let back = app + .post( + "/api/sign_in", + None, + &[("email", email), ("password", password)], + ) + .await; + assert_eq!(back.status, StatusCode::SEE_OTHER, "{}", back.body); + assert!( + back.session.is_some(), + "the password that was set does not sign in: {}", + back.body + ); +} + async fn invited(app: &App, admin: &str, email: &str, name: &str, role: Role) -> String { let role = match role { Role::Admin => "admin",