Ajout de vérifications des informations données
Rust Checks / checks (push) Successful in 20s Details
Rust Checks / checks (pull_request) Successful in 19s Details

This commit is contained in:
Tipragot 2024-01-10 08:30:33 +01:00
parent b707b857a9
commit 4c0c392819
1 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,5 @@
//! Un simple serveur http pour enregistrer des scores du jeu Ponguito.
use std::collections::HashMap;
use std::net::IpAddr;
use axum::extract::{Path, Query};
@ -138,6 +137,18 @@ async fn register_score(
LeftmostXForwardedFor(ip): LeftmostXForwardedFor,
Path((name, score)): Path<(String, u32)>,
) -> impl IntoResponse {
// Vérification des informations
let name = name.trim().to_lowercase();
if name.is_empty() || score == 0 {
return StatusCode::BAD_REQUEST;
}
// Vérification du nom du joueur
let authorized_characters = "abcdefghijklmnopqrstuvwxyz0123456789_-";
if name.chars().any(|c| !authorized_characters.contains(c)) {
return StatusCode::BAD_REQUEST;
}
// Création du fichier de logs des scores si il n'existe pas
let mut file = OpenOptions::new()
.create(true)