feat: make content security policy configurable

This commit is contained in:
knylbyte
2025-08-18 13:46:23 +02:00
parent 0168953351
commit e2c6aff5dc
8 changed files with 142 additions and 27 deletions
+41 -9
View File
@@ -1,13 +1,34 @@
use crate::error::{TuliproxError, TuliproxErrorKind};
use crate::model::WebAuthConfigDto;
use crate::utils::{default_as_true};
use crate::utils::default_as_true;
const RESERVED_PATHS: &[&str] = &[
"live", "movie", "series", "m3u-stream", "healthcheck", "status",
"player_api.php", "panel_api.php", "xtream", "timeshift", "timeshift.php", "streaming",
"get.php", "apiget", "m3u", "resource"
"live",
"movie",
"series",
"m3u-stream",
"healthcheck",
"status",
"player_api.php",
"panel_api.php",
"xtream",
"timeshift",
"timeshift.php",
"streaming",
"get.php",
"apiget",
"m3u",
"resource",
];
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Default, PartialEq)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub struct ContentSecurityPoliciesConfigDto {
#[serde(default)]
pub enabled: bool,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub custom_attributes: Vec<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Default, PartialEq)]
#[serde(deny_unknown_fields)]
@@ -16,8 +37,12 @@ pub struct WebUiConfigDto {
pub enabled: bool,
#[serde(default = "default_as_true")]
pub user_ui_enabled: bool,
#[serde(default)]
pub content_security_policy: bool,
#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "content-security-policies"
)]
pub content_security_policies: Option<ContentSecurityPoliciesConfigDto>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -37,13 +62,20 @@ impl WebUiConfigDto {
if web_path.is_empty() {
self.path = None;
} else {
let web_path = web_path.trim().trim_start_matches('/').trim_end_matches('/').to_string();
let web_path = web_path
.trim()
.trim_start_matches('/')
.trim_end_matches('/')
.to_string();
if RESERVED_PATHS.contains(&web_path.to_lowercase().as_str()) {
return Err(TuliproxError::new(TuliproxErrorKind::Info, format!("web ui path is a reserved path. Do not use {RESERVED_PATHS:?}")));
return Err(TuliproxError::new(
TuliproxErrorKind::Info,
format!("web ui path is a reserved path. Do not use {RESERVED_PATHS:?}"),
));
}
self.path = Some(web_path);
}
}
Ok(())
}
}
}