Skip to content

Commit 709eb25

Browse files
committed
Fix: gosec issues, ran go fmt and added checkout action in forgbot scan PR
1 parent bc599ce commit 709eb25

39 files changed

+136
-90
lines changed

.github/workflows/frogbot-scan-pull-request.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ jobs:
1111
scan-pull-request:
1212
runs-on: ubuntu-latest
1313
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
ref: ${{ github.event.pull_request.head.sha }}
17+
1418
- name: Setup Go with cache
1519
uses: jfrog/.github/actions/install-go-with-cache@main
1620

artifactory/commands/transferconfig/transferconfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ func (tcc *TransferConfigCommand) createExportPath() (exportPath string, unsetTe
186186
return "", unsetTempDir, err
187187
}
188188

189+
// #nosec G302 -- exportPath requires 0777 for cross-user access during config transfer
189190
return exportPath, unsetTempDir, errorutils.CheckError(os.Chmod(exportPath, 0777))
190191
}
191192

artifactory/commands/transferconfig/transferconfig_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func TestValidateTargetServer(t *testing.T) {
118118
_, err = w.Write(content)
119119
assert.NoError(t, err)
120120
default:
121+
//nolint:gosec // G117: marshaling test users list for mock server response
121122
content, err := json.Marshal(users)
122123
assert.NoError(t, err)
123124
_, err = w.Write(content)

artifactory/commands/transferconfig/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func archiveConfig(exportPath string, configXml string) (buffer *bytes.Buffer, r
4343
for _, neededFile := range neededFiles {
4444
neededFilePath := filepath.Join(exportPath, neededFile)
4545
log.Debug("Archiving " + neededFile)
46+
// #nosec G304 -- neededFilePath is within the validated Artifactory export directory
4647
fileContent, err := os.ReadFile(neededFilePath)
4748
if err != nil {
4849
if os.IsNotExist(err) && strings.Contains(neededFile, "security") {

artifactory/commands/transferfiles/delayedartifactshandler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func readDelayFile(path string) (DelayedArtifactsFile, error) {
196196
// Stores the errors read from the errors file.
197197
var delayedArtifactsFile DelayedArtifactsFile
198198

199+
// #nosec G304 -- path is the delayed artifacts file in the JFrog transfer directory
199200
fContent, err := os.ReadFile(path)
200201
if err != nil {
201202
return delayedArtifactsFile, errorutils.CheckError(err)

artifactory/commands/transferfiles/errorshandler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func makeDirIfDoesNotExists(path string) error {
101101
return err
102102
}
103103
if !exists {
104+
// #nosec G301 -- path is the transfer errors directory; 0777 is intentional for cross-user access
104105
err = os.Mkdir(path, 0777)
105106
}
106107
return err
@@ -320,6 +321,7 @@ func readErrorFile(path string) (FilesErrors, error) {
320321
// Stores the errors read from the errors file.
321322
var failedFiles FilesErrors
322323

324+
// #nosec G304 -- path is the errors file in the JFrog transfer directory
323325
fContent, err := os.ReadFile(path)
324326
if err != nil {
325327
return failedFiles, errorutils.CheckError(err)

artifactory/commands/transferfiles/transfer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func NewTransferFilesCommand(sourceServer, targetServer *config.ServerDetails) (
6969
if err != nil {
7070
return nil, err
7171
}
72+
// #nosec G118 -- cancelFunc is stored in the struct and called at tdc.cancelFunc() during stop/cancel
7273
ctx, cancelFunc := context.WithCancel(context.Background())
7374
return &TransferFilesCommand{
7475
context: ctx,
@@ -467,6 +468,7 @@ func (tdc *TransferFilesCommand) initTransferDir() error {
467468
return errorutils.CheckError(err)
468469
}
469470
}
471+
// #nosec G301 -- transferDir is the JFrog transfer directory; 0777 is intentional for cross-user access
470472
return errorutils.CheckError(os.MkdirAll(transferDir, 0777))
471473
}
472474

@@ -762,6 +764,7 @@ func (tdc *TransferFilesCommand) signalStop() error {
762764
return errorutils.CheckErrorf("Graceful stop is already in progress. Please wait...")
763765
}
764766

767+
// #nosec G304 -- stopFile path is within the JFrog transfer directory
765768
if stopFile, err := os.Create(filepath.Join(transferDir, StopFileName)); err != nil {
766769
return errorutils.CheckError(err)
767770
} else if err = stopFile.Close(); err != nil {

artifactory/commands/transferfiles/utils_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,12 @@ var convertPatternToPathPrefixTestCases = []struct {
479479
input string
480480
expected string
481481
}{
482-
{"folder/subfolder/*", "folder/subfolder"}, // strips trailing /*
483-
{"folder/**", "folder"}, // strips trailing /**
484-
{"folder/", "folder"}, // strips trailing /
485-
{"folder", "folder"}, // no change when no trailing pattern
486-
{"a/b/c/d/e/*", "a/b/c/d/e"}, // deep path with wildcard
487-
{"single", "single"}, // single segment without slash
482+
{"folder/subfolder/*", "folder/subfolder"}, // strips trailing /*
483+
{"folder/**", "folder"}, // strips trailing /**
484+
{"folder/", "folder"}, // strips trailing /
485+
{"folder", "folder"}, // no change when no trailing pattern
486+
{"a/b/c/d/e/*", "a/b/c/d/e"}, // deep path with wildcard
487+
{"single", "single"}, // single segment without slash
488488
}
489489

490490
func TestConvertPatternToPathPrefix(t *testing.T) {
@@ -592,11 +592,11 @@ var convertPatternToAqlMatchTestCases = []struct {
592592
input string
593593
expected string
594594
}{
595-
{"folder/subfolder/*", "*folder/subfolder*"}, // path with wildcard
596-
{"folder", "*folder*"}, // simple folder name
595+
{"folder/subfolder/*", "*folder/subfolder*"}, // path with wildcard
596+
{"folder", "*folder*"}, // simple folder name
597597
{"org/company/project/*", "*org/company/project*"}, // deep nested path
598-
{"*already/prefixed", "*already/prefixed*"}, // already has leading wildcard
599-
{"already/suffixed*", "*already/suffixed*"}, // already has trailing wildcard
598+
{"*already/prefixed", "*already/prefixed*"}, // already has leading wildcard
599+
{"already/suffixed*", "*already/suffixed*"}, // already has trailing wildcard
600600
}
601601

602602
func TestConvertPatternToAqlMatch(t *testing.T) {

artifactory/commands/utils/precheckrunner/remoteurlchecker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func (rrc *RemoteRepositoryCheck) createRemoteUrlRequest() ([]remoteRepoSettings
109109
func (rrc *RemoteRepositoryCheck) doCheckRemoteRepositories(args RunArguments, remoteUrlRequest []remoteRepoSettings) (inaccessibleRepositories *[]inaccessibleRepository, err error) {
110110
artifactoryUrl := clientutils.AddTrailingSlashIfNeeded(args.ServerDetails.ArtifactoryUrl)
111111

112+
// #nosec G117 -- intentional marshaling of remote repo settings (including credentials) for Artifactory API request
112113
body, err := json.Marshal(remoteUrlRequest)
113114
if err != nil {
114115
return nil, errorutils.CheckError(err)

artifactory/commands/utils/result.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func getTargetRepoFromMap(modulesMap *map[string][]clientutils.DeployableArtifac
127127

128128
func unmarshalDeployableArtifactsJson(filesPath string) (*map[string][]clientutils.DeployableArtifactDetails, error) {
129129
// Open the file
130+
// #nosec G304 -- filesPath is a temporary file path created by the CLI for deployable artifacts data
130131
jsonFile, err := os.Open(filesPath)
131132
defer func() {
132133
e := jsonFile.Close()

0 commit comments

Comments
 (0)