SARIF Rust Library
A comprehensive Rust library for parsing, generating, and manipulating SARIF (Static Analysis Results Interchange Format) v2.1.0 files.
SARIF is a standard JSON format for the output of static analysis tools. This library provides complete support for the SARIF v2.1.0 specification with type-safe parsing, generation, validation, and manipulation capabilities.
Features
- ✅ Complete SARIF v2.1.0 Support: Full specification compliance with all optional fields
- 🔒 Type-Safe API: Leverages Rust's type system for correctness and safety
- 🏗️ Builder Pattern: Ergonomic API for programmatic SARIF generation
- 🔍 Advanced Querying: Powerful filtering and search capabilities
- 🔄 Merge & Diff: Combine multiple SARIF files or compare them
- 📊 Multiple Formats: Export to CSV, HTML, GitHub Security Advisory format
- ⚡ High Performance: Streaming parser for large files with memory efficiency
- ✅ Comprehensive Validation: Multiple validation levels from minimal to pedantic
- 🔄 Schema Evolution: Automatic migration between SARIF versions
Quick Start
Add this to your Cargo.toml:
[]
= "0.2.0"
Basic Usage
use ;
// Parse existing SARIF file
let sarif: SarifLog = from_file?;
// Access results
for run in &sarif.runs
// Create new SARIF programmatically
let new_sarif = new
.with_schema
.build;
// Save to file
to_file?;
Advanced Usage
Querying and Filtering
use ;
let sarif = from_file?;
let index = from_sarif_log?;
// Query by rule ID
let security_issues = index.get_results_for_rule?;
// Complex filtering with query builder
let query = new
.with_rule_id_filter
.with_minimum_level
.with_file_pattern
.with_text_search
.build;
let results = query.execute?;
println!;
Merging Multiple SARIF Files
use ;
let baseline = from_file?;
let current = from_file?;
// Configure merge behavior
let config = default
.with_deduplication // Remove duplicate results
.with_consolidation // Merge runs from same tool
.with_include_added
.with_include_removed;
let merger = new;
let merged = merger.merge?;
to_file?;
Format Conversion
use ;
let sarif = from_file?;
let config = default
.with_include_full_paths
.with_max_message_length;
let converter = new;
// Convert to CSV
let csv_output = converter.to_csv?;
write?;
// Convert to HTML report
let html_output = converter.to_html?;
write?;
Documentation
- Specification Analysis: Deep dive into SARIF v2.1.0 specification
- Implementation Plan: Detailed technical implementation roadmap
- API Documentation: Complete API reference (when published)
SARIF Specification Compliance
This library implements the complete SARIF v2.1.0 specification including:
Core Objects
- SarifLog: Root container with version and runs
- Run: Analysis tool execution with results and metadata
- Result: Individual findings with locations and metadata
- Location: Physical and logical location information
- Tool: Tool and component information
- Artifact: File and content references
Advanced Features
- External Property Files: Large-scale analysis support
- Taxonomies: Rule categorization and classification
- Code Flows: Multi-step analysis paths
- Threading Flows: Multi-threaded analysis support
- Web Requests/Responses: Web application analysis
- Fixes: Automated fix suggestions
Performance Characteristics
| Operation | File Size | Performance Target |
|---|---|---|
| Parse | 1-10 MB | < 100ms |
| Validate | 1-10 MB | < 50ms |
| Serialize | 1-10 MB | < 50ms |
| Stream Parse | 100+ MB | < 500MB RAM |
Development Roadmap
Phase 1: Core Types (Week 1)
- Define SARIF object model
- Implement core enums and types
- Basic JSON serialization support
Phase 2: Validation (Week 2)
- Custom validation traits
- URI and cross-reference validation
- Comprehensive error types
Phase 3: Builders (Week 3)
- Fluent builder interfaces
- Type-safe construction
- Ergonomic API design
Phase 4: Advanced Features (Week 4)
- Streaming parser implementation
- Cross-reference indexing
- Memory optimization
Phase 5: Polish (Week 5)
- Comprehensive testing
- Documentation and examples
- Performance benchmarking
Contributing
Contributions are welcome! Please see our contribution guidelines for details on:
- Code style and formatting
- Testing requirements
- Documentation standards
- Pull request process
License
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
Related Projects
- SARIF Standard: Official SARIF specification and tools
- Microsoft SARIF SDK: .NET implementation
- sarif-python: Python SARIF library
Status: 🚧 Under Development - See Implementation Plan for current progress