Summary
NetBird's SSH configuration manager can place an unsanitized peer hostname into a system-wide OpenSSH configuration file. A malicious or compromised peer may exploit this behavior to inject SSH directives, potentially causing commands to execute locally when users run SSH.
NetBird's SSH configuration manager can place an unsanitized peer hostname into a system-wide OpenSSH configuration file. A malicious or compromised peer may exploit this behavior to inject SSH directives, potentially causing commands to execute locally when users run SSH.
Affected context
The issue occurs in NetBird desktop clients that generate an OpenSSH drop-in configuration from peer FQDNs or hostnames. It affects Linux, macOS, Windows, and FreeBSD deployments where peer-controlled or otherwise untrusted names are written into the SSH configuration without adequate escaping; mobile applications are outside the described affected context.
The issue occurs in NetBird desktop clients that generate an OpenSSH drop-in configuration from peer FQDNs or hostnames. It affects Linux, macOS, Windows, and FreeBSD deployments where peer-controlled or otherwise untrusted names are written into the SSH configuration without adequate escaping; mobile applications are outside the described affected context.
Exploit preconditions
- Attack surface: NetBird peer-name handling and generated OpenSSH configuration
- Required access: A malicious or compromised peer must be able to present a hostname or FQDN that reaches the configuration-generation path
- Trigger point: A local user runs an SSH command after the generated configuration has been loaded
- Why exploitation is possible: A peer name containing special characters can terminate the intended quoted host value and introduce additional SSH configuration directives, including command-execution directives
- Attack surface: NetBird peer-name handling and generated OpenSSH configuration
- Required access: A malicious or compromised peer must be able to present a hostname or FQDN that reaches the configuration-generation path
- Trigger point: A local user runs an SSH command after the generated configuration has been loaded
- Why exploitation is possible: A peer name containing special characters can terminate the intended quoted host value and introduce additional SSH configuration directives, including command-execution directives
Why this happens
The vulnerable code interpolates peer-controlled hostnames into a double-quoted OpenSSH Match host directive without applying context-appropriate escaping or strict validation. This is an instance of CWE-78: Improper Neutralization of Special Elements used in an OS Command, with CWE-116: Improper Encoding or Escaping of Output describing the unsafe generation of configuration text. The underlying insecure pattern is treating an externally influenced identifier as safe configuration syntax.
The vulnerable code interpolates peer-controlled hostnames into a double-quoted OpenSSH Match host directive without applying context-appropriate escaping or strict validation. This is an instance of CWE-78: Improper Neutralization of Special Elements used in an OS Command, with CWE-116: Improper Encoding or Escaping of Output describing the unsafe generation of configuration text. The underlying insecure pattern is treating an externally influenced identifier as safe configuration syntax.
Potential impact
- A local user's SSH invocation may execute attacker-controlled commands
- The affected host may experience unauthorized code execution with the privileges of the invoking user
- Credentials, configuration, or other user-accessible data could be exposed
- An attacker could alter files or establish persistence within the user's privilege boundary
- Multiple client hosts could be affected if the malicious peer is trusted by several deployments
- A local user's SSH invocation may execute attacker-controlled commands
- The affected host may experience unauthorized code execution with the privileges of the invoking user
- Credentials, configuration, or other user-accessible data could be exposed
- An attacker could alter files or establish persistence within the user's privilege boundary
- Multiple client hosts could be affected if the malicious peer is trusted by several deployments
General mitigation guidance
Mitigation generally focuses on reducing trust in peer names and preventing untrusted values from becoming SSH configuration syntax.
Common defensive patterns include:
- Accepting peer FQDNs or hostnames only when they conform to a strict DNS-name grammar
- Applying escaping appropriate to the exact OpenSSH configuration context
- Preferentially using structured configuration APIs or fixed templates rather than string concatenation
- Rejecting invalid values before writing configuration files
- Restricting write access to system-wide SSH configuration paths
- Running desktop services with least privilege and protecting generated files from unauthorized modification
- Reviewing existing generated configuration for unexpected directives and regenerating it from validated data
Mitigation generally focuses on reducing trust in peer names and preventing untrusted values from becoming SSH configuration syntax.
Common defensive patterns include:
- Accepting peer FQDNs or hostnames only when they conform to a strict DNS-name grammar
- Applying escaping appropriate to the exact OpenSSH configuration context
- Preferentially using structured configuration APIs or fixed templates rather than string concatenation
- Rejecting invalid values before writing configuration files
- Restricting write access to system-wide SSH configuration paths
- Running desktop services with least privilege and protecting generated files from unauthorized modification
- Reviewing existing generated configuration for unexpected directives and regenerating it from validated data
How teams detect issues like this
Detection can combine source review, runtime monitoring, and policy enforcement:
- Use static analysis to identify concatenation or interpolation of peer-controlled values into SSH configuration text
- Review code for missing validation or escaping before values enter quoted directives
- Monitor changes to system-wide SSH configuration directories and alert on unexpected
Match,ProxyCommand, orLocalCommanddirectives - Apply repository policies that require allowlisted hostname validation and security review for generated configuration
- Test configuration generation with boundary characters and verify that output remains syntactically constrained
- Automated code-review and software-composition tools may help identify related injection patterns
Detection can combine source review, runtime monitoring, and policy enforcement:
- Use static analysis to identify concatenation or interpolation of peer-controlled values into SSH configuration text
- Review code for missing validation or escaping before values enter quoted directives
- Monitor changes to system-wide SSH configuration directories and alert on unexpected
Match,ProxyCommand, orLocalCommanddirectives - Apply repository policies that require allowlisted hostname validation and security review for generated configuration
- Test configuration generation with boundary characters and verify that output remains syntactically constrained
- Automated code-review and software-composition tools may help identify related injection patterns
Sources
| Source | Link |
|---|---|
| github. | github.com/ |
| github. | github.com/ |
| github. | github.com/ |

