Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/commands/code_mappings/upload.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fs;
use std::path::Path;

use anyhow::{bail, Context as _, Result};
use clap::{Arg, ArgMatches, Command};
Expand Down Expand Up @@ -45,7 +46,13 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
let path = matches
.get_one::<String>("path")
.expect("path is a required argument");
let data = fs::read(path).with_context(|| format!("Failed to read mappings file '{path}'"))?;

// Validate and canonicalize the path to prevent path traversal attacks
let canonical_path = Path::new(path)
.canonicalize()
.with_context(|| format!("Failed to resolve path '{path}'. Ensure the file exists and is accessible."))?;

let data = fs::read(&canonical_path).with_context(|| format!("Failed to read mappings file '{}'", canonical_path.display()))?;

let mappings: Vec<BulkCodeMapping> =
serde_json::from_slice(&data).context("Failed to parse mappings JSON")?;
Expand Down