Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gosec): address false positives #288

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "^.secrets.baseline$",
"lines": null
},
"generated_at": "2021-10-20T20:40:14Z",
"generated_at": "2021-11-19T19:51:49Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -135,15 +135,15 @@
"hashed_secret": "3438d9111af8058916e075b463bd7a6583cbf012",
"is_secret": false,
"is_verified": false,
"line_number": 247,
"line_number": 254,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "53213c46677ac6f5576c44a4cbbdbe186d67cb00",
"is_secret": false,
"is_verified": false,
"line_number": 249,
"line_number": 256,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ install:
- sudo chmod o+rwx /usr/lib/python3/dist-packages/
- python3 -m pip install -U pip
- pip3 install --upgrade "git+https://github.com/ibm/detect-secrets.git@master#egg=detect-secrets"
- curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $GOPATH/bin
- go get -u github.com/kardianos/govendor

before_script:
Expand All @@ -30,3 +31,4 @@ before_script:

script:
- go test $(go list ./... | grep -v "plugin_examples" | grep -v "vendor")
- gosec -exclude-dir=plugin_examples -exclude-dir=vendor -quiet ./...
10 changes: 5 additions & 5 deletions bluemix/authentication/iam/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const (

// Grant types
const (
GrantTypePassword authentication.GrantType = "password" // #nosec G101
GrantTypeAPIKey authentication.GrantType = "urn:ibm:params:oauth:grant-type:apikey" // #nosec G101
GrantTypePassword authentication.GrantType = "password" // #nosec G101
GrantTypeAPIKey authentication.GrantType = "urn:ibm:params:oauth:grant-type:apikey" // #nosec G101
GrantTypeOnetimePasscode authentication.GrantType = "urn:ibm:params:oauth:grant-type:passcode" // #nosec G101
GrantTypeAuthorizationCode authentication.GrantType = "authorization_code"
GrantTypeRefreshToken authentication.GrantType = "refresh_token"
Expand All @@ -45,9 +45,9 @@ const (
ResponseTypeDelegatedRefreshToken authentication.ResponseType = "delegated_refresh_token" // #nosec G101
)

const (
InvalidTokenErrorCode = "BXNIM0407E"
RefreshTokenExpiryErrorCode = "BXNIM0408E"
const (
InvalidTokenErrorCode = "BXNIM0407E" // #nosec G101
RefreshTokenExpiryErrorCode = "BXNIM0408E" // #nosec G101
ExternalAuthenticationErrorCode = "BXNIM0400E"
SessionInactiveErrorCode = "BXNIM0439E"
)
Expand Down
7 changes: 6 additions & 1 deletion common/downloader/file_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ func (d *FileDownloader) DownloadTo(url string, outputName string) (dest string,
if err != nil {
return dest, 0, err
}
defer func() { _ = f.Close() }()
/* #nosec G307 */
defer func() {
if err := f.Close(); err != nil {
fmt.Printf("Error closing file: %s\n", err)
}
}()

var r io.Reader = resp.Body
if d.ProxyReader != nil {
Expand Down
14 changes: 12 additions & 2 deletions common/file_helpers/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ func CopyFile(src string, dest string) (err error) {
if err != nil {
return
}
defer func() { _ = srcFile.Close() }()
/* #nosec G307 */
defer func() {
if err := srcFile.Close(); err != nil {
fmt.Printf("Error closing file: %s\n", err)
}
}()

srcStat, err := srcFile.Stat()
if err != nil {
Expand All @@ -51,7 +56,12 @@ func CopyFile(src string, dest string) (err error) {
if err != nil {
return
}
defer func() { _ = destFile.Close() }()
/* #nosec G307 */
defer func() {
if err := destFile.Close(); err != nil {
fmt.Printf("Error closing file: %s\n", err)
}
}()

err = os.Chmod(dest, srcStat.Mode())
if err != nil {
Expand Down
15 changes: 13 additions & 2 deletions common/file_helpers/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package file_helpers
import (
"archive/tar"
"compress/gzip"
"fmt"
"io"
"os"
"path/filepath"
Expand All @@ -14,7 +15,12 @@ func ExtractTgz(src string, dest string) error {
if err != nil {
return err
}
defer func() { _ = fd.Close() }()
/* #nosec G307 */
defer func() {
if err := fd.Close(); err != nil {
fmt.Printf("Error closing file: %s\n", err)
}
}()

gReader, err := gzip.NewReader(fd)
if err != nil {
Expand Down Expand Up @@ -62,7 +68,12 @@ func extractFileInArchive(r io.Reader, hdr *tar.Header, dest string) error {
if err != nil {
return err
}
defer func() { _ = f.Close() }()
/* #nosec G307 */
defer func() {
if err := f.Close(); err != nil {
fmt.Printf("Error closing file: %s\n", err)
}
}()

_, err = io.Copy(f, r)
return err
Expand Down