Threat model
SshSharp is an SSH client library. This page lists who and what it trusts, and what it does about the rest.
It is reviewed before each release; the last review covered everything up to 1.3.0. Up to 1.0.0 that included SFTP and its
adapters, proxies, remote dynamic and Unix-socket forwarding, destination-constrained agent keys, SSH signatures, sntrup761,
Kerberos (gssapi-with-mic), adding keys to the agent and Pageant, revoked host keys (KRLs), ping@openssh.com, channel idle
timeouts (ChannelTimeout), segmented SFTP downloads, keys held elsewhere (SshKeySigner), SFTP Preserve with permissions,
and the dependency injection package (SshSharp.Extensions.DependencyInjection). The 1.1.0 review added: Diffie-Hellman group
exchange, the in-process agent (SshAgent.FromKeys) and the forwarded agent's filter, jump hosts (JumpHosts, and their
credentials), custom proxies, SOCKS 5 authentication on the local SOCKS proxy, issuing certificates (SshCertificateBuilder),
the public KRL reader (SshKeyRevocationList), the built-in DNS canonicalizer, segmented SFTP uploads, recursive SFTP listings
and deletes, and local Unix-socket forwarding. Compression is not part of it; it is reviewed with its own change. The 1.2.0
review added: the .NET 11 target (the platform's X25519, and commands that inherit only their standard streams and get SIGTERM
first), encrypted traditional PEM and chacha20-poly1305 OpenSSH private keys, traces and metrics, SFTP's TimeTolerance,
IgnoreCase and SkipUnreadableDirectories, Match canonical and the second configuration pass, the cases in which
UpdateHostKeys leaves known_hosts alone, CASignatureAlgorithms, RequiredRsaSize for a host certificate's authority, the
plain-key fallback for an unusable host certificate, @revoked lines without a port, the untrusted connection after a changed
key under StrictHostKeyChecking no, cleaned server text, the owed-reply budget, agent channels under MaxForwardedConnections,
one host key announcement per connection, Preserve uploads that do not follow links, %C and %j, the 64 MiB window step,
StaggeredConnectDelay, and killing a command's process tree. The 1.3.0 review added: channels and global requests the
application opens (OpenChannelAsync, SendGlobalRequestAsync), how SCP writes remote paths on the server's command line
(SshScpOptions.PathQuoting), the per-connection limit on log entries a server can trigger, the 256-principal limit and option
order of certificates, and hard links through the SshSharp.IO.Abstractions adapter.
Trusted
- The application that uses the library, its options and callbacks (host key verifier, loggers,
Match execrunner, a custom proxy's connector,ConfigureSocket, which gets the TCP socket before it connects, andConfirmAddKeyToAgent). - Signers (
SshKeySigner,SshPrivateKey.FromSigner,FromRsa,FromECDsa): application code, or a key service it trusts, that signs for a key SshSharp never sees. Each request says what it is for (SshSignRequest.Purpose: logging in, an SSH signature with its namespace, a certificate the key issues as a CA, orOther: data of another form that a program on a server asked a forwarded in-process agent to sign), so a signer can refuse by policy. What it signs includes the session identifier and the user name, which matters to a signer that logs its requests. Every signature it returns is verified against the public key before use. - The local machine: the process, its memory, and files the application chooses to load (private keys,
ssh_config,known_hosts). Their contents are still parsed defensively; see below. - The .NET runtime and OS cryptography (AES, SHA-2, HMAC, RSA, ECDSA, ECDH, random numbers).
- The platform's Kerberos (SSPI on Windows, MIT or Heimdal GSS-API elsewhere) and its KDC, when
gssapi-with-micis turned on: the library passes tokens through and checks only the SSH framing. The server's tokens are parsed by the GSS-API library, not here. Mutual authentication is required, the MIC binds the exchange to the SSH session id, and the host key is still verified by the usual verifier, so a Kerberos service ticket never replaces host key checking. Delegating the ticket (DelegateCredentials) gives the server your Kerberos identity, so it is off by default.
Not trusted
The network and the server
A man in the middle can read, change, drop and inject bytes. The server itself may be malicious or compromised.
Host authentication: the server must prove possession of a host key, and the application's verifier decides whether to trust it. There is deliberately no accept-everything default. A re-exchange must prove the same key.
Public-key signatures for keys the server refuses: a key held in the process signs its first
publickeyrequest, without asking first whether the server accepts it (why), so a server that refuses the key still receives a signature from it. That gives the server nothing it could not have had otherwise: the public key is in the request either way, a malicious server could answer "accepted" to a query and get the same signature, and the signed data starts with this session's identifier (and, host-bound, names this server's host key), so the signature logs in nowhere else. Keys held by an agent or a signer, whose signature may need the user's confirmation, a touch or a remote call, are still offered first and sign only for a server that accepts them.Passwords and password changes: passwords go only to the server whose host key was verified, inside the encrypted transport. A server that answers with a password change request (RFC 4252 section 8) receives the old password again and the new one the application's
ChangePasswordreturns; without that handler nothing more is sent. A server cannot make the client loop: it gets at most 3 new passwords per password,PasswordProvideris asked at mostNumberOfPasswordPromptstimes per connection, and keyboard-interactive rounds and walks of the method order stay bounded as before. What the server says in a change request (SshPasswordChangeRequest.Prompt) is its own text, for the application to clean before showing.Downgrade and prefix attacks: only modern algorithms are offered (no SHA-1 KEX or MACs, no CBC, no
ssh-rsaSHA-1 signatures, RSA ≥ 2048 bits). Strict KEX (Terrapin, CVE-2023-48795) is negotiated whenever the server supports it. The application can narrow or reorder the algorithm lists (SshClientOptions.KexAlgorithms,HostKeyAlgorithms,Ciphers,Macs, or thessh_configdirectives), but only among the algorithms SshSharp implements, so no list brings a legacy one back, andFipsModestill applies on top. The one setting that lowers the bar is the smallest RSA host key (SshClientOptions.RequiredRsaSize,RequiredRSASizeinssh_config): an application may accept down to 1024 bits for an old device, assshallows, and never less. A value above 2048 also applies to the RSA authority that signed a host certificate, as in OpenSSH master, in its next release (409167b833); a lower one does not lower the 2048 bits every certificate's authority needs. The algorithms a host certificate's authority may have signed with (SshClientOptions.CASignatureAlgorithms,CASignatureAlgorithmsinssh_config) can likewise only be narrowed: SHA-1ssh-rsaandsk-*signatures stay refused whatever the list says.Malformed input: every parser treats its input as hostile, rejecting it with a protocol error, never with an unexpected exception (mutation-fuzzed in every test run). Peer public keys are validated: points on the curve, no small-order Ed25519 keys, an RSA exponent ≥ 3, and an RSA modulus of at most 16384 bits (OpenSSH's limit), so a server or a file cannot make each verification cost what a 64000-bit key would. Public keys the application reads itself (
SshPublicKey.ParseandFromBlob:.pubandauthorized_keyslines, key blobs) get the same checks, are bounded to 8 KiB, and are refused withFormatException; a line withauthorized_keysoptions is refused rather than read without its restrictions. Private key files are bounded too: an RSA key over 16384 bits is refused before it is built, and an OpenSSH key may ask for at most 65,536 bcrypt rounds, so a hostile file can cost minutes of CPU only when a passphrase is given. Traditional encrypted PEM keys (AES-CBC, OpenSSL'sEVP_BytesToKeywith MD5 and one iteration) are read but never written: their weak key derivation makes a stolen file cheap to brute-force, so convert them withssh-keygen -p.What the client says before encryption: the identification line (
SSH-2.0-SshSharp_x.y.z) is sent in the clear, as every SSH client's is, so anyone on the path learns the library and its version.SshClientOptions.VersionAddendumadds the application's own comment to it, equally in the clear and kept in server logs; nothing else is added, and the documentation warns against putting secrets or personal data there.Staggered connect: with
StaggeredConnectDelay, several TCP connections to the server's addresses may be open at once (ConfigureSocketis called for each). Only the first to connect carries SSH; the others are closed before anything is sent.Resource exhaustion: packets are limited to 256 KiB, channel data to the advertised window (
ChannelWindowSize, 2 MiB by default and at most 1 GiB, which is also the most unread data one channel can buffer) and maximum packet size, command output toMaxCommandOutputBytes, and banners, identification lines andEXT_INFOentries are bounded. A peer that overruns the window is a protocol error. With compression on, a packet must also inflate to less than 256 KiB (Compression).Log volume: a few log entries are triggered by the server's side, as often as it likes: a message number the client does not implement, a forwarded connection that cannot be made or that a remote dynamic forwarding's filter refuses, and a forwarded agent request that
ForwardAgentFilterrefuses. Their text is the library's, so they cannot forge a log line, but they could fill a log. Like OpenSSH, which rate-limits its refused-forwarding messages, each connection writes at most 8 of them a minute at their own level (Warning, or Information for refused agent requests); the window starts with the first and lasts a minute. The rest are written at Debug, and when the window ends one summary says how many were (event id 63, "N more entries the server triggered ... were written at Debug level"), at the highest level among them. The limit is shared by the connection, its remote forwardings and its forwarded agent, and runs on the connection'sTimeProvider. Closing the connection writes the summary it still owes. Because the entries share one budget, a server can spend it with cheap unimplemented messages and lower a later entry that matters, such as a refused agent request with its key fingerprint, or a destination the forwarding filter refused: that entry is still written, at Debug, and counted in the summary, but its details are then visible only at Debug. An application that audits refused agent requests or forwardings keeps Debug for event ids 32 and 45, or does its own logging inForwardAgentFilterandallowDestination, which run for every request.Owed replies: many server messages require an answer from the client: a global or channel request that wants a reply, a channel the server opens (confirmed or refused), a CLOSE, a message number the client does not implement (
SSH_MSG_UNIMPLEMENTED), and a transport ping (ping@openssh.com, answered with a pong). The client queues these answers without waiting, as its receive loop must never wait on a send, and the server decides how many it asks for. So the answers queued and not yet sent share one budget of 256 KiB, each counted as its size plus 64 bytes for the memory that holds it, and given back once it is sent. A server that keeps asking but stops reading cannot grow the client's memory beyond that, which keep-alives would not catch, as the server keeps sending. Over the budget, a ping goes unanswered (a pong is optional, and the connection stays up), and any other message that requires an answer fails the connection withSshProtocolException(ProtocolError): "The server is not reading the replies it asked for". A server that reads never comes near it: the budget bounds the answers waiting, not the answers over the connection's life. The client's own messages (data, its own requests, and window adjustments, which follow only data the application has read or the client has discarded for a reader that is gone, at most one per half window, 64 MiB at most) are not counted.Keys and nonces: keys are renewed after 1 GiB (configurable, capped at 64 GiB), 2^31 packets or one hour, so sequence numbers (the ChaCha20-Poly1305 nonce) never wrap under one key.
Post-quantum key exchange:
mlkem768x25519-sha256and the FIPS-compatiblemlkem768nistp256-sha256andmlkem1024nistp384-sha384use the platform's ML-KEM (on .NET 10 and later where the OS provides it), andsntrup761x25519-sha512a managed sntrup761 (everywhere; see the cryptography review). Both check the server's reply length exactly and still reject low-order X25519 points, so neither is weaker than curve25519 alone.Server-chosen Diffie-Hellman groups (
diffie-hellman-group-exchange-sha256): the server picks the prime and generator. They are covered by the exchange hash the server signs, so a man in the middle cannot substitute a weak group; only the server can, and a malicious server holds the session keys anyway. The checks guard against a server with a broken or weak group, which would expose the session to an eavesdropper: the prime must have 2048 to 8192 bits (OpenSSH's client checks only this), be 3 mod 4, have no odd factor below 4096 in p or (p-1)/2, and pass one Miller-Rabin round with a random base; the generator must lie in [2, p-2], and the server's public value in (1, p-1). That (p-1)/2 is prime is not proven: it would cost another full-size exponentiation (about 0.65 s at 8192 bits) on every connection. A failed check fails the connection withKeyExchangeFailedbefore the client's public value is sent.A changed host key under
StrictHostKeyChecking no: accepted, as ssh accepts it, but the connection is not trusted: a key that differs from the one inknown_hostsis what a man in the middle presents, andnolets it through. So, as ssh does, the client then gives that server nothing it could use against the user or this machine:- no password, no password change and no keyboard-interactive answers (
Password,PasswordProvider,ChangePasswordandKeyboardInteractiveare not used, and the provider is not asked); public key and GSS-API authentication still work, since a signature bound to the session gives a man in the middle nothing to replay elsewhere; - no agent forwarding: sessions do not ask for it, and agent channels the server opens are refused;
- no port forwarding for the whole connection:
LocalForward,RemoteForwardandDynamicForwardare not started (withExitOnForwardFailurethe connection fails), andSshClient's forwarding methods (local, remote, dynamic and Unix socket forwarding) throwSshHostKeyException. A man in the middle would otherwise receive the connections meant for the host, or open connections on this side. Tunnels (OpenTcpTunnelAsync,OpenUnixSocketTunnelAsync, asssh -W, which ProxyJump uses) still work: they listen nowhere and serve only this process. So doOpenChannelAsyncandSendGlobalRequestAsync: what they send is the application's choice, and channels the server opens are still checked against the client's own forwardings; - no host key updates (below).
A warning with the new key's fingerprint (no host name) is logged once per connection. Each
ProxyJumporJumpHostshop is verified on its own, so a hop whose key changed loses its own password and agent forwarding, and the destination keeps them if its key is trusted. OnlyKnownHostsVerifierreports a key as changed; a custom verifier's verdict is all or nothing.- no password, no password change and no keyboard-interactive answers (
Host key rotation (
UpdateHostKeys): off by default. A new key is recorded only after the server proves it holds it (hostkeys-prove-00@openssh.com), and any invalid proof cancels the whole update. Removing keys the server no longer announces needs no proof, as inssh, so the update is applied only when the connection itself was trusted through the user's own file before it started: not a key from a global file orKnownHostsCommand, not a changed key let through byStrictHostKeyChecking no(which proves nothing, and must not get the real keys removed as stale), and not a keyAcceptNewrecorded on this connection (trusted on first use, which must not also teach or remove other keys). Likessh, the update is cancelled whenever a line for the host is a wildcard, names more thanhost,address, or is@cert-authorityor@revoked, and whenever a key the server announces, or one the update would remove, is also recorded under another name. Only plain host lines in the first user file are ever changed. A server announces its keys (hostkeys-00@openssh.com) once per connection, so the client acts on the first announcement only, and a second one fails the connection with a protocol error, as in OpenSSH: a server cannot start update after update, each racing the others onknown_hosts. As in OpenSSH, a client that does not update (UpdateHostKeysoff, a certificate host key, a keyAcceptNewrecorded on this connection) ignores every announcement, repeats included. A connection whose changed keyStrictHostKeyChecking nolet through still fails on a second announcement.Recording host keys: the host name is written into
known_hostsonly if it is a literal name. White space, control characters, commas,*,?and!are refused, since they would add lines or hosts, or turn the entry into a pattern that trusts the key for other hosts, and so is a leading@or#. Every line the library writes for the application (KnownHostsEntry,KnownHostsFile.Add,AppendAsync) is checked the same way: host patterns and the key type must be single fields, the host patterns must not start with@(the line would be read as a marker line:@cert-authority * <key> <comment>would trust the key in the comment as an authority for every host) or#(a comment), and the comment must not contain CR, LF or other control characters (a tab is allowed), so a value from the application, such as a comment taken from user input, cannot add a line (an@cert-authorityline, say) to the file or turn the line into one.Revoked host keys (
RevokedHostKeys): checked before anything else, in everyStrictHostKeyCheckingmode, for the plain key and a certificate's authority, serial and key id. A file that cannot be read, or a KRL that is malformed or has a section or critical extension this library does not know, refuses every host key, as ssh does, rather than let a revoked key through. In a text key list, a malformed certificate line of a type SshSharp accepts (Ed25519, ECDSA, RSA, FIDO) does the same; a certificate line of a type it never accepts (DSA, or one it does not know) is skipped, as OpenSSH skips it, since no key it could name is ever accepted. A certificate line is not held to the 1.3 certificate rules (at most 256 principals, options and extensions in order): only the key it certifies is read, and that key is revoked whatever the certificate's principals and options. The KRL parser is bounded (16 MiB files, 1 MiB per serial bitmap) and fuzzed. KRL signatures are not verified: the file is local configuration, trusted likeknown_hosts. Refusals name the directive (RevokedHostKeys), not the file's path.Host certificates (
@cert-authority): a certificate is trusted only when an@cert-authorityline for the host lists its authority and it is valid now, for the name connected to (orHostKeyAlias), with a valid signature, made with an algorithmCASignatureAlgorithmsallows, and no critical options. One that fails those checks proves nothing, and, as inssh(check_host_key: "Retry with plain key"), its certified key is then checked as a plain key with theStrictHostKeyCheckingrules, as for a certificate from an authority that is not listed: a plainknown_hostsline accepts it,Yesrefuses it, andAcceptNew,Noand an acceptedAskrecord the plain key, never the certificate. This trusts nothing a plain key would not be trusted for: the server still proved it holds that key, and the certificate adds nothing. The unusable certificate is logged as a warning with the key's and the authority's fingerprints and the problem, never the host name or the key id (often a host name). If the plain key is then refused, the exception message names the key id, cleaned like other server text, since the application asked about this host. A certificate whose key or authority is revoked (@revoked,RevokedHostKeys) is refused outright, with no fallback. A host certificate that is malformed is not read at all, and fails the connection whatever its authority: besides truncated or padded ones, that is one with more than 256 principals (OpenSSH's limit) or with critical options or extensions out of lexical order or listed twice (draft-ietf-sshm-cert), so two readers can never disagree on which entry applies.@revokedlines inknown_hosts: refuse the key in everyStrictHostKeyCheckingmode, and win over any line that trusts it. As in OpenSSH master, in its next release (d62150ded3), a line written without a port (@revoked server.example <key>) revokes the key for the host on every port, not only on 22, whether it is the plain key, a host certificate's certified key or its authority; a line with a port ([server.example]:2222) applies to that port only. These lines are read from the user's and the global files (not fromKnownHostsCommandoutput, which is produced for the port), but not underHostKeyAlias, which is looked up on its own name.UpdateHostKeysnever learns a revoked key.
Compression
Off by default, as in ssh. SshClientOptions.Compression (Compression yes in ssh_config) offers zlib@openssh.com, and the
server decides whether it is used. It changes two things.
What packet lengths say. Encryption hides content but not length, and compressed data is as long as it is compressible. When secrets and data an attacker can choose share a compression context, the attacker can guess a secret piece by piece and watch the length of the packets: a guess that matches compresses better (CRIME and BREACH against TLS and HTTP, and "Crossing the Streams" against SSH, where every channel of a connection shares one zlib stream per direction). This is the main reason compression is off by default.
- What SshSharp sends is compressed with Huffman coding only, as OpenSSH has done since September 2026: no LZ77, so nothing refers back to earlier data, and a packet's length depends on its own bytes alone, not on whether they repeat a secret sent before. Huffman coding still lets the length reflect how varied a packet's own bytes are. On .NET 8, where the strategy cannot be chosen, SshSharp does not compress what it sends at all.
- What the server sends is compressed however the server chooses. OpenSSH before that change, and other servers, use LZ77, so a secret the server sends (a file's content, a command's output) and attacker-influenced data in another channel of the same connection can leak through the lengths of the server's packets.
- So keep compression off for a connection that carries both secrets and data from a party that also watches the network, for example a tunnel that forwards a browser's traffic next to a session that reads credentials. It is fine for what it is meant for: command output, logs and files over a slow link, with no untrusted party feeding the same connection.
What the decompressor sees. Only delayed compression is supported: nothing is compressed or inflated before the server has
accepted the user's authentication, and every packet is decrypted and its MAC or tag checked before it is inflated. So the zlib
decoder only ever reads data from the server whose host key was verified, after login. Plain zlib, which starts with the first
packet and exposes the decoder to an unauthenticated peer, is not implemented, by design (OpenSSH removed it from its client in
2024). The decoder is .NET's (System.IO.Compression, zlib), and its output is bounded: a packet that inflates to 256 KiB or more
(a decompression bomb) or is not valid zlib data fails the connection with a protocol error, before any of it reaches a channel.
Compression is not a cryptographic algorithm, so FipsMode allows it.
What stays in memory. With compression on, plaintext is left behind in buffers SshSharp cannot wipe, unlike its own packet buffers (which are zeroed before they go back to the pool, a packet that fails to inflate included):
- zlib's native state: its window of recent data (up to 32 KiB per direction) is freed, not wiped, when the stream ends.
- .NET's
ZLibStream(aDeflateStream) rents an 8 KiB buffer from the process-wideArrayPool<byte>.Sharedfor each direction. When inflating, it holds the server's last compressed payloads; when compressing, SshSharp's last compressed payloads. Compressed is not encrypted: anyone who can inflate it reads the plaintext. The stream returns the buffer to the shared pool without clearing it when it is disposed (at each key exchange and when the connection ends), and the next code in the process that rents an array of that size gets it, contents and all.
This matters only to a threat that can read the process's memory or that shares its array pool with code it does not trust; such a threat can usually read the data where the application uses it anyway. With compression off there are none of these buffers.
Channels the server opens
- Only these server-opened channels are accepted:
forwarded-tcpipfor a port the client asked to forward,forwarded-streamlocal@openssh.comfor a socket path the client asked to forward (matched exactly), andauth-agent@openssh.comoragent-connect(RFC 9987) when agent forwarding is on. Everything else (X11, unknown types) is refused. - For remote port and Unix-socket forwarding, a connection goes only to the target the client named for that forwarding.
Remote dynamic forwarding (
ForwardRemoteDynamicPortAsync,ssh -R port) is different: the server's side names the destination in a SOCKS request, so anyone who can reach the forwarded port on the server can use this machine's network. As withssh, every destination is allowed unless the application passesallowDestination. The filter sees canonical forms: an IP literal in any spelling (127.1,::ffff:127.0.0.1) as its canonical address, and a host name both as given and as each address it resolves to here, and the connection goes only to an address that passed. A forwarding started fromssh_config(RemoteForward port) is filtered byPermitRemoteOpeninstead, withssh's rules: an IP literal is still compared in canonical form, but a host name is compared only as given and then resolved and connected to here, so an entry that names a host trusts this machine's resolver for it. Unset,PermitRemoteOpenallows everything, as inssh; an entry that does not parse allows nothing. - The client does not check the address a
forwarded-tcpipchannel names, only the port. The server picks which forwarding to use anyway. - Remote forwarding to a handler (
ForwardRemotePortAsyncandForwardRemoteUnixSocketAsyncwith a handler) runs the application's code for every connection the server forwards, so anyone who can reach the forwarded port or socket on the server (every user there, and other machines with a non-loopback bind address andGatewayPorts) can send it data. The handler must treat what it reads as untrusted input: bound sizes and time, validate, and authenticate requests where it matters.SshForwardedConnection's addresses and ports are what the server reported; they describe the connection and do not authenticate the peer. Each forwarding serves at mostmaxConnections(100 by default) at once and refuses the server's channels above it; a handler that throws closes its own connection only, and its exception is logged by type, never with its message. Disposal waitsHandlerShutdownTimeout(5 seconds by default) for cancelled handlers, then closes their connections; withTimeout.InfiniteTimeSpan, a handler that ignores its token holds disposal up for as long as it runs. A connection that the client takes only after disposal has gathered the ones it waits for is closed without reaching the handler: none escapes the bound. - Agent forwarding relays the agent protocol unchanged, as
ssh -Adoes: while the connection is up, the server can ask the agent to sign with any of its keys. Forward the agent only to servers you trust, and narrow what it can do: withForwardAgentFilter, destination constraints (ssh-add -h), or the agent's own confirmation (ssh-add -c) for sensitive keys. Each agent channel the server opens makes a connection to the local agent (or is served by the in-process one), so agent channels count againstSshClientOptions.MaxForwardedConnectionswith the forwarded connections; above it, the server's channel is refused (resource shortage) and no agent connection is made. ForwardAgentFilterputs the application between the server and the agent. A compromised server (or anyone with root on it) can then get only what the filter allows: each listed key and each signature is the filter's decision, and requests to add, remove or lock keys are refused, so they never reach a real agent. What it judges by:- The key, the purpose and the user name come from the request: the server's side chooses them. The purpose is what the data's form shows (a login request, an SSH signature, a certificate); data of any other form has no purpose (null). Such data is signed when the filter allows it, so other programs that sign through agents keep working (pam_ssh_agent_auth). An agent signs whatever data it is given, so a forwarded agent is a signing service for any protocol that uses the same key; a filter that allows only the purposes the application knows (logins and SSH signatures, say) turns that off.
DestinationHostKeyis set only from a session binding (session-bind@openssh.com) whose host key signature over the session identifier verified, and a login request must then be for that session (and, host-bound, name that host key) or it is refused. It proves which server's key exchange the program on the server took part in, not that the server is honest; an oldersshthat does not bind gives no destination.ForwardingHostKeys' first entry is this client's own server (from its key exchange); later hops are as the hops reported them.- A refused request is
SSH_AGENT_FAILURE, as a declined confirmation is. Anything the filter throws refuses the request. - Without a filter, nothing changes: a real agent's connection is relayed byte for byte.
- The in-process agent (
SshAgent.FromKeys) answers forwarded agent channels in this process. A program on the server reaches only its protocol server, which parses every request in full before acting, bounds each message at 256 KiB (OpenSSH's limit; a larger or empty one closes the channel, not the connection), answers malformed requests withSSH_AGENT_FAILURE, and serves each channel on its own. It is read-only and never signs RSA with SHA-1. Likessh-agent, it signs data of any form it is asked to (other programs sign their own challenges through agents), so without a filter a program on the server can use it to sign for other protocols that use the same key;ForwardAgentFilterlimits it to known purposes, and a key behind anSshKeySignersees such data asSshSignaturePurpose.Other, which its policy can refuse. Its keys are the application's: a key loaded from a file is held in this process's memory for as long as the agent is used, where a crash dump or a debugger can reach it, as with any key passed inPrivateKeys, whereasssh-agentkeeps keys in another process. For sensitive keys, serve a key behind anSshKeySigner(a KMS, an HSM, a smart card): its private half never enters the process, and the signer's own policy (SshSignRequest.Purpose) is a second check after the filter. - Transport pings (
ping@openssh.com) are answered with a pong, as OpenSSH answers them. Pongs not yet sent count against the owed-reply budget (256 KiB; see The network and the server), so a server that pings but stops reading cannot grow the client's memory; pings past the budget go unanswered. - Forwarded connections and agent channels the server opens are capped together (
SshClientOptions.MaxForwardedConnections, 1,000 by default, and a handler forwarding'smaxConnections); above it, new ones are refused. Within that, a server can still send data up to each channel's window (2 MiB), and no more until it is read: a handler that stops reading holds the server back.
Channels and global requests the application opens
SshClient.OpenChannelAsync and SendGlobalRequestAsync send a channel type or request name and data that the application
chooses. They go to the destination only, never to a jump host. SshSharp checks only that the name is well formed (RFC 4251
section 6) and that the data fits in one packet; the bytes themselves are the application's to encode and the server's to read.
A few limits keep these from getting around what the library enforces elsewhere:
- No sessions. A
sessionchannel opened this way would bypassPreventNewSessionsAsyncand the session options, so that type is refused. - Standard names are not blocked, but gain nothing. The application may send a global request such as
tcpip-forward. Any channel the server then opens is still checked against the forwardings the client itself started, as described above. - Answers are untrusted. An
SshGlobalRequestResultand a custom channel's data are what the server sent, unchecked. The application parses them as input from an untrusted peer. - The data is never logged or recorded in telemetry. Global request names aren't logged either. A channel type appears only in
the idle-timeout log line (
ChannelTimeout), as for every channel type. Names should not carry secrets.
The agent
- Windows named pipes: any user can create a pipe under a name nobody holds yet, so another user on the same machine could create the OpenSSH agent's pipe while the service is stopped, or Pageant's (its name is derived from the user name and a value every process on the machine computes alike). SshSharp therefore uses an agent pipe only when its owner is the current user, SYSTEM or the Administrators group, as PuTTY checks Pageant's pipe; otherwise no signing request or key is sent to it.
- The agent's path (a socket, or a pipe whose name, as Pageant's, holds the user name) is never put in an exception message or a log: an agent that cannot be reached is reported by the system error's type or socket error code, not its message, which can quote the path.
- Adding keys (
AddKeyAsync,AddKeysToAgent): the private key goes to the agent the application named.AddKeysToAgentadds only identity-file keys the server accepted, never keys the application passed inPrivateKeys. WithAddKeysToAgent ask, a key goes only after the application'sConfirmAddKeyToAgentsays yes; without that callback, or inBatchMode, none goes, so a configuration cannot put keys into the agent unasked. The prompt it gets carries the identity file's path and the key's comment, which can name the user; they are given to the application, not logged. The lock passphrase (LockAsync) is a managed string and cannot be wiped. - An in-process agent (
SshAgent.FromKeys) is trusted like the keys it holds: it is the application's own code and keys, reached through no socket or pipe, so no other local user can pose as it or connect to it. It refuses to add, remove or lock keys, soAddKeysToAgentandAddKeyAsynccannot put keys into it.
Local listeners (port forwarding and SOCKS)
ForwardLocalPortAsyncandForwardDynamicPortAsyncbind where the application says. Forwardings fromssh_configbind to loopback unless the configuration names an address or setsGatewayPorts, as withssh.ForwardLocalUnixSocketAsync(andLocalForward /path ...) listens on a Unix socket file it creates, owner-only by default: mode 0600 on Unix (ssh's defaultStreamLocalBindMask 0177), an ACL with only the current user on Windows. The application (asocketMode) or the configuration (StreamLocalBindMask) can widen it on Unix, for example to the owner's group; everyone the mode lets connect can then use the SSH connection. Windows keeps the current-user ACL whatever the mode: a Unix mode has no faithful ACL counterpart, and the library narrows rather than guesses. The permission is set betweenbindandlisten, while the socket refuses connections, so no one the mode leaves out can connect in between. It never replaces an existing file unlessssh_configsaysStreamLocalBindUnlink yes(then whatever file is at that path is deleted, assshdoes), and it removes its socket file when it stops. The paths come from the application or the configuration; they are not logged.- The SOCKS proxy supports only CONNECT (SOCKS 4, 4a and 5). Started without credentials it has no authentication (like
ssh -D): anyone who can reach its address can use the SSH connection, so it should listen on loopback. Started with aNetworkCredential, it takes only SOCKS 5 with username/password authentication (RFC 1929) and refuses SOCKS 4 and clients that do not authenticate, so it can listen beyond loopback. That protects against those who cannot see the traffic, not against those who can: RFC 1929 sends the credentials in clear text, and the application's traffic to the proxy is plain TCP (only the hop from this machine to the server is encrypted), so anyone on that network path can read the password and reuse it, and read or change the traffic. Loopback stays the safer choice where it will do. The forwarder keeps only HMAC-SHA256 digests of the user name and password, under a random key made for it, and compares each attempt's digests in constant time (both fields, without stopping at the first that differs), so response timing reveals nothing about the expected values or their lengths. Failed attempts are logged without the client's address and are not rate limited: the password must be long and random. - Remote forwarding to a handler opens no listener on this machine: its connections reach the application's code only through the SSH connection (see Channels the server opens for what that code must expect).
Proxies
- An HTTP or SOCKS proxy (
SshProxy) sees the destination host and port; the SSH traffic through it is encrypted and the host key is verified as usual, so a hostile proxy can refuse or delay the connection but not read or change it. - Proxy credentials (HTTP Basic, SOCKS 5 user name and password) are sent as the protocols define them, in clear text to the proxy; they never appear in exceptions or logs. Replies are bounded (HTTP headers to 16 KiB) and validated, and host names that a protocol cannot carry are refused rather than altered.
- A custom proxy (
SshProxy.FromConnector) is the application's own code, run in-process; it is given the host and port of the first network hop and nothing else (no credentials, no host keys). The stream it returns is trusted no more than a TCP connection: the host key is verified over it, so a transport that misbehaves can refuse, delay or break the connection but not read or change it. Its exception messages are not copied into the library's own (they may name the host); the exception is kept as the inner exception for the application.
Jump hosts
A jump host (SshClientOptions.JumpHosts, or ProxyJump in ssh_config) relays the next hop's SSH connection through a
direct-tcpip channel. It sees the next host's name and port and the encrypted traffic, and can refuse, delay or end the
connection, but not read or change it: each host's key is verified end to end, by that host's own verifier.
- Credentials go only to the host they belong to. With
JumpHosts, each hop is offered only what its ownSshJumpHost.Optionshold, and the destination's password, keys, keyboard-interactive handler and agent forwarding are never offered to a hop (nor a hop's to the destination). WithProxyJump, see Configuration input. - A hop's options cannot carry a proxy, a local address or jump hosts of their own (
ArgumentException), so which network connection a setting applies to is never ambiguous: the destination'sProxy,LocalEndPointandAddressFamilyapply to the first hop. - An application that passes the same
SshClientOptionsobject to a hop and to the destination offers the same credentials to both, by its own choice. - A connection that fails partway closes the hops already opened, and disposing the destination closes the whole chain, so no authenticated hop is left open behind a failed or finished connection.
SFTP
- Every reply is parsed as hostile (and fuzzed): lengths, counts and request ids are checked, a packet is at most 1 MiB, a directory listing is bounded, and names that are not valid UTF-8 are decoded with replacement characters instead of failing.
- Recursive downloads apply the same name checks as SCP (no
.,.., separators, NUL, or Windows device names;:and\only matter on Windows) and keep every path inside the target directory. Uploads skip special files (FIFOs, sockets, devices). - With
Preserve, a download applies the server's permission bits (read, write and execute for owner, group and others; never set-id or sticky) where this machine has Unix modes, without the local umask, assftp -pdoes: a server can make what it sends world-writable. A directory's mode is applied after its contents, and a name listed twice is fetched once. - With
Preserve, an upload never sets times or permissions through a path that may have changed since the file or directory was created. Another user who can write to the destination could replace it with a symbolic link meanwhile, and a pathSETSTATwould follow the link and apply this user's mode and times to its target, such as a file or directory this user owns. A file's attributes are set on its open handle (FSETSTAT) once every write has landed and before it is closed (for a segmented upload, before any session closes it), and a directory's withlsetstat@openssh.com, which does not follow links, assftpdoes. A server without that extension gets a plainSETSTATfor directories. - A recursive delete (
DeleteDirectoryAsync(path, recursive: true)) removes symbolic links without following them, and checks every subdirectory withLSTATbefore entering it, so a listing that describes a link as a directory cannot lead it outside the tree. It is bounded like a directory download (64 levels; each listing bounded) and touches only the server's files. The checks cannot be atomic: SFTP has noO_NOFOLLOWoropenat, so every request names a path the server resolves again. Someone else who can write inside the tree on the server (another user, a process there) can swap a checked directory for a link between theLSTATand the requests that follow, and the delete then removes the files the link leads to, as far as this login's rights on the server reach. Delete recursively only trees no one else can change while it runs. - A listing keeps up to 8 READDIR requests in flight on its handle and takes the batches in the order it asked for them; the
replies to requests past the end (EOF, or an error from some servers) are read and dropped before the handle is closed. A
recursive listing (
SftpListOptions.Recursive) only reads: it goes at mostMaxDepthlevels down (64 by default, 1024 at most), enters each name a directory lists once, and holds at mostMaxConcurrentDirectorieshandles. It does not enter links unlessFollowSymbolicLinksis set; then a link may lead anywhere the server lets the user see, and a loop is recognized by the path the server'sREALPATHresolves (a server that does not resolve links leaves it toMaxDepth). The server decides what a listing contains, so a hostile one can make a recursive listing as large asMaxDepthallows; stop or cancel it to bound the work. SftpTransferOptions.SkipUnchangedtrusts the sizes and modification times the server reports (in a download's listing, or of the remote files an upload would replace): a server can make a transfer leave files it should have replaced (TimeTolerancegives it nothing more: it can report any time it likes). It cannot make anything be written that it did not send. WithSkipUnreadableDirectories(transfers and recursive listings), a server can leave a directory out by refusing it withPermissionDenied; a transfer lists every such directory inSftpTransferSummary.UnreadableDirectories(a listing reports it toUnreadableDirectory), and any other error still fails the transfer.SftpTransferOptions.Filteris the caller's code, run locally for each entry; in a download it sees the server's names and attributes, already checked as above.- A server that stops answering holds a request until the session ends, unless
SftpClient.OperationTimeoutis set; it then fails the request (Timeout) once the server has been silent that long. - Segmented transfers (
Segments) open more SFTP sessions as channels of the same connection: nothing new is authenticated or sent anywhere else. A segmented upload that fails cuts the remote file it created or truncated to its unbroken start, or deletes that file where the server cannot cut it, so a later resume cannot keep a gap; it never touches another path. A server that stops answering can only delay this byOperationTimeout(or 5 s) per step; a cleanup that did not finish is marked on the exception (SftpClient.UploadCleanupIncompleteKey), so the application knows not to resume a file that may have gaps. - A file hash (
GetFileHashAsync,check-fileormd5-hash) is computed by the server, so a match is only as good as the server: it detects a truncated or damaged file, not a server that lies. Only SHA-2 is accepted unless the application namesmd5,sha1orcrc32, which detect accidental damage only. The reply must name an algorithm that was asked for and carry a digest of that algorithm's length. - A raw extended request (
SendExtendedRequestAsync) sends the name and bytes the application gives, to the SFTP server of this session only. The reply is returned as untrusted bytes for the application to parse; only a status is parsed, and its message is stripped of control characters and cut to 200 characters, as for every other status. SshSharp.FileProviderstreats backslashes as separators and refuses..and NUL in subpaths, so a web request cannot leave the configured root by name, and bounds its cache. The server follows symbolic links, including ones that point out of the root.
SSH signatures and allowed-signers files
- A signature is accepted only for its exact namespace, with SHA-256 or SHA-512, and never with SHA-1 RSA (
ssh-rsa). - An allowed-signers file is parsed strictly, as
ssh-keygendoes: an unknown or repeated option rejects the whole file rather than silently dropping a restriction. Acert-authorityline accepts only user certificates it issued, within their validity, for a principal the certificate names and the line allows.
Certificates the application checks or issues
- Checking (
SshCertificate): a certificate is parsed as hostile input (and fuzzed), and refused when malformed, including more than 256 principals and options or extensions out of order or repeated (draft-ietf-sshm-cert).VerifySignatureproves only that the key in the certificate'sAuthorityKeysigned it; anyone can make a CA, so trusting a certificate means comparing its authority with one you trust.IsValidFordoes both, then the type, the validity window (valid_after <= now < valid_before), the principal (exact for users, a pattern for hosts; a certificate without principals is no one's) and refuses any critical option, since only the application can enforceforce-commandorsource-address. The CA's signature must be SHA-2 or Ed25519 (never SHA-1ssh-rsa), from an RSA key of 2048 bits or more; the same rules apply to host certificates inknown_hostsand to certificates in allowed-signers files. Revocation is not part of these checks: check it withSshKeyRevocationList(a KRL or a key list, as sshd'sRevokedKeys), which revokes a certificate by serial or key id for its authority, and when its certified key or its authority's key is revoked. The list is parsed with the same bounds and strictness asRevokedHostKeys(a malformed KRL, or one with a section this library does not know, throws rather than being read in part). In a text key list, a certificate line revokes the key it certifies, FIDO security-key certificates (sk-...-cert-v01@openssh.com) included, and a certificate line of an accepted type whose key cannot be read throws for the whole list rather than being skipped, so it cannot leave a revoked key accepted (a DSA or unknown certificate line is skipped: its key is never accepted). Its signatures are not verified: it is local configuration, as trusted as the code that loads it. Vendor extension values (ExtensionValues) are what the CA wrote; servers ignore extensions they do not know, and an application that acts on one is trusting the CA for it. - Signatures by an expected key (
SshSignature.Verify(message, namespace, expectedKey)): accepted when that key, or a certificate for it, made the signature; such a certificate's authority, validity and principals are not checked, since the key itself is what is trusted. - Issuing (
SshCertificateBuilder): the application is then the certificate authority, and whoever can sign with the CA key can log in as any principal on every server that trusts it. Keep the key out of the process: in an SSH agent, or in a key vault, KMS or HSM through anSshKeySignerthat allowsSshSignaturePurpose.Certificateand nothing else (and, the other way round, have login keys refuse that purpose). Issue for the shortest time that works (there is no default end, so nothing is valid forever by accident), name principals exactly (at least one is required, so no certificate is valid for any user), drop the extensions a use does not need, give each certificate its own serial for revocation, and log what is issued. The builder checks option names and values before anything is signed, writes options sorted and once each, refuses more than 256 principals, uses a fresh 32-byte random nonce, signs RSA withrsa-sha2-512(neverssh-rsa), and verifies the signature before returning the certificate, so a signer or agent that answers with the wrong key or algorithm fails instead of producing a certificate servers would refuse. - What it decides: who gets a certificate is the application's decision. The library does not authenticate the requester.
SCP downloads
Names the server sends must be single path components: not empty,
.or.., and free of separators, drive colons and control characters (the CVE-2019-6111 pattern). On Windows, device names (CON,NUL,COM1, ...) and names ending in a dot or space are refused too.A single-file download refuses a second file or a directory.
File modes from the server apply only with
Preserve, and only the permission bits, never set-id or sticky.Remote paths, for downloads and uploads, are part of the command line run on the server (
scp -t <path>,scp -f <path>), so how they are written decides whether a path can run a command as the logged-in user: the issue behind CVE-2020-15778 and SSH.NET's GHSA-mggc-4xg6-vcxf.SshScpOptions.PathQuotingchooses how:Posix(the default) writes one single-quoted word, with each',\and!written outside the quotes, escaped ('\'','\\','\!'). sshd runs the line with the account's login shell, and this is safe for any path with sh, bash and zsh, but also with fish, which reads\'and\\as escapes even inside single quotes, and tcsh, which expands!there. Up to 1.2.0 a path holding them could run a command when the account's shell was fish or tcsh. On a Windows OpenSSH server the command runs throughcmd.exe, which does not treat single quotes as quotes, or PowerShell, which escapes a quote inside them differently, so there a path the application does not control can run a command.None(1.3) writes the path as given, with no quotes and no--, for network devices that read the line without a shell. It allows only letters, digits and/ . _ - : + @ =, with no-,=or@first, so even a server that does have a shell gets one word that is not an option and that the common shells read literally: zsh and tcsh expand a leading=, and PowerShell splats a leading@and splits a word at,.DoubleQuote(1.3) writes one double-quoted word, for OpenSSH for Windows withcmd.exe(which runscmd.exe /c "<line>"). It refuses control characters,", whatcmd.exeexpands inside double quotes (%, and!with delayed expansion), what PowerShell expands or ends a string at ($,`, its typographic double quotes),< > | * ?, a trailing\(which the C runtime would read, with the closing quote, as a literal"), and a leading-, so the path cannot be read as an option even by a shell that drops the--before it.
Both new modes refuse a path before anything is sent, with
ArgumentException. Their checks keep a path to one word, but do not confine it: a path can still name any file the account can reach. They are meant for paths the application controls; applications pass other paths to SFTP, which runs no shell.Total size, file count and directory depth are not limited: a server can fill the target's disk.
Secrets in memory and logs
- Passwords, private keys and command text are never logged. User names and host names are not logged either; host key
fingerprints and algorithm names are. The connection's addresses (
SshClient.RemoteEndPoint,LocalEndPoint) and session id are there for the application to read, and are never logged or recorded in telemetry. - Exception messages, which applications log, follow the same rule: no user names, host names (the canonicalizer's failure
included) or names that usually are user names (a certificate's principals, the agent's path). A file or SFTP path the
application passed to the failing call can appear, as in .NET's own I/O exceptions; a path that comes from ssh_config does not
(an
Included file is named by its file name only, aRevokedHostKeysfile by the directive), nor does an agent destination's[user@]host. A ProxyJump hop that refuses to log in is named by its place in the list ("ProxyJump hop 2"), not by its name. - Text the server chooses reaches exception messages and log entries only cleaned: the reason in its
DISCONNECT, the reason it gives for refusing a channel, the comment in its identification line (logged; a malformed line is echoed in the exception), SFTP status messages, the remote scp's error lines and stderr, an exit signal's name, an SCP or SFTP file name it was refused for, and, since 1.3.0, the names a server sends before its host key is verified (an unknown host key, curve or certificate type) and an unusable host certificate's key id, signature algorithm and critical option names. Line breaks, tabs and Unicode line and paragraph separators become one space, other control and format characters (terminal escapes, the bell, bidirectional overrides, zero-width characters) are removed, and the text is cut short (200 characters for most), so a server cannot forge a log line or send escape sequences to a terminal that shows the message. The raw identification line is still what the exchange hash covers. Text an application asks for and shows itself is not cleaned: banners and keyboard-interactive prompts (see the authentication section),SshExitSignal.ErrorMessage,SftpFileInfo.LongNameand a forwarded agent request's user name are the server's, and an application that shows them should treat them as such. - Log values that carry an exception (an agent failure, say) are formatted to a sanitized reason and expose no public property holding the exception, so a structured log sink that records properties cannot record the agent's path from it either.
- Traces and metrics carry no user name, host name, file or directory path, a forwarding's address, port or socket path, SOCKS
destination, or dependency injection endpoint name. The connect span records the server's TCP port (
server.port), never its address. SFTP and SCP transfer spans carry byte and file counts, forwarding instruments only the kind of forwarding, and the authentication span the method that succeeded and the number of requests, never which key was offered. SshAuthenticationException(its message andAttempts) names methods, outcomes and the SHA-256 fingerprints of the keys offered, which identify public keys only. It never holds a password, a keyboard-interactive answer or the user name. A key fingerprint can link a failed login to its owner, as it can in the server's own log; treat it as you treat host key fingerprints.PasswordProviderandChangePasswordget the user name and the host as the caller gave it, to show a prompt. The library keeps neither the passwords they return nor the new password after authentication.- Derived keys and key material are wiped (
CryptographicOperations.ZeroMemory) when no longer needed. Managed strings (thePasswordoption) cannot be wiped; this is a known limitation. The same holds forSshGssapiOptions.Credential: aNetworkCredentialkeeps its password as a managed string, so prefer the platform's ticket (kinit, or the Windows logon session) to an explicit credential. - On .NET 11, X25519 comes from the platform where the OS provides it. The managed X25519, Ed25519, sntrup761 and Poly1305 code avoids branches and table lookups on secret data. DH (group14/16/18
and group exchange) uses
BigInteger.ModPow, which is not constant-time, on an ephemeral exponent used once; the post-quantum hybrids, curve25519 and ECDH are preferred.
Configuration input
ssh_config can run local commands (Match exec, ProxyCommand, KnownHostsCommand), as in OpenSSH.
Match execruns nothing unless the application opts in with an exec runner.ProxyCommandruns by default, as withssh. Applications that load configurations they do not control can turn it off withSshConfigConnectOptions.AllowProxyCommand = false.- The password, keyboard-interactive answers and keys given in
SshConfigConnectOptions(Password,KeyboardInteractive,PrivateKeys) go to the destination only: aProxyJumphop, perhaps run by someone else, is never offered them, and logs in with its own configuration's identity files and the agent. The same holds forPasswordProviderandChangePassword: they are never called for a hop, nor inBatchMode. (Before 1.1,PrivateKeyswere offered to every hop as well: a hop learned the public keys, and could have accepted one of them.) PubkeyAcceptedAlgorithmsnarrows which keys are offered, as inssh; it only ever removes keys from what would otherwise be offered, and never brings SHA-1ssh-rsasignatures back.Includeis bounded: at most 16 levels deep and 1,024 files in all, so a configuration cannot make resolution parse without end.KnownHostsCommandruns only withSshConfigConnectOptions.AllowKnownHostsCommand = true. It is off by default, unlikeProxyCommand, because its output is trusted as known_hosts lines: a configuration the application does not control must not be able to vouch for host keys. With it off, a configuration that names one fails the connection. As in OpenSSH, no shell is involved (the command is split into arguments, each expanded on its own, the program taken as written, and the program must be an absolute path), so token values cannot inject commands; the run is limited to 30 seconds and 1 MiB of output. On Windows a batch file (.bat,.cmd) is refused, because Windows runs it throughcmd.exe, which would reparse the arguments.- When the library stops one of these commands (
Match execcancelled or past its 30 seconds,KnownHostsCommandpast its limit, aProxyCommandwhen its connection closes), it kills the command and every process it started. On Linux and macOS these processes run in the application's own process group, and each getsSIGKILLalone, neverSIGSTOPfirst: .NET's own tree kill stops each process before killing it, and a background child left stopped when its shell died made macOS sendSIGHUPto that group, which terminates the application (#432). A process forked as its parent is killed is no longer in the tree (macOS completes the fork), so each command also runs withSSHSHARP_PROCESS_TREEset to a random value of its own, which everything it starts inherits: after the tree, every live process carrying that value is killed too, until none is left, each parent before its children, so that a shell cannot run its next command between its child's death and its own. Only processes of the application's own user are found. A process that drops the variable from its environment and leaves the tree can escape. On Windows the command's process tree is ended as .NET ends it, which stops nothing first; there is noSSHSHARP_PROCESS_TREEmark and no sweep there, so a process that has already left the tree survives. - On .NET 11, these commands inherit only their standard streams, not the other handles the application has open (sockets,
files, the agent's pipe). Outside Windows, a command being stopped first gets
SIGTERMand half a second to exit, so it can close its connection; then it and every process it started are killed as above. If it exits in time, the processes it left running are still killed: those carrying itsSSHSHARP_PROCESS_TREEvalue. Earlier runtimes inherit what the OS passes by default, and kill at once. Match localnetworkreads the local interface addresses. As ssh_config(5) warns, a network address is not a trustworthy criterion: anyone who controls the network can choose which block applies.- Host name canonicalization (
CanonicalizeHostname) with the built-in DNS canonicalizer (UseDnsCanonicalizer, off by default) sends a lookup for each candidate name (the host with eachCanonicalDomainsentry) to the system's resolver, and so to its DNS servers, usually unencrypted: they learn the names tried, as withssh. The answers decide theHostNameand, through the second pass, whichHostandMatchblocks apply (anIdentityFile, aProxyJump, aUser), so whoever can answer those queries can choose among the names tried and the blocks written for them. The host key is still checked for the name connected to, so a forged answer cannot impersonate a host whose key is known; withStrictHostKeyCheckingother thanyes, a new name may be accepted as for any new host. A CNAME target replaces the name only whenCanonicalizePermittedCNAMEsallows that pair, which keeps a forged CNAME from moving the connection (and its known_hosts lookup) to an arbitrary name. Canonicalization makes no lookups for a host reached throughProxyJump,ProxyCommandorSshConfigConnectOptions.Proxyunless the configuration saysalways, so with a proxy that resolves names itself (socks5h, HTTP), the names are not sent to this machine's DNS. That includes the hops of aProxyJumpchain after the first: each is reached through the hop before it, which resolves its name, so internal names behind a bastion are not looked up here. - Host and user names supplied by the caller are substituted into those commands (
%h,%n,%r), so they are refused when they contain shell metacharacters, control characters or a leading-(the CVE-2023-51385 pattern). Host names may not contain white space either, which would split%hinto extra arguments. User names may (Windows account names can). - The config file itself is trusted to the same degree OpenSSH trusts it: whoever can edit it can run commands as the user.
Values it sets (
HostName,User) are used as written. - Socket paths in
LocalForwardandRemoteForwardtake%tokens and${VAR}, as inssh; only paths on this machine take~, so a path on the server never carries this machine's home directory (and user name). A server-side path is expanded on this machine and sent to the server as one string (no shell is involved on either side), so a caller-supplied host or user name in%hor%rcan only change which path is asked for; the server's ownStreamLocalBindMaskand permissions apply there.StreamLocalBindMaskcan widen a local socket's permissions (see Local listeners). TCPKeepAliveandIPQoSset socket options only: keep-alive probes and the type-of-service mark are visible on the network path, as withssh, and say nothing the connection's existence does not.
Dependency injection
SshEndpointOptionscan hold a password, a key passphrase, private keys as text (PrivateKeys) and a proxy URI with a password, bound from configuration: bind them from a secret store, not a checked-in file. They are not logged, validation errors name an entry without its value, andSshEndpointPrivateKey.ToString()and the debugger do not show them.- Host keys are checked strictly by default: an unknown host fails unless
AcceptNewHostKeysis set (which trusts the first key it sees), and a changed key always fails. HostKeyFingerprintsreplaces known_hosts with pinned keys (fingerprints,.publines or known_hosts lines); whoever can change the configuration decides which servers are trusted, as with a known_hosts file. Combining it withKnownHostsFiles,AcceptNewHostKeysorConfigAliasfails validation rather than widening trust to either source. A known_hosts line's host field is not checked (the entry pins its key), and marked lines (@cert-authority,@revoked) are refused rather than turned into pins.JumpHostsreaches the server through bastions. Each hop is offered only its own credentials (password, keys, the agent when its ownUseAgentis set): the endpoint's never reach a jump host, and a hop's never reach the destination. Every hop's host key is checked: against its own pins or known_hosts files, or else the endpoint's known_hosts files (with the endpoint'sAcceptNewHostKeys); behind an endpoint that pins its keys, a hop without its own fails validation rather than falling back to files a pinned deployment does not have.UseAgentlets the endpoint (or a hop) sign with the agent's keys: anSshAgentregistered in the container, else the user's agent (withConfigAliastoo, in place of ssh_config'sIdentityAgent). Every key the agent holds is offered to that server, as with ssh; an application that should offer one key only registers an in-process agent (SshAgent.FromKeys) with it. Nothing is added to the agent.UseSshTunnelsends anHttpClient's connections through the endpoint's server, which resolves the host names and connects to them (direct-tcpip): the server sees which services are called, but not the traffic when it is HTTPS, as TLS runs end to end.- Connection events (
WatchAsync) name the endpoint by its registered name only, with no host or user name; the error they carry can hold the server's disconnect text. - With
ConfigAlias, the connection takes ssh_config's settings and the core defaults (ProxyCommandallowed, the agent used,ForwardAgentandStrictHostKeyCheckingas the file says); an unknown host is refused, since there is no one to ask. - The health check's description names no server software and carries no server text, since health endpoints are often reachable without authentication. Its exception is attached for logging: do not write it to a public response.
Out of scope
- A compromised local machine or process (memory dumps, debuggers, malicious code in the same process).
- Denial of service by a server the user chose to connect to, beyond the bounds above (a server can always refuse service).
- Physical side channels (power, EM) and microarchitectural attacks across processes.