Skip to content

Commit

Permalink
Do not log user password in clear text
Browse files Browse the repository at this point in the history
Instead the password should be masked and replaced with e.g. asterisks.

Signed-off-by: Milan Lenco <[email protected]>
(cherry picked from commit 0483f48)
  • Loading branch information
milan-zededa committed May 27, 2024
1 parent c2d6ae2 commit 049c806
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/wwan/mmagent/mmdbus/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1357,9 +1357,12 @@ func (c *Client) reconfigureEpsBearerIfNotRegistered(modemObj dbus.BusObject,
}
var currentSettings map[string]dbus.Variant
_ = getDBusProperty(c, modemObj, Modem3GPPPropertyInitialEpsBearer, &currentSettings)
maskedPasswd := interface{}("***")
maskedVariantPasswd := dbus.MakeVariant(maskedPasswd)
c.log.Warnf("Modem %s is failing to register, "+
"trying to apply settings %+v for the initial EPS bearer (previously: %+v)",
modemObj.Path(), newSettings, currentSettings)
modemObj.Path(), maskPassword(newSettings, maskedPasswd),
maskPassword(currentSettings, maskedVariantPasswd))
err = c.callDBusMethod(modemObj, Modem3GPPMethodSetInitialEpsBearer, nil, newSettings)
if err != nil {
err = fmt.Errorf(
Expand All @@ -1372,6 +1375,19 @@ func (c *Client) reconfigureEpsBearerIfNotRegistered(modemObj dbus.BusObject,
modemObj, ModemStateRegistered, changeInitEPSBearerTimeout)
}

// maskPassword creates a copy of the original map with the "password" key's value masked
func maskPassword[Type any](data map[string]Type, maskWith Type) map[string]Type {
maskedData := make(map[string]Type)
for key, value := range data {
if key == "password" {
maskedData[key] = maskWith
} else {
maskedData[key] = value
}
}
return maskedData
}

func (c *Client) setPreferredRATs(modemObj dbus.BusObject,
preferredRATs []types.WwanRAT) error {
var prefModes []uint32
Expand Down

0 comments on commit 049c806

Please sign in to comment.