Skip to content

Commit

Permalink
Redact logged install paths for possible credential leak
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Dec 29, 2023
1 parent 4a8484b commit 5a3c28c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions backend/bindings/debug_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 6 additions & 5 deletions backend/bindings/ficsitcli/installs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion backend/bindings/ficsitcli/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions backend/utils/paths.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package utils

import (
"log/slog"
"net/url"
"os"

"github.com/pkg/errors"
Expand All @@ -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))
}

0 comments on commit 5a3c28c

Please sign in to comment.