Skip to content

Commit c925646

Browse files
mootz12fnando
andauthored
Validate auth entries before signing (#2530)
### What The CLI currently relies on the RPC to check that no non-root auths are included in simulation results. This PR adds an explicit, per-entry validation step inside `sign_soroban_authorizations` that classifies every `Address`-credential auth entry against the transaction's host function before signing. Entries that don't match the host function exactly require approval. This approval can be bypassed with a `--force` flag. Example output: ``` $ stellar contract invoke --source alice --id CA3WF5KPVE2TXQQSOEQPVD3J6GIZ7G74UA2H7BNQMHBQPOON6XV4PHT4 -- diff_auth_sub_auth --addr bob --val "Test" --subcall CAXDPLG2XWFA3LI3SUDG7AIQ7MF7ZJMFBEQYRGTZIGLT7OLZ243IU3FE ℹ️ Simulating transaction… ⚠️ Authorization entry does not match the current contract call, and needs approval: Auth Entry: Signer: GCFEAQ5A5BOO4NYTCDN63TF2UX2DS3T3KLNZDHPDPC3IVGCPR37RSRCC Invocation: Contract: CA3WF5KPVE2TXQQSOEQPVD3J6GIZ7G74UA2H7BNQMHBQPOON6XV4PHT4 Fn: diff_auth_sub_auth Args: "1" "2" Sub-invocation #0: Contract: CAXDPLG2XWFA3LI3SUDG7AIQ7MF7ZJMFBEQYRGTZIGLT7OLZ243IU3FE Fn: do_auth Args: "GCFEAQ5A5BOO4NYTCDN63TF2UX2DS3T3KLNZDHPDPC3IVGCPR37RSRCC" Test ⚠️ Sign this authorization entry? (y/N) y ℹ️ Signing transaction: ebf3db4651a6cd77ed8a9f2782938eaedd1603e4942a9ceab99b467dd8c04f40 🌎 Sending transaction… ✅ Transaction submitted successfully! "Test" ``` If the CLI is invoked in a non-interactive location and the force flag is not preset, it will fail: ``` $ echo | stellar contract invoke --source alice --id CA3WF5KPVE2TXQQSOEQPVD3J6GIZ7G74UA2H7BNQMHBQPOON6XV4PHT4 -- diff_auth_sub_auth --addr bob --val "Test" --subcall CAXDPLG2XWFA3LI3SUDG7AIQ7MF7ZJMFBEQYRGTZIGLT7OLZ243IU3FE ℹ️ Simulating transaction… ⚠️ Authorization entry does not match the current contract call, and needs approval: Auth Entry: Signer: GCFEAQ5A5BOO4NYTCDN63TF2UX2DS3T3KLNZDHPDPC3IVGCPR37RSRCC Invocation: Contract: CA3WF5KPVE2TXQQSOEQPVD3J6GIZ7G74UA2H7BNQMHBQPOON6XV4PHT4 Fn: diff_auth_sub_auth Args: "1" "2" Sub-invocation #0: Contract: CAXDPLG2XWFA3LI3SUDG7AIQ7MF7ZJMFBEQYRGTZIGLT7OLZ243IU3FE Fn: do_auth Args: "GCFEAQ5A5BOO4NYTCDN63TF2UX2DS3T3KLNZDHPDPC3IVGCPR37RSRCC" Test ❌ error: An authorization entry requires confirmation, but stdin is not interactive. Rerun with --force to sign anyway. ``` ### Why The CLI eagerly signs authorization entries returned from the user-specified RPC. If an unsafe auth entry is included, the user might unexpectedly sign for something they did not intend. This check ensures everything the CLI signs automatically is bound to the exact host function invocation in the transaction. Close stellar/stellar-cli-internal#50 ### Known limitations #### `require_auth_for_args` for non-source accounts The check flags contracts that use `require_auth_for_args(custom_args)` at the root for non-source accounts. The auth tree's root carries `custom_args`, not the host function's args, so the strict-match check fails even though the auth is genuinely rooted at the operation. A tampered auth entry with the same custom args at root could otherwise be signed and replayed. Source-account auth via `SorobanCredentials::SourceAccount` is unaffected. --------- Co-authored-by: Nando Vieira <me@fnando.com>
1 parent 2f81472 commit c925646

16 files changed

Lines changed: 1386 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FULL_HELP_DOCS.md

Lines changed: 54 additions & 0 deletions
Large diffs are not rendered by default.

cmd/crates/soroban-test/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ impl TestEnv {
278278
hd_path: None,
279279
sign_with_lab: false,
280280
sign_with_ledger: false,
281+
auto_sign: false,
281282
},
282283
fee: None,
283284
inclusion_fee: None,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "test_auth"
3+
version = "25.2.0"
4+
authors = ["Stellar Development Foundation <info@stellar.org>"]
5+
license = "Apache-2.0"
6+
edition = "2021"
7+
publish = false
8+
9+
[lib]
10+
crate-type = ["cdylib", "rlib"]
11+
doctest = false
12+
13+
[dependencies]
14+
soroban-sdk = { workspace = true }
15+
16+
[dev-dependencies]
17+
soroban-sdk = { workspace = true, features = ["testutils"]}

0 commit comments

Comments
 (0)