Skip to content

Commit

Permalink
Issue #4232 - Fix CWE-22 Path/Directory Traversal issues
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Mordyk <[email protected]>
  • Loading branch information
omordyk committed Jan 31, 2025
1 parent 6cef591 commit 203c266
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/path_publickey.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func UploadPublicKey(filename string,
return errorhandler(NewAPIUserInputError(fmt.Sprintf("provided public key or cert is not valid; error: %v", err), "trusted cert file"))
} else if err := os.MkdirAll(targetPath, 0644); err != nil {
return errorhandler(NewSystemError(fmt.Sprintf("unable to create trusted cert directory %v, error: %v", targetPath, err)))
} else if err := ioutil.WriteFile(targetFile, inBytes, 0644); err != nil {
} else if err := os.WriteFile(targetFile, inBytes, 0644); err != nil {
return errorhandler(NewSystemError(fmt.Sprintf("unable to write uploaded trusted cert file %v, error: %v", targetFile, err)))
}
return false
Expand Down
2 changes: 1 addition & 1 deletion cli/cliconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func GetConfig(configFile string) (*HorizonCliConfig, error) {

cliutils.Verbose(msgPrinter.Sprintf("Reading configuration file: %v", configFile))

fileBytes, err := ioutil.ReadFile(configFile)
fileBytes, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf(msgPrinter.Sprintf("Unable to read config file: %v. %v", configFile, err))
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cliutils/cliutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ func TrustIcpCert(httpClient *http.Client) error {
}

if icpCertPath != "" {
icpCert, err := ioutil.ReadFile(icpCertPath)
icpCert, err := os.ReadFile(icpCertPath)
if err != nil {
return fmt.Errorf(i18n.GetMessagePrinter().Sprintf("Encountered error reading ICP cert file %v: %v", icpCertPath, err))
}
Expand Down
2 changes: 1 addition & 1 deletion config/collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func newHTTPClientFactory(hConfig HorizonConfig) (*HTTPClientFactory, error) {

if mhCertPath != "" {
var err error
mgmtHubBytes, err = ioutil.ReadFile(mhCertPath)
mgmtHubBytes, err = os.ReadFile(mhCertPath)
if err != nil {
return nil, fmt.Errorf("Failed to read Cert File: %v", mhCertPath)
}
Expand Down
2 changes: 1 addition & 1 deletion container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ func (b *ContainerWorker) ResourcesCreate(agreementId string, agreementProtocol

glog.V(5).Infof("Writing raw config to file in %v. Config data: %v", workloadRWStorageDir, string(configureRaw))
// write raw to workloadRWStorageDir
if err := ioutil.WriteFile(path.Join(workloadRWStorageDir, "Configure"), configureRaw, 0644); err != nil {
if err := os.WriteFile(path.Join(workloadRWStorageDir, "Configure"), configureRaw, 0644); err != nil {
return nil, err
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion css/horizonAuthenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func newHTTPClient(certPath string) (*http.Client, error) {

if certPath != "" {
var err error
caBytes, err = ioutil.ReadFile(certPath)
caBytes, err = os.ReadFile(certPath)
if err != nil {
return nil, errors.New(fmt.Sprintf("unable to read %v, error %v", certPath, err))
}
Expand Down

0 comments on commit 203c266

Please sign in to comment.