mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-16 21:02:28 +02:00
feat: make content security policy configurable
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user