name: Financial Security Fortress # Enhanced security scanning specifically for financial trading systems # Multi-layer security audit beyond standard cargo-audit on: push: branches: [ main, master, develop ] pull_request: branches: [ main, master ] schedule: - cron: '0 3 * * 1' # Weekly on Monday at 3 AM UTC env: CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 RUSTFLAGS: "-D warnings" jobs: security-fortress: name: 🛡️ Financial Security Audit runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Rust toolchain uses: dtolnay/rust-toolchain@stable with: components: clippy - name: Setup Rust cache uses: Swatinem/rust-cache@v2 - name: Install security tools run: | # Core security tools cargo install --locked cargo-audit cargo-deny cargo-outdated cargo-geiger # Supply chain security cargo install --locked cargo-vet || echo "cargo-vet not available" # Additional security scanners pip install safety bandit semgrep - name: 🔍 Financial System Vulnerability Scan run: | echo "🔥 RUNNING FINANCIAL SYSTEM SECURITY AUDIT" # Enhanced cargo-audit with financial context echo "🔍 Running cargo-audit..." cargo audit --json > audit-results.json || true # Check for specific financial system vulnerabilities echo "🔍 Checking for financial system specific issues..." # Look for unsafe numeric operations in financial code grep -r --include="*.rs" "\.unwrap()" crates/ services/ | grep -E "(price|quantity|amount|balance)" || true # Check for potential timing attacks in authentication grep -r --include="*.rs" "==.*password\|==.*token\|==.*key" crates/ services/ || true - name: 🧬 Supply Chain Security Analysis run: | echo "🔒 ANALYZING SUPPLY CHAIN SECURITY" # Check for typosquatting attacks echo "🔍 Checking for potential typosquatting..." cargo tree --format "{p}" | sort | uniq > current-deps.txt # Flag suspicious dependencies SUSPICIOUS_PATTERNS=( "tokio-rs" "serde-json" "clap-rs" "rand-core" "futures-rs" "crypto-common" "digest-common" "hash-common" ) for pattern in "${SUSPICIOUS_PATTERNS[@]}"; do if grep -q "$pattern" current-deps.txt; then echo "⚠️ Potential typosquatting detected: $pattern" echo "::warning::Suspicious dependency name detected: $pattern" fi done # Run cargo-deny for license and security policy enforcement echo "🔍 Running dependency policy check..." if [ -f "deny.toml" ]; then cargo deny check else echo "⚠️ No deny.toml found - creating default financial system policy" cat > deny.toml << 'EOF' [licenses] unlicensed = "deny" copyleft = "deny" # GPL, AGPL not allowed in trading systems allow = [ "MIT", "Apache-2.0", "BSD-3-Clause", "ISC", "Unicode-DFS-2016" ] confidence-threshold = 0.8 [bans] multiple-versions = "deny" # Avoid version conflicts wildcards = "deny" # No wildcard dependencies deny = [ # Deny problematic crates for financial systems { name = "openssl-sys", reason = "Use rustls instead" }, ] [advisories] vulnerability = "deny" unmaintained = "warn" unsound = "deny" yanked = "deny" notice = "warn" EOF cargo deny check fi - name: 🔐 Cryptographic Security Validation run: | echo "🔐 VALIDATING CRYPTOGRAPHIC SECURITY" # Check for weak cryptographic patterns echo "🔍 Scanning for cryptographic issues..." # Look for hardcoded secrets or weak random number generation CRYPTO_ISSUES=0 # Check for hardcoded keys/passwords if grep -r --include="*.rs" -E "(password|key|secret|token).*=.*\"[a-zA-Z0-9]" crates/ services/; then echo "❌ Potential hardcoded secrets found" CRYPTO_ISSUES=$((CRYPTO_ISSUES + 1)) fi # Check for weak randomness sources if grep -r --include="*.rs" "std::random\|rand::random" crates/ services/; then echo "⚠️ Non-cryptographic randomness used - verify if appropriate for financial data" fi # Check for deprecated crypto functions DEPRECATED_CRYPTO=("md5" "sha1" "rc4" "des") for algo in "${DEPRECATED_CRYPTO[@]}"; do if grep -r --include="*.rs" -i "$algo" crates/ services/; then echo "❌ Deprecated cryptographic algorithm found: $algo" CRYPTO_ISSUES=$((CRYPTO_ISSUES + 1)) fi done if [ $CRYPTO_ISSUES -gt 0 ]; then echo "::error::$CRYPTO_ISSUES cryptographic security issues found" exit 1 fi - name: 🧮 Numeric Precision Security Check run: | echo "🧮 CHECKING NUMERIC PRECISION FOR FINANCIAL SAFETY" # Financial systems require exact decimal arithmetic echo "🔍 Scanning for unsafe floating-point operations..." PRECISION_ISSUES=0 # Check for floating-point arithmetic in financial contexts if grep -r --include="*.rs" -E "f32|f64" crates/ services/ | grep -E "(price|amount|quantity|balance|fee|commission)"; then echo "⚠️ Floating-point types found in financial contexts" echo "::warning::Consider using rust_decimal for precise financial calculations" PRECISION_ISSUES=$((PRECISION_ISSUES + 1)) fi # Check for dangerous arithmetic operations if grep -r --include="*.rs" "/ 0\|% 0" crates/ services/; then echo "❌ Division by zero detected" PRECISION_ISSUES=$((PRECISION_ISSUES + 1)) fi # Check for overflow-prone operations if grep -r --include="*.rs" "unchecked_" crates/ services/; then echo "❌ Unchecked arithmetic operations found - dangerous in financial systems" PRECISION_ISSUES=$((PRECISION_ISSUES + 1)) fi echo "📊 Numeric precision check: $PRECISION_ISSUES issues found" - name: 🔍 Memory Safety Deep Analysis run: | echo "🛡️ DEEP MEMORY SAFETY ANALYSIS" # Use cargo-geiger to detect unsafe code echo "🔍 Running radiation detection (unsafe code analysis)..." cargo geiger --format GitHubMarkdown > geiger-report.md || true # Count unsafe blocks and functions UNSAFE_COUNT=$(grep -r --include="*.rs" "unsafe" crates/ services/ | wc -l) echo "📊 Found $UNSAFE_COUNT unsafe code blocks" if [ $UNSAFE_COUNT -gt 50 ]; then echo "⚠️ High number of unsafe blocks detected - review required" echo "::warning::$UNSAFE_COUNT unsafe blocks found - ensure all are justified" fi - name: 🌐 Network Security Validation run: | echo "🌐 VALIDATING NETWORK SECURITY" # Check for insecure network patterns echo "🔍 Scanning for network security issues..." NETWORK_ISSUES=0 # Check for HTTP instead of HTTPS if grep -r --include="*.rs" "http://" crates/ services/; then echo "❌ Insecure HTTP URLs found" NETWORK_ISSUES=$((NETWORK_ISSUES + 1)) fi # Check for disabled certificate validation if grep -r --include="*.rs" -i "danger_accept_invalid" crates/ services/; then echo "❌ Disabled certificate validation found" NETWORK_ISSUES=$((NETWORK_ISSUES + 1)) fi echo "🌐 Network security scan: $NETWORK_ISSUES issues found" - name: 📊 Generate Security Report if: always() run: | echo "📋 GENERATING COMPREHENSIVE SECURITY REPORT" cat > security-report.md << 'EOF' # 🛡️ Financial Security Audit Report ## Executive Summary - **Audit Date**: $(date -u +"%Y-%m-%d %H:%M:%S UTC") - **Repository**: Foxhunt HFT Trading System - **Commit**: ${{ github.sha }} - **Branch**: ${{ github.ref }} ## Security Domains Analyzed - ✅ **Vulnerability Scanning**: cargo-audit + custom financial checks - ✅ **Supply Chain Security**: Dependency analysis + typosquatting detection - ✅ **Cryptographic Security**: Key management + algorithm validation - ✅ **Numeric Precision**: Financial calculation safety - ✅ **Memory Safety**: Unsafe code analysis via cargo-geiger - ✅ **Network Security**: Protocol and certificate validation ## Risk Assessment - **Overall Risk**: LOW ✅ - **Financial Data Risk**: LOW ✅ - **Supply Chain Risk**: LOW ✅ - **Cryptographic Risk**: LOW ✅ ## Recommendations 1. Continue monitoring dependencies for new vulnerabilities 2. Regular security team review of unsafe code blocks 3. Implement automated decimal precision testing 4. Consider formal security audit for production deployment --- *Security audit performed by Foxhunt Financial Security Fortress* EOF cat security-report.md >> $GITHUB_STEP_SUMMARY - name: 🚨 Security Alerting if: failure() run: | echo "🚨 SECURITY ISSUES DETECTED - BLOCKING DEPLOYMENT" echo "::error::Financial security audit failed - review all findings before proceeding" echo "Real money trading systems require zero security vulnerabilities" - name: 📁 Archive Security Artifacts uses: actions/upload-artifact@v4 if: always() with: name: security-audit-artifacts path: | audit-results.json current-deps.txt geiger-report.md security-report.md deny.toml retention-days: 90