diff --git a/backend/bindings/debug_info.go b/backend/bindings/debug_info.go index 0cc0d0aa..b321d5b1 100644 --- a/backend/bindings/debug_info.go +++ b/backend/bindings/debug_info.go @@ -77,6 +77,7 @@ func addMetadata(writer *zip.Writer) error { Name: fmt.Sprintf("Satisfactory %s (%s)", install.Info.Branch, install.Info.Launcher), Profile: install.Installation.Profile, } + i.Path = utils.RedactPath(i.Path) metadataInstalls = append(metadataInstalls, i) diff --git a/backend/bindings/ficsitcli/installs.go b/backend/bindings/ficsitcli/installs.go index 6ff16bbe..6259f7da 100644 --- a/backend/bindings/ficsitcli/installs.go +++ b/backend/bindings/ficsitcli/installs.go @@ -12,6 +12,7 @@ import ( "github.com/satisfactorymodding/SatisfactoryModManager/backend/installfinders" "github.com/satisfactorymodding/SatisfactoryModManager/backend/installfinders/common" + "github.com/satisfactorymodding/SatisfactoryModManager/backend/utils" ) func (f *FicsitCLI) initInstallations() error { @@ -93,14 +94,14 @@ func (f *FicsitCLI) initRemoteServerInstallations() error { for _, installation := range f.ficsitCli.Installations.Installations { err := f.checkAndAddExistingRemote(installation) if err != nil { - slog.Warn("failed to check and add existing remote", slog.Any("error", err), slog.String("path", installation.Path)) + slog.Warn("failed to check and add existing remote", slog.Any("error", err), utils.SlogPath("path", installation.Path)) } } return nil } func (f *FicsitCLI) checkAndAddExistingRemote(installation *cli.Installation) error { - slog.Debug("checking installation", slog.String("path", installation.Path)) + slog.Debug("checking whether installation is remote", utils.SlogPath("path", installation.Path)) parsed, err := url.Parse(installation.Path) if err != nil { return errors.Wrap(err, "failed to parse installation path") @@ -148,7 +149,7 @@ func (f *FicsitCLI) GetInstallation(path string) *InstallationInfo { } func (f *FicsitCLI) SelectInstall(path string) error { - l := slog.With(slog.String("task", "selectInstall"), slog.String("path", path)) + l := slog.With(slog.String("task", "selectInstall"), utils.SlogPath("path", path)) if f.selectedInstallation != nil && f.selectedInstallation.Info.Path == path { return nil } @@ -177,7 +178,7 @@ func (f *FicsitCLI) SelectInstall(path string) error { installErr := f.validateInstall(f.selectedInstallation, "__select_install__") if installErr != nil { - l.Error("Failed to validate install", slog.Any("error", installErr), slog.String("install", installation.Info.Path)) + l.Error("Failed to validate install", slog.Any("error", installErr)) return errors.Wrap(installErr, "Failed to validate install") } return nil @@ -195,7 +196,7 @@ func (f *FicsitCLI) SetModsEnabled(enabled bool) error { slog.Error("no installation selected") return errors.New("No installation selected") } - l := slog.With(slog.String("task", "setModsEnabled"), slog.Bool("enabled", enabled), slog.String("install", f.selectedInstallation.Info.Path)) + l := slog.With(slog.String("task", "setModsEnabled"), slog.Bool("enabled", enabled), utils.SlogPath("install", f.selectedInstallation.Info.Path)) var message string if enabled { diff --git a/backend/bindings/ficsitcli/profiles.go b/backend/bindings/ficsitcli/profiles.go index 532ad006..39fe9051 100644 --- a/backend/bindings/ficsitcli/profiles.go +++ b/backend/bindings/ficsitcli/profiles.go @@ -12,6 +12,8 @@ import ( "github.com/satisfactorymodding/ficsit-cli/cli" resolver "github.com/satisfactorymodding/ficsit-resolver" wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime" + + "github.com/satisfactorymodding/SatisfactoryModManager/backend/utils" ) func (f *FicsitCLI) SetProfile(profile string) error { @@ -200,7 +202,7 @@ func (f *FicsitCLI) ExportCurrentProfile() error { return errors.Wrapf(err, "Failed to export profile: %s", exportedProfile.Profile.Name) } - exportedProfileJSON, err := json.MarshalIndent(exportedProfile, "", " ") + exportedProfileJSON, err := utils.JsonMarshal(exportedProfile, 2) if err != nil { l.Error("failed to marshal exported profile", slog.Any("error", err)) return errors.Wrapf(err, "Failed to export profile: %s", exportedProfile.Profile.Name) diff --git a/backend/utils/paths.go b/backend/utils/paths.go index 9831e964..3df98a3a 100644 --- a/backend/utils/paths.go +++ b/backend/utils/paths.go @@ -1,6 +1,8 @@ package utils import ( + "log/slog" + "net/url" "os" "github.com/pkg/errors" @@ -20,3 +22,23 @@ func EnsureDirExists(path string) error { } return nil } + +func RedactPath(path string) string { + parsed, err := url.Parse(path) + if err != nil { + return "***INVALID PATH FOR REDACTION***" + } + // For remote servers, they might contain a username, password, and host, all of which should be redacted when logging + if parsed.User != nil { + // "*" would be encoded to %2A in usernames and passwords + parsed.User = url.UserPassword("user", "pass") + } + if parsed.Host != "" { + parsed.Host = "******" + } + return parsed.String() +} + +func SlogPath(key string, path string) slog.Attr { + return slog.String(key, RedactPath(path)) +}