mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-14 21:20:48 +08:00
fix(profile): validate profile file names
This commit is contained in:
@@ -17,6 +17,7 @@ use serde_yaml_ng::Mapping;
|
||||
use smartstring::alias::String;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
path::{Component, Path},
|
||||
sync::{
|
||||
LazyLock,
|
||||
atomic::{AtomicU64, Ordering},
|
||||
@@ -227,6 +228,10 @@ impl IProfiles {
|
||||
|
||||
/// update the item value
|
||||
pub async fn patch_item(&mut self, uid: &String, item: &PrfItem) -> Result<()> {
|
||||
if let Some(file) = &item.file {
|
||||
Self::validate_profile_file(file)?;
|
||||
}
|
||||
|
||||
let mut items = self.items.take().unwrap_or_default();
|
||||
|
||||
for each in items.iter_mut() {
|
||||
@@ -250,6 +255,22 @@ impl IProfiles {
|
||||
bail!("failed to find the profile item \"uid:{uid}\"")
|
||||
}
|
||||
|
||||
fn validate_profile_file(file: &str) -> Result<()> {
|
||||
let mut components = Path::new(file).components();
|
||||
if file.is_empty()
|
||||
|| file.contains('/')
|
||||
|| file.contains('\\')
|
||||
|| !matches!(
|
||||
(components.next(), components.next()),
|
||||
(Some(Component::Normal(_)), None)
|
||||
)
|
||||
{
|
||||
bail!("profile file must be a single filename");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// be used to update the remote item
|
||||
/// only patch `updated` `extra` `file_data`
|
||||
pub async fn update_item(&mut self, uid: &String, item: &mut PrfItem) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user