Normalize fingerprints everywhere: strip colons from URLs and DB keys

Client: strip colons before putting fingerprints in URL paths
(colons in URLs confuse axum path matching).

Server: normalize fingerprints in message routes too.

All fingerprint storage and lookup is now hex-only, case-insensitive.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-03-26 22:41:26 +04:00
parent de118371de
commit 8dd45b1bfe
2 changed files with 12 additions and 5 deletions

View File

@@ -21,11 +21,15 @@ struct SendRequest {
message: Vec<u8>,
}
fn normalize_fp(fp: &str) -> String {
fp.chars().filter(|c| c.is_ascii_hexdigit()).collect::<String>().to_lowercase()
}
async fn send_message(
State(state): State<AppState>,
Json(req): Json<SendRequest>,
) -> AppResult<Json<serde_json::Value>> {
let key = format!("queue:{}", req.to);
let key = format!("queue:{}", normalize_fp(&req.to));
state.db.messages.insert(
format!("{}:{}", key, uuid::Uuid::new_v4()).as_bytes(),
req.message,
@@ -37,7 +41,7 @@ async fn poll_messages(
State(state): State<AppState>,
Path(fingerprint): Path<String>,
) -> AppResult<Json<Vec<String>>> {
let prefix = format!("queue:{}", fingerprint);
let prefix = format!("queue:{}", normalize_fp(&fingerprint));
let mut messages = Vec::new();
for item in state.db.messages.scan_prefix(prefix.as_bytes()) {
let (_, value) = item?;