Skip to content

Commit 500fa07

Browse files
Add safety notes about docs fields in soroban-spec-rust (#1650)
### What Add and update comments in soroban-spec-rust explaining why the "docs" fields from spec entries are intentionally not output as rustdocs in generated Rust code. ### Why Rustdocs can contain Rust code that gets executed. Generated code may come from untrusted WASMs with untrusted spec docs, creating a code execution risk. We already have a comment about this in one of the files, but I wanted to put this important note at the top of all the files in this crate so it's present to anybody who's reading any of them.
1 parent 086daf6 commit 500fa07

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

soroban-spec-rust/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ use soroban_spec::read::{from_wasm, FromWasmError};
1414

1515
use types::{generate_enum, generate_error_enum, generate_event, generate_struct, generate_union};
1616

17+
// IMPORTANT: The "docs" fields of spec entries are not output in Rust token
18+
// streams as rustdocs, because rustdocs can contain Rust code, and that code
19+
// will be executed. Generated code may be generated from untrusted Wasm
20+
// containing untrusted spec docs.
21+
1722
#[derive(thiserror::Error, Debug)]
1823
pub enum GenerateFromFileError {
1924
#[error("reading file: {0}")]

soroban-spec-rust/src/trait.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ use stellar_xdr::ScSpecFunctionV0;
55

66
use super::types::generate_type_ident;
77

8+
// IMPORTANT: The "docs" fields of spec entries are not output in Rust token
9+
// streams as rustdocs, because rustdocs can contain Rust code, and that code
10+
// will be executed. Generated code may be generated from untrusted Wasm
11+
// containing untrusted spec docs.
12+
813
/// Constructs a token stream containing a single trait that has a function for
914
/// every function spec.
1015
pub fn generate_trait(name: &str, specs: &[&ScSpecFunctionV0]) -> TokenStream {

soroban-spec-rust/src/types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use stellar_xdr::{
88
};
99

1010
// IMPORTANT: The "docs" fields of spec entries are not output in Rust token
11-
// streams as rustdocs, because rustdocs are evaluated and execute code by
12-
// default in Rust projects.
11+
// streams as rustdocs, because rustdocs can contain Rust code, and that code
12+
// will be executed. Generated code may be generated from untrusted Wasm
13+
// containing untrusted spec docs.
1314

1415
// TODO: Replace the unwrap()s in this code with returning Result.
1516
// TODO: Create Idents in a way that we can get a Result back and return it too

0 commit comments

Comments
 (0)