Skip to content

Commit 08bbc13

Browse files
Merge branch 'main' into feature/analyzer/added-figma-pat-analyzer
2 parents ff34e22 + 12164e3 commit 08bbc13

File tree

4 files changed

+270
-18
lines changed

4 files changed

+270
-18
lines changed

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require (
2929
github.com/aws/aws-sdk-go-v2/config v1.29.6
3030
github.com/aws/aws-sdk-go-v2/credentials v1.17.59
3131
github.com/aws/aws-sdk-go-v2/service/sns v1.33.19
32+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.14
3233
github.com/aymanbagabas/go-osc52 v1.2.1
3334
github.com/bill-rich/go-syslog v0.0.0-20220413021637-49edb52a574c
3435
github.com/bitfinexcom/bitfinex-api-go v0.0.0-20210608095005-9e0b26f200fb
@@ -107,11 +108,12 @@ require (
107108
go.uber.org/automaxprocs v1.6.0
108109
go.uber.org/mock v0.5.0
109110
go.uber.org/zap v1.27.0
110-
golang.org/x/crypto v0.32.0
111-
golang.org/x/net v0.34.0
111+
golang.org/x/crypto v0.35.0
112+
golang.org/x/net v0.36.0
112113
golang.org/x/oauth2 v0.25.0
113114
golang.org/x/sync v0.11.0
114115
golang.org/x/text v0.22.0
116+
golang.org/x/time v0.8.0
115117
google.golang.org/api v0.214.0
116118
google.golang.org/protobuf v1.36.5
117119
gopkg.in/h2non/gock.v1 v1.1.2
@@ -160,7 +162,6 @@ require (
160162
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.13 // indirect
161163
github.com/aws/aws-sdk-go-v2/service/sso v1.24.15 // indirect
162164
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.14 // indirect
163-
github.com/aws/aws-sdk-go-v2/service/sts v1.33.14 // indirect
164165
github.com/aws/smithy-go v1.22.2 // indirect
165166
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
166167
github.com/aymerick/douceur v0.2.0 // indirect
@@ -324,7 +325,6 @@ require (
324325
golang.org/x/mod v0.22.0 // indirect
325326
golang.org/x/sys v0.30.0 // indirect
326327
golang.org/x/term v0.29.0 // indirect
327-
golang.org/x/time v0.8.0 // indirect
328328
golang.org/x/tools v0.29.0 // indirect
329329
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
330330
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v
877877
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
878878
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
879879
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
880+
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
881+
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
880882
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
881883
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
882884
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -944,6 +946,8 @@ golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
944946
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
945947
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
946948
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
949+
golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA=
950+
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
947951
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
948952
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
949953
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

pkg/analyzer/analyzers/anthropic/anthropic.go

+38-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package anthropic
44
import (
55
"errors"
66
"os"
7+
"strings"
78

89
"github.com/fatih/color"
910
"github.com/jedib0t/go-pretty/v6/table"
@@ -17,7 +18,8 @@ var _ analyzers.Analyzer = (*Analyzer)(nil)
1718

1819
const (
1920
// Key Types
20-
APIKey = "API-Key"
21+
APIKey = "API-Key"
22+
AdminKey = "Admin-Key"
2123
)
2224

2325
type Analyzer struct {
@@ -28,7 +30,6 @@ type Analyzer struct {
2830
type SecretInfo struct {
2931
Valid bool
3032
Type string // key type - TODO: Handle Anthropic Admin Keys
31-
Reference string
3233
AnthropicResources []AnthropicResource
3334
Permissions string // always full_access
3435
Misc map[string]string
@@ -39,6 +40,7 @@ type AnthropicResource struct {
3940
ID string
4041
Name string
4142
Type string
43+
Parent *AnthropicResource
4244
Metadata map[string]string
4345
}
4446

@@ -73,7 +75,7 @@ func AnalyzeAndPrintPermissions(cfg *config.Config, key string) {
7375
}
7476

7577
if info.Valid {
76-
color.Green("[!] Valid Anthropic API key\n\n")
78+
color.Green("[!] Valid Anthropic %s\n\n", info.Type)
7779
// no user information
7880
// print full access permission
7981
printPermission(info.Permissions)
@@ -88,16 +90,23 @@ func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) {
8890
// create a HTTP client
8991
client := analyzers.NewAnalyzeClient(cfg)
9092

91-
var secretInfo = &SecretInfo{
92-
Type: APIKey, // TODO: implement Admin-Key type as well
93-
}
93+
keyType := getKeyType(key)
9494

95-
if err := listModels(client, key, secretInfo); err != nil {
96-
return nil, err
95+
var secretInfo = &SecretInfo{
96+
Type: keyType,
9797
}
9898

99-
if err := listMessageBatches(client, key, secretInfo); err != nil {
100-
return nil, err
99+
switch keyType {
100+
case APIKey:
101+
if err := captureAPIKeyResources(client, key, secretInfo); err != nil {
102+
return nil, err
103+
}
104+
case AdminKey:
105+
if err := captureAdminKeyResources(client, key, secretInfo); err != nil {
106+
return nil, err
107+
}
108+
default:
109+
return nil, errors.New("unsupported key type")
101110
}
102111

103112
// anthropic key has full access only
@@ -133,6 +142,14 @@ func secretInfoToAnalyzerResult(info *SecretInfo) *analyzers.AnalyzerResult {
133142
},
134143
}
135144

145+
if Anthropicresource.Parent != nil {
146+
binding.Resource.Parent = &analyzers.Resource{
147+
Name: Anthropicresource.Parent.Name,
148+
FullyQualifiedName: Anthropicresource.Parent.ID,
149+
Type: Anthropicresource.Parent.Type,
150+
}
151+
}
152+
136153
for key, value := range Anthropicresource.Metadata {
137154
binding.Resource.Metadata[key] = value
138155
}
@@ -162,3 +179,14 @@ func printAnthropicResources(resources []AnthropicResource) {
162179
}
163180
t.Render()
164181
}
182+
183+
// getKeyType return the type of key
184+
func getKeyType(key string) string {
185+
if strings.Contains(key, "sk-ant-admin01") {
186+
return AdminKey
187+
} else if strings.Contains(key, "sk-ant-api03") {
188+
return APIKey
189+
}
190+
191+
return ""
192+
}

0 commit comments

Comments
 (0)