Steller-Base/soroban-guard
About
A fast, dependency-free static security linter for Soroban smart contracts on Stellar.
Security & PrivacyMeasured star growth
- in 24h
- Collecting history
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Originalsoroban-guard
soroban-guard is a fast, dependency-free static security linter for Soroban smart contracts on the Stellar network. Point it at a contract crate and it reports common, dangerous patterns — before they reach the chain.
It is written in Rust, has zero third-party dependencies, builds in seconds, and produces both human-readable and JSON output for CI pipelines.
Why
Soroban contracts handle real value. A missing authorization check, an unchecked
integer overflow, or a storage entry that silently expires can drain a contract
or lock its users out. soroban-guard gives maintainers and auditors a fast
first line of defense that runs on every commit.
Install
cargo install --path .
Or build and run without installing:
cargo run -- <PATH>...
Usage
soroban-guard [scan] <PATH>... [OPTIONS]
soroban-guard --list-rules
ARGS:
<PATH>... Files or directories to scan (directories are searched recursively)
OPTIONS:
--format <fmt> Output format: text, json, or sarif (default: text)
--fail-on <level> Exit non-zero when a finding at or above this level is present
(low, medium, high, none; default: high)
--disable <IDs> Comma-separated rule identifiers to skip, e.g. SG001,SG005
--exclude <path> Skip any path containing this substring (repeatable)
--baseline <file> Suppress findings listed in a baseline file
--write-baseline <f> Write current findings to a baseline file and exit 0
--max-file-bytes <n> Skip files larger than n bytes (default: 2097152 = 2 MiB)
--strict Fail (exit 2) on unreadable, oversized, or non-UTF-8 files
--list-rules Print all rules with their default severity and exit
-h, --help Print help
-V, --version Print version
Examples
# Scan an entire contracts directory.
soroban-guard contracts/
# Machine-readable output for CI, failing on any medium+ finding.
soroban-guard contracts/ --format json --fail-on medium
# Ignore the unchecked-arithmetic rule for a single run.
soroban-guard contracts/ --disable SG002
# Skip vendored code and tests.
soroban-guard contracts/ --exclude target --exclude tests
# List every available rule.
soroban-guard --list-rules
# Adopt the tool on a legacy codebase: snapshot current findings, then only
# fail on new ones.
soroban-guard contracts/ --write-baseline .soroban-guard-baseline.txt
soroban-guard contracts/ --baseline .soroban-guard-baseline.txt
Example text output:
contracts/token.rs:14:9 HIGH [SG001] `mint` writes to contract storage but no require_auth call was found in its body
| env.storage().instance().set(&"supply", &total);
contracts/token.rs:19:23 MEDIUM [SG003] `.unwrap` can panic; validate input and return a Result instead
2 finding(s): 1 high, 1 medium, 0 low
GitHub Action
- uses: Steller-Base/soroban-guard@main
with:
path: contracts/
fail-on: high
The composite action installs the linter and scans the given path. Extra CLI
flags can be passed through args.
Docker
docker build -t soroban-guard .
docker run --rm -v "$PWD:/work" -w /work soroban-guard contracts/ --fail-on high
SARIF / GitHub code scanning
--format sarif emits SARIF 2.1.0, which GitHub can ingest into the Security
tab:
- name: soroban-guard
run: cargo run --quiet -- contracts/ --format sarif --fail-on none > soroban-guard.sarif
- uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: soroban-guard.sarif
Baselines
To roll the linter out on an existing codebase without drowning in legacy findings, write a baseline once and commit it:
soroban-guard contracts/ --write-baseline .soroban-guard-baseline.txt
soroban-guard contracts/ --baseline .soroban-guard-baseline.txt --fail-on high
Baseline entries are tab-separated rule_id, path, and line number. When code
moves, previously suppressed findings surface again, as intended.
pre-commit
The repository ships a .pre-commit-config.yaml with
cargo fmt, cargo clippy, cargo test, and soroban-guard hooks.
Examples
See examples/clean for a contract that passes with no
findings and examples/vulnerable for one that
triggers several rules.
Rules
| ID | Severity | What it catches |
|---|---|---|
| SG001 | High | A public contract function writes to storage without require_auth |
| SG002 | Medium | Bare + - * arithmetic that is not overflow-checked |
| SG003 | Medium | unwrap/expect/panic!/assert! that can be triggered by input |
| SG004 | High (secrets) / Medium | Hardcoded Stellar secret seeds, public keys, or hex key material |
| SG005 | Medium | Contract storage is written but no extend_ttl call is present |
| SG006 | High | unsafe code inside a contract |
| SG007 | Low | todo! / unimplemented! left in shipping code |
Malware / suspicious intent
These rules target deliberately malicious or backdoored contracts rather than honest mistakes.
| ID | Severity | What it catches |
|---|---|---|
| SG101 | High | Contract can replace its own WASM (update_current_contract_wasm) |
| SG102 | High | Payment/transfer line with a hardcoded Stellar recipient address |
| SG103 | Medium | Obfuscation primitives (transmute, include_bytes!, raw pointers, …) |
| SG104 | High | Host I/O in contract code (std::process, sockets, env, …) |
| SG105 | Medium | Non-ASCII characters in code (homoglyph/obfuscation) |
| SG106 | Medium | Long encoded (hex/base64) string literal that may hide a payload |
See docs/RULES.md for details and examples of each rule.
Library use
The linter is also a library:
use soroban_guard::{scan_source, Config};
let source = std::fs::read_to_string("contracts/lib.rs").unwrap();
let findings = scan_source("contracts/lib.rs", &source, &Config::default());
for finding in findings {
println!("{}:{} {}", finding.line, finding.column, finding.message);
}
How it works
src/scanner.rs keeps two views of each file: the original source and a
masked copy in which comments and string/char literals are blanked out while
preserving byte offsets. Rules then match against the masked view to avoid false
positives, while snippets and hardcoded-key detection read the original. This
keeps the tool dependency-free and very fast, with no compiler or syn needed.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md and
check the open issues labelled good first issue. All participants must follow
our CODE_OF_CONDUCT.md.
Security
Please do not open a public issue for security problems in this tool. See
SECURITY.md for the disclosure policy.
The scanner is built with #![forbid(unsafe_code)], has zero third-party
dependencies, never executes the code it scans, does not follow symlinks while
walking directories, skips files above a configurable size limit, and sanitizes
control characters in terminal output to prevent escape-sequence injection. An
author-side review and threat model live in
docs/security-review.md; it is not a substitute for
an independent audit.
License
MIT — see LICENSE.
Explore related projects
Loading…