Skip to content

Commit

Permalink
feat(sozo-walnut): remove sensitive data from dojo configuration file (
Browse files Browse the repository at this point in the history
…#2978)

* Added message to prevent user from exspose their private key during verification

* Verification propmt message lint fix

* Remove env section from dojo_*.toml before upload it
  • Loading branch information
marijamijailovic authored Feb 5, 2025
1 parent d875ec8 commit 870087b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions crates/sozo/walnut/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ version.workspace = true

[dependencies]
anyhow.workspace = true
clap.workspace = true
console.workspace = true
dojo-utils.workspace = true
reqwest.workspace = true
scarb.workspace = true
scarb-ui.workspace = true
serde.workspace = true
serde_json.workspace = true
starknet.workspace = true
thiserror.workspace = true
toml.workspace = true
url.workspace = true
urlencoding = "2.1.3"
walkdir.workspace = true
dojo-utils.workspace = true
clap.workspace = true

[dev-dependencies]
starknet.workspace = true
3 changes: 3 additions & 0 deletions crates/sozo/walnut/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pub enum Error {
#[error("Invalid file name")]
InvalidFileName,

#[error("Failed to serialize toml: {0}")]
TomlSerializationError(#[from] toml::ser::Error),

#[error("Namespace prefix not found in file name")]
NamespacePrefixNotFound,

Expand Down
40 changes: 35 additions & 5 deletions crates/sozo/walnut/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,41 @@ fn collect_source_code(root_dir: &Path) -> Result<Value, Error> {
// Safe to unwrap here because we're iterating over files within root_dir,
// so path will always have root_dir as a prefix
let relative_path = path.strip_prefix(root_dir).unwrap();
let file_content = std::fs::read_to_string(path)?;
file_data.insert(
relative_path.to_string_lossy().into_owned(),
serde_json::Value::String(file_content),
);
let mut file_content = std::fs::read_to_string(path)?;

// Check if the file is a TOML file and its name starts with "dojo_"
if extension == "toml"
&& path
.file_stem()
.and_then(OsStr::to_str)
.map_or(false, |name| name.starts_with("dojo_"))
{
if let Ok(mut toml_data) = file_content.parse::<toml::Value>() {
if let Some(table) = toml_data.as_table_mut() {
// Remove the "env" table if it exists
table.remove("env");

// Serialize the modified TOML data back into a string, and
// handle any serialization error
file_content = toml::to_string(&toml_data)
.map_err(Error::TomlSerializationError)?;

// Insert the updated content into file_data, using the relative
// path as the key
file_data.insert(
relative_path.to_string_lossy().into_owned(),
Value::String(file_content),
);
}
}
} else {
// If the file is not a "dojo_" prefixed TOML file, just insert the
// original content
file_data.insert(
relative_path.to_string_lossy().into_owned(),
Value::String(file_content),
);
}
}
}
}
Expand Down

0 comments on commit 870087b

Please sign in to comment.