Skip to content

[Security] Native SSH hardening: zeroize secrets, SafeHandle, FFI abuse tests #121

Description

@benyblack

Area: src/NovaTerminal.App/native/rusty_ssh/, src/NovaTerminal.Platform/Ssh/Native/NativeSshInterop.cs

Summary

Hardening items for the native SSH stack. (Note: host-key verification was reviewed and is correctly implemented — TOFU with pinning via NativeKnownHostsStore, mismatch refusal in SshInteractionService.cs:141-163.)

  1. No secret zeroization. zeroize is not in Cargo.toml; passwords/passphrases live in plain String/Vec<u8> (Rust) and GC-managed string (C#). Crash dumps/swap retain credentials. Add zeroize on the Rust side; minimize string retention on the C# side.
  2. Raw IntPtr handles in NativeSshInterop.cs (no SafeHandle): an exception between allocation and storage leaks the native session; close/poll races mirror [Security] PTY FFI: use-after-free window between pty_close and concurrent calls #118. Wrap session handles in SafeHandle subclasses.
  3. Audit error-string ownership across FFI — confirm every Rust-allocated error payload is freed when C# abandons a session mid-error (add a debug allocation counter).
  4. ffi_contract.rs is thin (41 LOC) for a 13-export surface. Add abuse tests: call-after-close, double-close, concurrent poll+close, malformed/oversized JSON payloads. Confirm cargo test runs in CI.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions