Skip to content

Commit a86f6e8

Browse files
fix(gateway): prevent leaking username in logs (#6012)
* fix(gateway): prevent leaking username in logs Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix(cli): remove unused JWT username helper Signed-off-by: Simon Scatton <sscatton@nvidia.com> --------- Signed-off-by: Simon Scatton <sscatton@nvidia.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 793c5f3 commit a86f6e8

1 file changed

Lines changed: 1 addition & 22 deletions

File tree

‎crates/openshell-cli/src/commands/gateway.rs‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,18 +1247,9 @@ pub async fn gateway_login(name: &str, gateway_insecure: bool) -> Result<()> {
12471247
.await?
12481248
};
12491249

1250-
let username = jwt_preferred_username(&bundle.access_token);
12511250
openshell_bootstrap::oidc_token::store_oidc_token(name, &bundle)?;
12521251
openshell_bootstrap::oidc_token::clear_oidc_login_prompt(name)?;
1253-
1254-
if let Some(user) = username {
1255-
eprintln!(
1256-
"{} Authenticated to gateway '{name}' as {user}",
1257-
"✓".green().bold(),
1258-
);
1259-
} else {
1260-
eprintln!("{} Authenticated to gateway '{name}'", "✓".green().bold());
1261-
}
1252+
eprintln!("{} Authenticated to gateway '{name}'", "✓".green().bold());
12621253
}
12631254
_ => {
12641255
return Err(miette::miette!(
@@ -1271,18 +1262,6 @@ pub async fn gateway_login(name: &str, gateway_insecure: bool) -> Result<()> {
12711262
Ok(())
12721263
}
12731264

1274-
/// Extract `preferred_username` from a JWT payload without signature verification.
1275-
fn jwt_preferred_username(token: &str) -> Option<String> {
1276-
let payload = token.split('.').nth(1)?;
1277-
let decoded =
1278-
base64::Engine::decode(&base64::engine::general_purpose::URL_SAFE_NO_PAD, payload).ok()?;
1279-
let claims: serde_json::Value = serde_json::from_slice(&decoded).ok()?;
1280-
claims
1281-
.get("preferred_username")
1282-
.and_then(|v| v.as_str())
1283-
.map(String::from)
1284-
}
1285-
12861265
/// Clear stored authentication credentials for a gateway.
12871266
pub fn gateway_logout(name: &str) -> Result<()> {
12881267
let metadata = openshell_bootstrap::load_gateway_metadata(name).map_err(|_| {

0 commit comments

Comments
 (0)