diff --git a/src/api/endpoints/hls_api.rs b/src/api/endpoints/hls_api.rs index ac94a95c0..add36211a 100644 --- a/src/api/endpoints/hls_api.rs +++ b/src/api/endpoints/hls_api.rs @@ -25,13 +25,10 @@ struct HlsApiPathParams { token: String, } -fn hls_response(hls_content: String, cookie: Option) -> impl IntoResponse + Send { +fn hls_response(hls_content: String) -> impl IntoResponse + Send { let mut builder = axum::response::Response::builder() .status(axum::http::StatusCode::OK) .header(axum::http::header::CONTENT_TYPE, "application/x-mpegurl"); - if let Some(cookie) = cookie { - builder = builder.header(axum::http::header::SET_COOKIE, cookie); - } builder.body(hls_content) .unwrap() .into_response() @@ -85,7 +82,7 @@ pub(in crate::api) async fn handle_hls_stream_request( user_token: session_token.as_deref(), }; let hls_content = rewrite_hls(user, &rewrite_hls_props); - hls_response(hls_content, session_token).into_response() + hls_response(hls_content).into_response() } Err(err) => { error!("Failed to download m3u8 {}", sanitize_sensitive_info(err.to_string().as_str())); diff --git a/src/model/config_api_proxy.rs b/src/model/config_api_proxy.rs index d5c6d151f..11e2b26cb 100644 --- a/src/model/config_api_proxy.rs +++ b/src/model/config_api_proxy.rs @@ -534,7 +534,11 @@ impl ApiProxyConfig { return Some((credentials.clone(), target_name.to_string())); } } - debug!("Could not find any target for user {username}"); + if log::log_enabled!(log::Level::Debug) { + if !username.eq("api") { + debug!("Could not find any target for user {username}"); + } + } None } diff --git a/src/processing/parser/hls.rs b/src/processing/parser/hls.rs index 2e8dab7a3..b92618170 100644 --- a/src/processing/parser/hls.rs +++ b/src/processing/parser/hls.rs @@ -3,19 +3,23 @@ use crate::utils::{CONSTANTS, HLS_PREFIX}; use crate::utils::{deobfuscate_text, obfuscate_text}; use std::str; +const TOKEN_SEPARATOR: char = '\x1F'; + fn create_hls_session_token_and_url(secret: &[u8], session_token: &str, stream_url: &str) -> Option { - if let Ok(cookie_value) = obfuscate_text(secret, &format!("{session_token}{stream_url}")) { + if let Ok(cookie_value) = obfuscate_text(secret, &format!("{session_token}{TOKEN_SEPARATOR}{stream_url}")) { return Some(cookie_value); } None } -const TOKEN_LEN: usize = 6; pub fn get_hls_session_token_and_url_from_token(secret: &[u8], token: &str) -> Option<(Option, String)> { if let Ok(decrypted) = deobfuscate_text(secret, token) { - let session_token: String = decrypted.chars().take(TOKEN_LEN).collect(); - let stream_url: String = decrypted.chars().skip(TOKEN_LEN).collect(); - return Some((Some(session_token), stream_url)); + let parts: Vec<&str> = decrypted.split(TOKEN_SEPARATOR).collect(); + if !parts.is_empty() && parts.len() == 2 { + let session_token: String = parts[0].to_string(); + let stream_url: String = parts[1].to_string(); + return Some((Some(session_token), stream_url)); + } } None }