Skip to content

Add Rust version of AntiSSRF library with full CI and documentation#29

Open
finn79426 wants to merge 8 commits into
microsoft:mainfrom
finn79426:feature/rust
Open

Add Rust version of AntiSSRF library with full CI and documentation#29
finn79426 wants to merge 8 commits into
microsoft:mainfrom
finn79426:feature/rust

Conversation

@finn79426

Copy link
Copy Markdown

This PR ports the Microsoft AntiSSRF library to Rust, providing SSRF protection for the Rust ecosystem.
The implementation mirrors the existing .NET and Node.js libraries in API design and security guarantees.

Changes

Core library (rust/):

  • AntiSSRFPolicy — configurable allow/deny lists, IP restriction policies, header injection prevention, HTTP/HTTPS agent integration
  • URIValidator — DNS resolution and IP range validation with thread-safe caching
  • CIDR primitives (IpAddressCidr) with IPv4/IPv6 support
  • RFC-compliant IP address ranges (RFC 1918, 4193, 5735, 6598, etc.)
  • Well-known Microsoft and Azure domain constants

Testing (rust/tests/):

  • Integration bypass tests: DNS rebinding, URL encoding edge cases, protocol smuggling
  • SSRF payload tests: IP encoding variants, redirect chains, IPv6 mappings, cloud metadata endpoints
  • All 181 tests passing across lib and integration suites

CI/CD (.github/workflows/):

  • New test-rust.yml: cargo build, test, clippy, format on ubuntu/macos/windows
  • Updated update-domains.yml and update-ip-ranges.yml to generate Rust source files
  • Updated codeql.yml and check-license-headers.yml for Rust

Build system (scripts/):

  • build-domains-rust.sh and build-ip-ranges-rust.sh for regenerating data constants from upstream sources

Documentation (docs/):

  • docs/rust-api/index.md — Rust API reference
  • Updated docs/index.md, docs/getting-started.md, README.md with Rust installation and usage examples

Verification

  • cargo build — clean
  • cargo test --lib — 106 passed
  • cargo test --all-features — 181 passed
  • cargo clippy — no issues
  • cargo fmt --check — clean

Standalone Reference

The standalone Rust implementation is maintained at:
https://github.com/finn79426/AntiSSRF-rs

This port adapts the standalone crate into the monorepo structure, aligning with the existing .NET and Node.js build and release pipelines.

finn79426 added 8 commits June 4, 2026 17:14
Set up Rust project structure with cargo init.
Add .gitignore for Rust build artifacts.
Define AntiSSrfError enum for validation, DNS, and I/O failures.
Implement IpAddressCidr with parsing, containment checks, and
IPv4/IPv6 support using the ipnetwork crate.
Add comprehensive CIDR constants for RFC 1918, 4193, 5735, 6598,
and other special-purpose address ranges.
Define well-known Microsoft and Azure domains for SSRF detection.
Implement core SSRF protection:
- AntiSSRFPolicy: configurable allow/deny lists, IP restrictions,
  header injection prevention, HTTP/HTTPS agent integration.
- URIValidator: DNS resolution and IP range validation with
  multi-threaded safety and cache support.
- Network layer: IP address classification, range checking,
  DNS resolution with timeout and retry.
Add comprehensive test coverage:
- Integration bypass tests for DNS rebinding, URL parsing edge
  cases, and protocol smuggling attempts.
- SSRF payload tests covering IP encoding variants, redirect
  chains, IPv6 mappings, and cloud metadata endpoints.
Add shell scripts to regenerate domain constants and IP range
constants from upstream data sources, mirroring the existing
Node.js and .NET build pipeline.
Add dedicated test-rust workflow for cargo build, test, clippy,
and format checking on ubuntu, macos, and windows.
Update update-domains and update-ip-ranges to generate Rust
source files alongside existing Node.js and .NET outputs.
Extend codeql analysis and license header checks to cover
Rust source files.
Add Rust API documentation covering AntiSSRFPolicy, URIValidator,
error types, CIDR primitives, and data module reference.
Update getting-started guide with Rust installation instructions
and code examples.
Update documentation index pages and README with Rust badge
and cross-references.
@finn79426

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant