Skip to content

Commit 947c88e

Browse files
Fixes pentest issue DG25-29 from 2025-09-02 (#98)
* exclude Peer::preshared_key from debug output * cargo update, bump version * add test
1 parent 42e9437 commit 947c88e

File tree

3 files changed

+74
-16
lines changed

3 files changed

+74
-16
lines changed

Cargo.lock

Lines changed: 29 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "defguard_wireguard_rs"
3-
version = "0.7.6"
3+
version = "0.7.7"
44
edition = "2024"
55
rust-version = "1.85"
66
description = "A unified multi-platform high-level API for managing WireGuard interfaces"

src/host.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::{
44
collections::HashMap,
5-
fmt::{Debug, Formatter},
5+
fmt::{self, Debug, Formatter},
66
io::{self, BufRead, BufReader, Read},
77
net::SocketAddr,
88
str::FromStr,
@@ -20,7 +20,7 @@ use serde::{Deserialize, Serialize};
2020
use crate::{error::WireguardInterfaceError, key::Key, net::IpAddrMask, utils::resolve};
2121

2222
/// WireGuard peer representation.
23-
#[derive(Clone, Debug, Default, PartialEq)]
23+
#[derive(Clone, Default, PartialEq)]
2424
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
2525
pub struct Peer {
2626
pub public_key: Key,
@@ -34,6 +34,25 @@ pub struct Peer {
3434
pub allowed_ips: Vec<IpAddrMask>,
3535
}
3636

37+
// implement manually to avoid exposing preshared keys
38+
impl fmt::Debug for Peer {
39+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40+
f.debug_struct("Peer")
41+
.field("public_key", &self.public_key)
42+
.field("protocol_version", &self.protocol_version)
43+
.field("endpoint", &self.endpoint)
44+
.field("last_handshake", &self.last_handshake)
45+
.field("tx_bytes", &self.tx_bytes)
46+
.field("rx_bytes", &self.rx_bytes)
47+
.field(
48+
"persistent_keepalive_interval",
49+
&self.persistent_keepalive_interval,
50+
)
51+
.field("allowed_ips", &self.allowed_ips)
52+
.finish_non_exhaustive()
53+
}
54+
}
55+
3756
impl Peer {
3857
/// Create new `Peer` with a given `public_key`.
3958
#[must_use]
@@ -448,4 +467,27 @@ mod tests {
448467
peer.as_uapi_remove()
449468
);
450469
}
470+
471+
#[test]
472+
fn dg25_28_test_dont_expose_preshared_keys() {
473+
let preshared_key_str = "000102030405060708090a0b0c0d0e0ff0e1d2c3b4a5968778695a4b3c2d1e0f";
474+
let peer = Peer {
475+
public_key: Key::decode(
476+
"286ac5ff9b2f900259008172225da774031e8a3689d8f341667be157b2336970",
477+
)
478+
.unwrap(),
479+
preshared_key: Some(Key::decode(preshared_key_str).unwrap()),
480+
protocol_version: None,
481+
endpoint: None,
482+
last_handshake: None,
483+
tx_bytes: 0,
484+
rx_bytes: 0,
485+
persistent_keepalive_interval: None,
486+
allowed_ips: Vec::new(),
487+
};
488+
489+
let debug = format!("{peer:?}");
490+
assert!(!debug.contains("preshared_key"));
491+
assert!(!debug.contains(preshared_key_str));
492+
}
451493
}

0 commit comments

Comments
 (0)