@@ -13,18 +13,25 @@ import (
13
13
"strconv"
14
14
"strings"
15
15
16
- "github.com/snyk/cli/cliv2/internal/cliv2"
17
- "github.com/snyk/cli/cliv2/internal/utils"
18
16
"github.com/snyk/error-catalog-golang-public/snyk_errors"
19
17
"github.com/snyk/go-application-framework/pkg/auth"
20
18
"github.com/snyk/go-application-framework/pkg/configuration"
21
19
"github.com/snyk/go-application-framework/pkg/local_workflows/config_utils"
22
20
21
+ "github.com/snyk/cli/cliv2/internal/cliv2"
22
+ "github.com/snyk/cli/cliv2/internal/utils"
23
+
23
24
localworkflows "github.com/snyk/go-application-framework/pkg/local_workflows"
24
25
"github.com/snyk/go-application-framework/pkg/networking"
25
26
"github.com/snyk/go-application-framework/pkg/networking/fips"
26
27
)
27
28
29
+ func redactAuthorizationTokens (token string ) string {
30
+ temp := sha256 .Sum256 ([]byte (token ))
31
+ tokenShaSum := fmt .Sprintf ("%s***%s" , hex .EncodeToString (temp [0 :4 ]), hex .EncodeToString (temp [12 :16 ]))
32
+ return tokenShaSum
33
+ }
34
+
28
35
func logHeaderAuthorizationInfo (
29
36
config configuration.Configuration ,
30
37
networkAccess networking.NetworkAccess ,
@@ -47,18 +54,16 @@ func logHeaderAuthorizationInfo(
47
54
if len (splitHeader ) == 2 {
48
55
tokenType := splitHeader [0 ]
49
56
token := splitHeader [1 ]
50
- temp := sha256 .Sum256 ([]byte (token ))
51
- tokenShaSum = hex .EncodeToString (temp [0 :16 ]) + "[...]"
57
+ tokenShaSum = redactAuthorizationTokens (token )
52
58
tokenDetails = fmt .Sprintf (" (type=%s)" , tokenType )
53
59
}
54
60
55
61
if config .GetBool (configuration .FF_OAUTH_AUTH_FLOW_ENABLED ) {
56
62
oauthEnabled = "Enabled"
57
63
token , err := auth .GetOAuthToken (config )
58
64
if token != nil && err == nil {
65
+ tokenShaSum = redactAuthorizationTokens (token .AccessToken )
59
66
tokenDetails = fmt .Sprintf (" (type=oauth; expiry=%v)" , token .Expiry .UTC ())
60
- temp := sha256 .Sum256 ([]byte (token .AccessToken ))
61
- tokenShaSum = hex .EncodeToString (temp [0 :16 ]) + "[...]"
62
67
}
63
68
}
64
69
0 commit comments