Skip to content

Commit 59bbfd9

Browse files
authored
Fix: hide password on GET /scans/{id} response (#2211)
1 parent 4e089c7 commit 59bbfd9

2 files changed

Lines changed: 95 additions & 1 deletion

File tree

rust/crates/greenbone-scanner-framework/src/get_scans_id.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ where
5959
Box::pin(async move {
6060
enforce_client_id_and_scan_id(&client_id, id, gsp.as_ref(), async |id| {
6161
match gsp.get_scans_id(id).await {
62-
Ok(x) => BodyKind::json_content(StatusCode::OK, &x),
62+
Ok(mut x) => {
63+
x.target.credentials = x
64+
.clone()
65+
.target
66+
.credentials
67+
.into_iter()
68+
.map(|c| c.hide_pass())
69+
.collect();
70+
BodyKind::json_content(StatusCode::OK, &x)
71+
}
6372
Err(e) => e.into(),
6473
}
6574
})

rust/crates/greenbone-scanner-framework/src/models/credential.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,88 @@ impl AsRef<str> for CredentialType {
151151
}
152152
}
153153
}
154+
155+
impl CredentialType {
156+
pub fn hide_pass(&mut self) -> Self {
157+
match self {
158+
CredentialType::UP {
159+
username,
160+
privilege,
161+
..
162+
} => {
163+
let pr = match privilege {
164+
Some(x) => Some(PrivilegeInformation {
165+
username: x.username.clone(),
166+
password: "".to_string(),
167+
}),
168+
None => None,
169+
};
170+
171+
Self::UP {
172+
username: username.to_string(),
173+
password: "".to_string(),
174+
privilege: pr,
175+
}
176+
}
177+
CredentialType::USK {
178+
username,
179+
password,
180+
privilege,
181+
private_key,
182+
} => {
183+
let pr = match privilege {
184+
Some(x) => Some(PrivilegeInformation {
185+
username: x.username.clone(),
186+
password: "".to_string(),
187+
}),
188+
None => None,
189+
};
190+
if let Some(p) = password.as_mut() {
191+
p.clear();
192+
};
193+
194+
CredentialType::USK {
195+
username: username.to_string(),
196+
password: password.clone(),
197+
privilege: pr,
198+
private_key: private_key.to_string(),
199+
}
200+
}
201+
CredentialType::SNMP {
202+
username,
203+
auth_algorithm,
204+
privacy_algorithm,
205+
community,
206+
..
207+
} => CredentialType::SNMP {
208+
username: username.to_string(),
209+
password: "".to_string(),
210+
privacy_password: "".to_string(),
211+
privacy_algorithm: privacy_algorithm.to_string(),
212+
auth_algorithm: auth_algorithm.to_string(),
213+
community: community.to_string(),
214+
},
215+
216+
CredentialType::KRB5 {
217+
username,
218+
realm,
219+
kdc,
220+
..
221+
} => CredentialType::KRB5 {
222+
username: username.to_string(),
223+
password: String::new(),
224+
realm: realm.to_string(),
225+
kdc: kdc.to_string(),
226+
},
227+
}
228+
}
229+
}
230+
231+
impl Credential {
232+
pub fn hide_pass(mut self) -> Self {
233+
Self {
234+
credential_type: self.credential_type.hide_pass(),
235+
..self
236+
}
237+
}
238+
}

0 commit comments

Comments
 (0)