Skip to content

Commit c69ed19

Browse files
Anemona HanusAnemona Hanus
authored andcommitted
Address review comments: use RawURLEncoding and fix defer placement
1 parent 823c553 commit c69ed19

1 file changed

Lines changed: 2 additions & 17 deletions

File tree

pkg/detectors/adobeims/adobeims.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,7 @@ func decodeJWTPayload(token string) (*jwtPayload, error) {
7272
return nil, fmt.Errorf("not a JWT: expected 3 parts, got %d", len(parts))
7373
}
7474

75-
seg := parts[1]
76-
seg = strings.ReplaceAll(seg, "-", "+")
77-
seg = strings.ReplaceAll(seg, "_", "/")
78-
// Add back the '=' padding that base64url omits.
79-
// base64 strings must have a length that is a multiple of 4.
80-
switch len(seg) % 4 {
81-
case 2:
82-
seg += "=="
83-
case 3:
84-
seg += "="
85-
}
86-
87-
// Decode the base64 string into raw bytes.
88-
decoded, err := base64.StdEncoding.DecodeString(seg)
75+
decoded, err := base64.RawURLEncoding.DecodeString(parts[1])
8976
if err != nil {
9077
return nil, fmt.Errorf("base64 decode failed: %w", err)
9178
}
@@ -194,12 +181,10 @@ func validateToken(ctx context.Context, client *http.Client, baseURL, token stri
194181

195182
// Send the request to Adobe
196183
resp, err := client.Do(req)
197-
if resp != nil {
198-
defer resp.Body.Close()
199-
}
200184
if err != nil {
201185
return false, err
202186
}
187+
defer resp.Body.Close()
203188

204189
// Read the full response body into memory.
205190
body, err := io.ReadAll(resp.Body)

0 commit comments

Comments
 (0)