Skip to content

Commit 2ce1543

Browse files
RemiBouRemi Bourgarelcursoragent
authored
JGC-449 - Add gosec suppressions for static analysis (#1524)
* JGC-449 - Add gosec suppressions for static analysis Co-authored-by: Cursor <cursoragent@cursor.com> * JGC-449 - Fix staticcheck QF1012 use fmt.Fprintf instead of WriteString(fmt.Sprintf) Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Remi Bourgarel <remib@jfrog.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c98f347 commit 2ce1543

File tree

9 files changed

+24
-24
lines changed

9 files changed

+24
-24
lines changed

artifactory/commands/transferfiles/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func TestGetMaxUniqueSnapshots(t *testing.T) {
186186
default:
187187
assert.Fail(t, "tried to get the Max Unique Snapshots setting of a repository of an unsupported package type")
188188
}
189-
_, err := w.Write([]byte(response))
189+
_, err := w.Write([]byte(response)) // #nosec G705 -- test server response, not user input
190190
assert.NoError(t, err)
191191
})
192192
defer testServer.Close()

artifactory/commands/utils/precheckrunner/remoteurlchecker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type remoteRepoSettings struct {
3232
Url string `json:"url,omitempty"`
3333
RepoType string `json:"repo_type,omitempty"`
3434
Username string `json:"username,omitempty"`
35-
Password string `json:"password,omitempty"`
35+
Password string `json:"password,omitempty"` // #nosec G117 -- API struct for remote repo settings
3636
QueryParams string `json:"query_params,omitempty"`
3737
}
3838

artifactory/utils/commandsummary/buildinfosummary.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (bis *BuildInfoSummary) generateModuleArtifactTree(rootModuleID string, nes
156156

157157
markdownBuilder.WriteString(generateModuleHeader(rootModuleID))
158158
if !StaticMarkdownConfig.IsExtendedSummary() {
159-
markdownBuilder.WriteString(fmt.Sprintf(basicSummaryUpgradeNotice, StaticMarkdownConfig.GetExtendedSummaryLangPage()))
159+
fmt.Fprintf(&markdownBuilder, basicSummaryUpgradeNotice, StaticMarkdownConfig.GetExtendedSummaryLangPage())
160160
}
161161
for _, module := range nestedModules {
162162
if isMultiModule && rootModuleID == module.Id {
@@ -166,7 +166,7 @@ func (bis *BuildInfoSummary) generateModuleArtifactTree(rootModuleID string, nes
166166
if err != nil {
167167
return "", err
168168
}
169-
markdownBuilder.WriteString(fmt.Sprintf("\n\n<pre>%s</pre>\n\n", tree))
169+
fmt.Fprintf(&markdownBuilder, "\n\n<pre>%s</pre>\n\n", tree)
170170
}
171171
return markdownBuilder.String(), nil
172172
}
@@ -193,7 +193,7 @@ func (bis *BuildInfoSummary) generateTableModuleMarkdown(nestedModules []buildIn
193193

194194
if !StaticMarkdownConfig.IsExtendedSummary() {
195195
nestedModuleMarkdownTree.WriteString("|")
196-
nestedModuleMarkdownTree.WriteString(fmt.Sprintf(basicSummaryUpgradeNotice, StaticMarkdownConfig.GetExtendedSummaryLangPage()))
196+
fmt.Fprintf(&nestedModuleMarkdownTree, basicSummaryUpgradeNotice, StaticMarkdownConfig.GetExtendedSummaryLangPage())
197197
nestedModuleMarkdownTree.WriteString("<pre>")
198198
} else {
199199
nestedModuleMarkdownTree.WriteString("|<pre>")

general/token/oidctokenexchange.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type OidcParams struct {
7979
}
8080

8181
type ExchangeCommandOutputStruct struct {
82-
AccessToken string `json:"AccessToken"`
82+
AccessToken string `json:"AccessToken"` // #nosec G117 -- CLI output struct for OIDC exchange
8383
Username string `json:"Username"`
8484
}
8585

utils/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,11 +590,11 @@ type ServerDetails struct {
590590
OnemodelUrl string `json:"-"`
591591
ApptrustUrl string `json:"-"`
592592
User string `json:"user,omitempty"`
593-
Password string `json:"password,omitempty"`
593+
Password string `json:"password,omitempty"` // #nosec G117 -- config struct for auth
594594
SshKeyPath string `json:"sshKeyPath,omitempty"`
595595
SshPassphrase string `json:"sshPassphrase,omitempty"`
596-
AccessToken string `json:"accessToken,omitempty"`
597-
RefreshToken string `json:"refreshToken,omitempty"`
596+
AccessToken string `json:"accessToken,omitempty"` // #nosec G117 -- config struct for auth
597+
RefreshToken string `json:"refreshToken,omitempty"` // #nosec G117 -- config struct for auth
598598
ArtifactoryRefreshToken string `json:"artifactoryRefreshToken,omitempty"`
599599
ArtifactoryTokenRefreshInterval int `json:"tokenRefreshInterval,omitempty"`
600600
ClientCertPath string `json:"clientCertPath,omitempty"`
@@ -609,7 +609,7 @@ type ServerDetails struct {
609609
// Deprecated
610610
type MissionControlDetails struct {
611611
Url string `json:"url,omitempty"`
612-
AccessToken string `json:"accessToken,omitempty"`
612+
AccessToken string `json:"accessToken,omitempty"` // #nosec G117 -- config struct for auth
613613
}
614614

615615
func (serverDetails *ServerDetails) IsEmpty() bool {

utils/config/config_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ func createEncryptionTestConfig() *Config {
246246
ServerId: "test-server",
247247
Url: "http://acme.jfrog.io",
248248
User: "elmar",
249-
Password: "Wabbit",
250-
AccessToken: "DewiciousWegOfWamb",
251-
SshPassphrase: "KiwwTheWabbit",
249+
Password: "Wabbit", // #nosec G101 -- test data only
250+
AccessToken: "DewiciousWegOfWamb", // #nosec G101 -- test data only
251+
SshPassphrase: "KiwwTheWabbit", // #nosec G101 -- test data only
252252
}}},
253253
}}
254254
}
@@ -479,10 +479,10 @@ func TestCreateAuthConfigAppendPreRequestFunctionBehavior(t *testing.T) {
479479
name: "DisableTokenRefreshTrue_WithArtifactoryRefreshToken",
480480
serverDetails: &ServerDetails{
481481
ServerId: "test-server",
482-
AccessToken: "access-token-123",
483-
ArtifactoryRefreshToken: "artifactory-refresh-token-789",
482+
AccessToken: "access-token-123", // #nosec G101 -- test data only
483+
ArtifactoryRefreshToken: "artifactory-refresh-token-789", // #nosec G101 -- test data only
484484
User: "testuser",
485-
Password: "testpass",
485+
Password: "testpass", // #nosec G101 -- test data only
486486
DisableTokenRefresh: true,
487487
},
488488
shouldCallAppendPreRequest: true,
@@ -491,10 +491,10 @@ func TestCreateAuthConfigAppendPreRequestFunctionBehavior(t *testing.T) {
491491
name: "DisableTokenRefreshFalse_WithArtifactoryRefreshToken",
492492
serverDetails: &ServerDetails{
493493
ServerId: "test-server",
494-
AccessToken: "access-token-123",
495-
ArtifactoryRefreshToken: "artifactory-refresh-token-789",
494+
AccessToken: "access-token-123", // #nosec G101 -- test data only
495+
ArtifactoryRefreshToken: "artifactory-refresh-token-789", // #nosec G101 -- test data only
496496
User: "testuser",
497-
Password: "testpass",
497+
Password: "testpass", // #nosec G101 -- test data only
498498
DisableTokenRefresh: false,
499499
},
500500
shouldCallAppendPreRequest: true,

utils/config/configtoken.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ type configToken struct {
1818
MissionControlUrl string `json:"missionControlUrl,omitempty"`
1919
PipelinesUrl string `json:"pipelinesUrl,omitempty"`
2020
User string `json:"user,omitempty"`
21-
Password string `json:"password,omitempty"`
21+
Password string `json:"password,omitempty"` // #nosec G117 -- config struct for auth
2222
SshKeyPath string `json:"sshKeyPath,omitempty"`
2323
SshPassphrase string `json:"sshPassphrase,omitempty"`
24-
AccessToken string `json:"accessToken,omitempty"`
25-
RefreshToken string `json:"refreshToken,omitempty"`
24+
AccessToken string `json:"accessToken,omitempty"` // #nosec G117 -- config struct for auth
25+
RefreshToken string `json:"refreshToken,omitempty"` // #nosec G117 -- config struct for auth
2626
TokenRefreshInterval int `json:"tokenRefreshInterval,omitempty"`
2727
ClientCertPath string `json:"clientCertPath,omitempty"`
2828
ClientCertKeyPath string `json:"clientCertKeyPath,omitempty"`

utils/coreutils/tableutils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func setColMaxWidth(columnConfigs []table.ColumnConfig, fieldsProperties []field
314314
}
315315

316316
func getTerminalAllowedWidth(colNum int) (int, error) {
317-
width, _, err := term.GetSize(int(os.Stdout.Fd()))
317+
width, _, err := term.GetSize(int(os.Stdout.Fd())) // #nosec G115 -- fd from process stdout, safe on all supported platforms
318318
if err != nil {
319319
return 0, err
320320
}

utils/progressbar/progressbarmng.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ var ShouldInitProgressBar = func() (bool, error) {
343343
}
344344

345345
func setTerminalWidth() error {
346-
width, _, err := term.GetSize(int(os.Stderr.Fd()))
346+
width, _, err := term.GetSize(int(os.Stderr.Fd())) // #nosec G115 -- fd from process stderr, safe on all supported platforms
347347
if err != nil {
348348
return errorutils.CheckError(err)
349349
}

0 commit comments

Comments
 (0)