diff --git a/keystore.go b/keystore.go index 36415e1..ae1bd5a 100644 --- a/keystore.go +++ b/keystore.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "golang.org/x/text/unicode/norm" - "io/ioutil" "os" "path/filepath" "unicode" @@ -165,7 +164,8 @@ func KeystoreCryptoFromJSON(data map[string]interface{}) (*KeystoreCrypto, error // FromFile reads a keystore from a file func (ks *Keystore) FromFile(path string) error { - fileData, err := ioutil.ReadFile(path) + cleanedPath := filepath.Clean(path) + fileData, err := os.ReadFile(cleanedPath) if err != nil { return err } @@ -319,8 +319,11 @@ func (ks *Keystore) ToJSON() (string, error) { // Save writes the Keystore to a file in JSON format func (ks *Keystore) Save(fileFolder string) error { - filePath := filepath.Join(fileFolder, ks.UUID+".json") - file, err := os.Create(filePath) + cleanedFileFolder := filepath.Clean(fileFolder) + filePath := filepath.Join(cleanedFileFolder, ks.UUID+".json") + + cleanedFilePath := filepath.Clean(fileFolder) + file, err := os.Create(cleanedFilePath) if err != nil { return err } diff --git a/mnemonic.go b/mnemonic.go index 2340443..4c24755 100644 --- a/mnemonic.go +++ b/mnemonic.go @@ -27,8 +27,11 @@ import ( // - []string: A slice of words from the wordlist. // - error: An error object if the wordlist file cannot be read. func getWordList(language, path string) ([]string, error) { - filePath := filepath.Join(path, fmt.Sprintf("%s.txt", language)) - file, err := os.Open(filePath) + cleanLanguageFileName := filepath.Clean(fmt.Sprintf("%s.txt", language)) + filePath := filepath.Join(path, cleanLanguageFileName) + + cleanFilePath := filepath.Clean(filePath) + file, err := os.Open(cleanFilePath) if err != nil { return nil, fmt.Errorf("failed to open wordlist file: %v", err) }