Skip to content

Commit 8b97ef5

Browse files
committed
Fix gosec linter issues and upgrade go.step.sm/crypto to v0.76.2
1 parent 3c47ad7 commit 8b97ef5

18 files changed

Lines changed: 47 additions & 39 deletions

File tree

command/api/token/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func createAction(ctx *cli.Context) (err error) {
120120
client := http.Client{
121121
Transport: transport,
122122
}
123-
resp, err := client.Do(post)
123+
resp, err := client.Do(post) // #nosec G704 -- request depends on configuration
124124
if err != nil {
125125
return err
126126
}

command/ca/acme/eab/list.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"os"
77
"os/exec"
8+
"strings"
89

910
"github.com/pkg/errors"
1011
"github.com/urfave/cli"
@@ -99,8 +100,16 @@ func listAction(ctx *cli.Context) (err error) {
99100

100101
// prepare the $PAGER command to run when not disabled and when available
101102
pager := os.Getenv("PAGER")
103+
if strings.ContainsAny(pager, " \t\n;&|<>") {
104+
return errors.New("invalid PAGER environment value")
105+
}
106+
107+
if _, err := exec.LookPath(pager); err != nil {
108+
return fmt.Errorf("invalid PAGER environment value: %w", err)
109+
}
110+
102111
if usePager && pager != "" {
103-
cmd = exec.Command(pager)
112+
cmd = exec.Command(pager) // #nosec G702 -- $PAGER is intended to be provided by users; basic validation applied
104113
var err error
105114
out, err = cmd.StdinPipe()
106115
if err != nil {

command/ca/provisioner/add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func addCommand() cli.Command {
31-
return cli.Command{
31+
return cli.Command{ // #nosec G101 -- Google OIDC example values
3232
Name: "add",
3333
Action: cli.ActionFunc(addAction),
3434
Usage: "add a provisioner",

command/certificate/verify.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ func verifyAction(ctx *cli.Context) error {
250250

251251
switch {
252252
case (verifyCRL || verifyOCSP) && roots != "":
253-
//nolint:gosec // using default configuration for 3rd party endpoints
254253
tlsConfig := &tls.Config{
255254
RootCAs: rootPool,
256255
}
@@ -389,7 +388,7 @@ func VerifyOCSPEndpoint(endpoint string, cert, issuer *x509.Certificate, httpCli
389388
return false, errors.Errorf("error contacting OCSP server: %s", endpoint)
390389
}
391390
httpReq.Header.Add("Content-Type", "application/ocsp-request")
392-
httpResp, err := httpClient.Do(httpReq)
391+
httpResp, err := httpClient.Do(httpReq) // #nosec G704 -- request relies on values from certificate or intentionally provided by user
393392
if err != nil {
394393
return false, errors.Errorf("error contacting OCSP server: %s", endpoint)
395394
}

command/crypto/jwk/keyset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func rwLockKeySet(filename string) (jwks *jose.JSONWebKeySet, writeFunc func(boo
234234
return
235235
}
236236

237-
fd := int(f.Fd())
237+
fd := int(f.Fd()) // #nosec G115 -- uintptr comes from file descriptor
238238

239239
// non-blocking exclusive lock
240240
err = sysutils.FileLock(fd)

command/crypto/winpe/winpe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func extractPEAction(ctx *cli.Context) error {
6767
}
6868

6969
func extractPE(filename string) error {
70-
file, err := os.Open(filename)
70+
file, err := os.Open(filename) // #nosec G703 -- file to open intentionally relies on user configuration
7171
if err != nil {
7272
return errors.Wrapf(err, "error opening %s", filename)
7373
}

command/oauth/cmd.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ const (
6666
)
6767

6868
type token struct {
69-
AccessToken string `json:"access_token"`
69+
AccessToken string `json:"access_token"` // #nosec G117 -- JSON property
7070
IDToken string `json:"id_token"`
71-
RefreshToken string `json:"refresh_token"`
71+
RefreshToken string `json:"refresh_token"` // #nosec G117 -- JSON property
7272
ExpiresIn int `json:"expires_in"`
7373
TokenType string `json:"token_type"`
7474
Err string `json:"error,omitempty"`
@@ -571,13 +571,13 @@ type endpoint struct {
571571
}
572572

573573
var knownProviders = map[string]endpoint{
574-
"google": {
574+
"google": { // #nosec G101 -- no credentials; just well-known configuration values
575575
authorization: "https://accounts.google.com/o/oauth2/v2/auth",
576576
deviceAuthorization: "https://oauth2.googleapis.com/device/code",
577577
token: "https://www.googleapis.com/oauth2/v4/token",
578578
userInfo: "https://www.googleapis.com/oauth2/v3/userinfo",
579579
},
580-
"github": {
580+
"github": { // #nosec G101 -- no credentials; just well-known configuration values
581581
authorization: "https://github.com/login/oauth/authorize",
582582
deviceAuthorization: "https://github.com/login/device/code",
583583
token: "https://github.com/login/oauth/access_token",
@@ -712,7 +712,7 @@ func disco(provider string) (map[string]interface{}, error) {
712712
// application/json", without this header GitHub will use
713713
// application/x-www-form-urlencoded.
714714
func postForm(rawurl string, data url.Values) (*http.Response, error) {
715-
req, err := http.NewRequest("POST", rawurl, strings.NewReader(data.Encode()))
715+
req, err := http.NewRequest("POST", rawurl, strings.NewReader(data.Encode())) // #nosec G704 -- request intentionally relies on user data
716716
if err != nil {
717717
return nil, fmt.Errorf("create POST %s request failed: %w", rawurl, err)
718718
}
@@ -722,7 +722,7 @@ func postForm(rawurl string, data url.Values) (*http.Response, error) {
722722

723723
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
724724
req.Header.Set("Accept", "application/json")
725-
return http.DefaultClient.Do(req)
725+
return http.DefaultClient.Do(req) // #nosec G704 -- request intentionally relies on user configuration
726726
}
727727

728728
// NewServer creates http server
@@ -1106,7 +1106,7 @@ func (o *oauth) ServeHTTP(w http.ResponseWriter, req *http.Request) {
11061106

11071107
code, state := q.Get("code"), q.Get("state")
11081108
if code == "" || state == "" {
1109-
fmt.Fprintf(os.Stderr, "Invalid request received: http://%s%s\n", req.RemoteAddr, req.URL.String())
1109+
fmt.Fprintf(os.Stderr, "Invalid request received: http://%s%s\n", req.RemoteAddr, req.URL.String()) // #nosec G705 -- terminal output
11101110
fmt.Fprintf(os.Stderr, "You may have an app or browser plugin that needs to be turned off\n")
11111111
http.Error(w, "400 bad request", http.StatusBadRequest)
11121112
return

exec/exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func RunWithPid(pidFile, name string, arg ...string) {
7979
cmd, exitCh, err := run(name, arg...)
8080
if err != nil {
8181
f.Close()
82-
os.Remove(f.Name())
82+
_ = os.Remove(f.Name()) // #nosec G703 -- file does not depend on user configuration
8383
errorAndExit(name, err)
8484
}
8585

@@ -94,7 +94,7 @@ func RunWithPid(pidFile, name string, arg ...string) {
9494
}
9595

9696
// clean, exit and wait until os.Exit
97-
os.Remove(f.Name())
97+
_ = os.Remove(f.Name()) // #nosec G703 -- file does not depend on user configuration
9898
exitCh <- getExitStatus(cmd)
9999
exitCh <- 0
100100
}

internal/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func panicHandler() {
163163

164164
fmt.Fprintln(os.Stderr, "Something unexpected happened.")
165165
fmt.Fprintln(os.Stderr, "If you want to help us debug the problem, please run:")
166-
fmt.Fprintf(os.Stderr, "STEPDEBUG=1 %s\n", strings.Join(os.Args, " "))
166+
fmt.Fprintf(os.Stderr, "STEPDEBUG=1 %q\n", strings.Join(os.Args, " ")) // #nosec G705 -- terminal output
167167
fmt.Fprintln(os.Stderr, "and send the output to info@smallstep.com")
168168
os.Exit(2)
169169
}

internal/plugin/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func LookPath(name string) (string, error) {
3838
}
3939
for _, ext := range exts {
4040
path := filepath.Join(step.BasePath(), "plugins", fileName+ext)
41-
if _, err := os.Stat(path); err == nil {
41+
if _, err := os.Stat(path); err == nil { // #nosec G703 -- path to stat intentionally relies on (partial) user configuration
4242
return path, nil
4343
}
4444
}

0 commit comments

Comments
 (0)