From 2bb6d09d1b06bde4ddcf62050a17a38ade5b92b4 Mon Sep 17 00:00:00 2001 From: euzu Date: Fri, 14 Mar 2025 13:21:18 +0100 Subject: [PATCH] hls reverse proxy random token generation to avoid clashes --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/processing/parser/hls.rs | 4 ++-- src/utils/hash_utils.rs | 7 ++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7b382ed4..f2821dd7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1503,6 +1503,7 @@ dependencies = [ "tower-http", "unidecode", "url", + "uuid", "vergen", "winapi", ] @@ -2840,6 +2841,15 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "uuid" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "458f7a779bf54acc9f347480ac654f68407d3aab21269a6e3c9f922acd9e2da9" +dependencies = [ + "getrandom 0.3.1", +] + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index dadfb1f23..5806ba5a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,7 @@ paste = "1.0" tempfile = "3.16" ruzstd = "0" filetime = "0.2" +uuid = { version = "1", features = ["v4"] } #[cfg(target_os = "macos")] libc = "0" #[cfg(target_os = "windows")] diff --git a/src/processing/parser/hls.rs b/src/processing/parser/hls.rs index 367e39f1e..b47e672b8 100644 --- a/src/processing/parser/hls.rs +++ b/src/processing/parser/hls.rs @@ -1,17 +1,17 @@ use crate::model::api_proxy::ProxyUserCredentials; use crate::model::config::TargetType; use crate::model::hls::HlsEntry; -use crate::repository::storage::hash_string_as_hex; use std::collections::HashMap; use std::str; use tokio::time::Instant; +use crate::utils::hash_utils::uuid_v4; use crate::utils::string_utils::replace_after_last_slash; pub const HLS_PREFIX: &str = "hls"; pub fn rewrite_hls(base_url: &str, content: &str, hls_url: &str, virtual_id: u32, user: &ProxyUserCredentials, target_type: &TargetType, input_name: &str) -> (HlsEntry, String) { - let token = hash_string_as_hex(hls_url); + let token = uuid_v4(); let username = &user.username; let password = &user.password; let mut chunk: u32 = 1; diff --git a/src/utils/hash_utils.rs b/src/utils/hash_utils.rs index 7c5904745..e8cb377b7 100644 --- a/src/utils/hash_utils.rs +++ b/src/utils/hash_utils.rs @@ -21,4 +21,9 @@ pub fn generate_playlist_uuid(key: &str, provider_id: &str, item_type: PlaylistI } } hash_string(url) -} \ No newline at end of file +} + +#[inline] +pub fn uuid_v4() -> String { + uuid::Uuid::new_v4().to_string().replace("-", "") +}