Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa2d92a7ae | |||
| 786579a7d8 | |||
| af9359bbdf | |||
| b8c705554f | |||
| 826a3b59c9 |
@@ -47,7 +47,16 @@ struct GetAppsResponse {
|
|||||||
impl crate::backend::Backend {
|
impl crate::backend::Backend {
|
||||||
#[craft(endpoint(status_codes(StatusCode::OK, StatusCode::INTERNAL_SERVER_ERROR)))]
|
#[craft(endpoint(status_codes(StatusCode::OK, StatusCode::INTERNAL_SERVER_ERROR)))]
|
||||||
pub async fn get_apps(self: ::std::sync::Arc<Self>, depot: &mut Depot) -> AppResult<Json<GetAppsResponse>> {
|
pub async fn get_apps(self: ::std::sync::Arc<Self>, depot: &mut Depot) -> AppResult<Json<GetAppsResponse>> {
|
||||||
let user = auth::get_user_from_depot(depot).cloned();
|
let user = match auth::get_user_from_depot(depot) {
|
||||||
|
Some(u) => u.clone(),
|
||||||
|
None => {
|
||||||
|
error!("get_apps reached without authenticated user in depot");
|
||||||
|
return Err(AppError {
|
||||||
|
status_code: StatusCode::UNAUTHORIZED,
|
||||||
|
description: "Not authenticated".to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
let standard_error = Err(AppError {
|
let standard_error = Err(AppError {
|
||||||
status_code: StatusCode::INTERNAL_SERVER_ERROR,
|
status_code: StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
description: "failed to get available apps".to_string(),
|
description: "failed to get available apps".to_string(),
|
||||||
@@ -146,7 +155,6 @@ impl crate::backend::Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter apps by user permissions (admins see everything)
|
// Filter apps by user permissions (admins see everything)
|
||||||
if let Some(ref user) = user {
|
|
||||||
if !user.is_admin {
|
if !user.is_admin {
|
||||||
let permissions = self.db.get_permissions(&user.id).unwrap_or_default();
|
let permissions = self.db.get_permissions(&user.id).unwrap_or_default();
|
||||||
for (server_name, apps) in get_apps_resp.apps.iter_mut() {
|
for (server_name, apps) in get_apps_resp.apps.iter_mut() {
|
||||||
@@ -158,7 +166,6 @@ impl crate::backend::Backend {
|
|||||||
}
|
}
|
||||||
get_apps_resp.apps.retain(|_, apps| !apps.is_empty());
|
get_apps_resp.apps.retain(|_, apps| !apps.is_empty());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Json(get_apps_resp))
|
Ok(Json(get_apps_resp))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,31 +85,17 @@ impl crate::proxy::Proxy {
|
|||||||
description: "Could not start stream".to_string(),
|
description: "Could not start stream".to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Validate single-use stream token
|
// Validate single-use stream token via the shared helper so this
|
||||||
|
// handler and its unit tests exercise the same code path.
|
||||||
let provided_token = req.query::<String>("token").unwrap_or_default();
|
let provided_token = req.query::<String>("token").unwrap_or_default();
|
||||||
{
|
if let Err(msg) = super::validate_stream_token(&self, &provided_token).await {
|
||||||
let mut token_guard = self.stream_token.write().await;
|
error!("Stream token validation failed: {msg}");
|
||||||
match token_guard.take() {
|
return Err(AppError {
|
||||||
Some(expected) if expected == provided_token => {
|
status_code: StatusCode::UNAUTHORIZED,
|
||||||
// Token consumed successfully (single-use)
|
description: msg,
|
||||||
|
});
|
||||||
|
}
|
||||||
info!("Stream token validated and consumed");
|
info!("Stream token validated and consumed");
|
||||||
}
|
|
||||||
Some(_) => {
|
|
||||||
error!("Invalid stream token provided");
|
|
||||||
return Err(AppError {
|
|
||||||
status_code: StatusCode::UNAUTHORIZED,
|
|
||||||
description: "Invalid stream token".to_string(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
error!("Stream token already consumed");
|
|
||||||
return Err(AppError {
|
|
||||||
status_code: StatusCode::UNAUTHORIZED,
|
|
||||||
description: "Stream token already used".to_string(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("WebTransport connection initiated");
|
info!("WebTransport connection initiated");
|
||||||
let (wt_stream_send, wt_stream_recv, wt_datagram_send) = match setup_webtransport(req).await
|
let (wt_stream_send, wt_stream_recv, wt_datagram_send) = match setup_webtransport(req).await
|
||||||
|
|||||||
@@ -85,8 +85,9 @@ pub async fn validate_stream_token(proxy: &Proxy, provided: &str) -> std::result
|
|||||||
match token_guard.take() {
|
match token_guard.take() {
|
||||||
Some(expected) if expected == provided => Ok(()),
|
Some(expected) if expected == provided => Ok(()),
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
// Put the token back since it wasn't matched
|
// Wrong token: still consumed by the `take()` above. Any validation
|
||||||
// Actually no — the design is that any attempt consumes it for security
|
// attempt — correct or not — invalidates the token, so a wrong
|
||||||
|
// guess cannot be followed by a correct one.
|
||||||
Err("Invalid stream token".to_string())
|
Err("Invalid stream token".to_string())
|
||||||
}
|
}
|
||||||
None => Err("Stream token already used".to_string()),
|
None => Err("Stream token already used".to_string()),
|
||||||
|
|||||||
@@ -90,7 +90,16 @@ impl crate::backend::Backend {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Check app permission
|
// Check app permission
|
||||||
if let Some(user) = auth::get_user_from_depot(depot) {
|
let user = match auth::get_user_from_depot(depot) {
|
||||||
|
Some(u) => u.clone(),
|
||||||
|
None => {
|
||||||
|
error!("post_stream_start reached without authenticated user in depot");
|
||||||
|
return Err(AppError {
|
||||||
|
status_code: StatusCode::UNAUTHORIZED,
|
||||||
|
description: "Not authenticated".to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
if !user.is_admin {
|
if !user.is_admin {
|
||||||
match self.db.check_app_permission(&user.id, &body.server, body.id as i64) {
|
match self.db.check_app_permission(&user.id, &body.server, body.id as i64) {
|
||||||
Ok(true) => {}
|
Ok(true) => {}
|
||||||
@@ -106,7 +115,6 @@ impl crate::backend::Backend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let reader = self.state.read().await;
|
let reader = self.state.read().await;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user