fixed javalsai's mess

This commit is contained in:
2026-05-31 15:50:00 +01:00
parent 585d642204
commit 9378ab8fed
4 changed files with 59 additions and 10 deletions
Generated
+39
View File
@@ -2,6 +2,15 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "aho-corasick"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.102" version = "1.0.102"
@@ -98,6 +107,7 @@ dependencies = [
"axum", "axum",
"futures", "futures",
"rand 0.10.1", "rand 0.10.1",
"regex",
"serde", "serde",
"serde_json", "serde_json",
"tokio", "tokio",
@@ -668,6 +678,35 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "regex"
version = "1.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.23" version = "1.0.23"
+1
View File
@@ -8,6 +8,7 @@ anyhow = "1.0.102"
axum = { version = "0.8.9", features = ["ws"] } axum = { version = "0.8.9", features = ["ws"] }
futures = "0.3.32" futures = "0.3.32"
rand = "0.10.1" rand = "0.10.1"
regex = "1.12.3"
serde = { version = "1.0.228", features = ["derive"] } serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149" serde_json = "1.0.149"
tokio = { version = "1.52.3", features = ["full"] } tokio = { version = "1.52.3", features = ["full"] }
BIN
View File
Binary file not shown.
+19 -10
View File
@@ -28,6 +28,7 @@ use futures::StreamExt as _;
use rand::random_bool; use rand::random_bool;
use serde::{Deserialize, Serialize, de}; use serde::{Deserialize, Serialize, de};
use serde_json::json; use serde_json::json;
use regex::Regex;
#[derive(Deserialize, Serialize, Debug, Ord, Eq, PartialEq, PartialOrd, Clone)] #[derive(Deserialize, Serialize, Debug, Ord, Eq, PartialEq, PartialOrd, Clone)]
struct Entry struct Entry
@@ -372,15 +373,14 @@ async fn handle_socket
let Some(name) = socket.next().await else let Some(name) = socket.next().await else
{ {
eprintln!("user gave no username"); eprintln!("No username");
return; return;
}; };
let name: Arc<str> = match name.expect("failed to recv socket msg") let name: Arc<str> = match name.expect("failed to recv socket msg")
{ {
Message::Text(text) Message::Text(text) =>
if validate_name(&text.to_string()) =>
{ {
Arc::from(text.to_string().into_boxed_str()) Arc::from(validate_name(text.to_string()))
} }
_ => Arc::from("anon"), _ => Arc::from("anon"),
}; };
@@ -442,16 +442,25 @@ async fn handle_socket
} }
} }
fn validate_name(input: &str) -> bool { fn validate_name(input: String) -> String {
let input = input.trim(); let input = input.trim();
if input == "null"
// Length check
if input.is_empty() || input.len() > 32
{ {
return false; return "anon".to_string();
}
// Length check
if input.is_empty() || input.len() > 32 {
return "anon".to_string();
} }
input.chars().all(|c| c.is_ascii_alphanumeric()) // Allow only letters, numbers, _ and -
let re = Regex::new(r"^[a-zA-Z0-9_-]+$").unwrap();
if re.is_match(input) {
input.to_string()
} else {
"anon".to_string()
}
} }
// static routes // static routes