Skip to content

Commit

Permalink
Move room-ID header validation into authorize
Browse files Browse the repository at this point in the history
  • Loading branch information
adel-signal authored Oct 1, 2024
1 parent 3bdd3d1 commit f701aec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 9 additions & 0 deletions frontend/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use axum::{
routing::get,
Extension, Router,
};
use axum_extra::TypedHeader;
use base64::engine::general_purpose::STANDARD;
use base64::Engine;
use http::{header, Method, StatusCode};
Expand All @@ -30,6 +31,7 @@ use tower::ServiceBuilder;
use zkgroup::call_links::CreateCallLinkCredentialPresentation;

use crate::{
api::call_links::RoomId,
authenticator::{Authenticator, AuthenticatorError, GroupAuthToken, ParsedHeader::*},
frontend::{Frontend, FrontendError},
metrics::histogram::Histogram,
Expand Down Expand Up @@ -164,13 +166,20 @@ async fn metrics(
/// Middleware to handle the authorization header.
async fn authorize(
State(frontend): State<Arc<Frontend>>,
room_id: Option<TypedHeader<RoomId>>,
mut req: Request,
next: Next,
) -> Result<axum::response::Response, StatusCode> {
trace!("authorize");

let user_agent = get_user_agent(&req)?;

if let Some(room_id) = room_id {
if room_id.0.as_ref().contains(":") {
return Err(StatusCode::BAD_REQUEST);
}
}

let authorization_header = req
.headers()
.get(header::AUTHORIZATION)
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/api/call_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ impl Header for RoomId {
return Err(headers::Error::invalid());
}
if let Ok(value) = value.to_str() {
if value.contains(":") {
Err(headers::Error::invalid())
} else {
Ok(Self(value.into()))
}
Ok(Self(value.into()))
} else {
Err(headers::Error::invalid())
}
Expand Down

0 comments on commit f701aec

Please sign in to comment.