Skip to content

Commit

Permalink
Merge pull request #518 from Hou-Xiaoxuan/docker_test_image
Browse files Browse the repository at this point in the history
chore: Enhance security in base_dir replacement
  • Loading branch information
genedna authored Aug 17, 2024
2 parents 06731f6 + 3c05829 commit bba12f0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,20 @@ impl Default for Config {
std::env::var("MEGA_BASE_DIR").unwrap_or_else(|_| "/tmp/.mega".to_string()),
);
std::fs::create_dir_all(&base_dir).unwrap();

// use mega/config.toml because mega use sqlite as default db
let default_config = include_str!("../../mega/config.toml");
let default_config = default_config.replace("/tmp/.mega", base_dir.to_str().unwrap());
let default_config = default_config
.lines()
.map(|line| {
if line.starts_with("base_dir ") {
format!("base_dir = \"{}\"", base_dir.to_str().unwrap())
} else {
line.to_string()
}
})
.collect::<Vec<String>>()
.join("\n");

let config_path = base_dir.join("config.toml");
std::fs::write(&config_path, default_config).unwrap();
Expand Down

1 comment on commit bba12f0

@vercel
Copy link

@vercel vercel bot commented on bba12f0 Aug 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mega – ./

mega-git-main-gitmono.vercel.app
mega-gitmono.vercel.app
www.gitmega.dev
gitmega.dev

Please sign in to comment.