Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Updated OpenAI Analyzer (#4203)
Kashif Khand1feae129670
diff --git a/pkg/analyzer/analyzers/openai/openai.go b/pkg/analyzer/analyzers/openai/openai.goindex e658a5f86..41103dcd8 100644--- a/pkg/analyzer/analyzers/openai/openai.go+++ b/pkg/analyzer/analyzers/openai/openai.go@@ -38,6 +38,7 @@ func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyfunc secretInfoToAnalyzerResult(info *AnalyzerJSON) *analyzers.AnalyzerResult {result := analyzers.AnalyzerResult{+ AnalyzerType: analyzers.AnalyzerTypeOpenAI,Metadata: map[string]any{"user": info.me.Name,"email": info.me.Email,diff --git a/pkg/analyzer/analyzers/openai/openai_test.go b/pkg/analyzer/analyzers/openai/openai_test.goindex 94365d9dc..36ebaf2ce 100644--- a/pkg/analyzer/analyzers/openai/openai_test.go+++ b/pkg/analyzer/analyzers/openai/openai_test.go@@ -1,6 +1,7 @@package openaiimport (+ _ "embed""encoding/json""testing""time"@@ -11,6 +12,9 @@ import ("github.com/trufflesecurity/trufflehog/v3/pkg/context")+//go:embed result_output.json+var expectedOutput []byte+func TestAnalyzer_Analyze(t *testing.T) {ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)defer cancel()@@ -22,59 +26,13 @@ func TestAnalyzer_Analyze(t *testing.T) {tests := []struct {name stringkey string- want string // JSON string+ want []bytewantErr bool}{{- name: "valid OpenAI key",- key: testSecrets.MustGetField("OPENAI_VERIFIED"),- want: `{- "AnalyzerType": 0,- "Bindings": [- {- "Resource": {- "Name": "Truffle Security Co",- "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",- "Type": "organization",- "Metadata": {- "description": "Personal org for [email protected]",- "user": "truffle-security-co"- },- "Parent": null- },- "Permission": {- "Value": "full_access",- "AccessLevel": "",- "Parent": null- }- },- {- "Resource": {- "Name": "Personal",- "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",- "Type": "organization",- "Metadata": {- "description": "Personal org for [email protected]",- "user": "user-ohfap0ky8lkatw97iskuhghv"- },- "Parent": null- },- "Permission": {- "Value": "full_access",- "AccessLevel": "",- "Parent": null- }- }- ],- "UnboundedResources": null,- "Metadata": {- "email": "[email protected]",- "is_admin": "true",- "is_restricted": "false",- "mfa": "true",- "user": "Dustin Decker"- }- }`,+ name: "valid OpenAI key",+ key: testSecrets.MustGetField("OPENAI_VERIFIED"),+ want: expectedOutput,wantErr: false,},}diff --git a/pkg/analyzer/analyzers/openai/permissions.go b/pkg/analyzer/analyzers/openai/permissions.goindex d26d557c9..730f776c8 100644--- a/pkg/analyzer/analyzers/openai/permissions.go+++ b/pkg/analyzer/analyzers/openai/permissions.go@@ -17,6 +17,10 @@ const (FineTuningWrite Permission = iotaFilesRead Permission = iotaFilesWrite Permission = iota+ EvalsRead Permission = iota+ EvalsWrite Permission = iota+ ResponsesRead Permission = iota+ ResponsesWrite Permission = iota)var (@@ -31,6 +35,10 @@ var (FineTuningWrite: "fine_tuning:write",FilesRead: "files:read",FilesWrite: "files:write",+ EvalsRead: "evals:read",+ EvalsWrite: "evals:write",+ ResponsesRead: "responses:read",+ ResponsesWrite: "responses:write",}StringToPermission = map[string]Permission{@@ -44,6 +52,10 @@ var ("fine_tuning:write": FineTuningWrite,"files:read": FilesRead,"files:write": FilesWrite,+ "evals:read": EvalsRead,+ "evals:write": EvalsWrite,+ "responses:read": ResponsesRead,+ "responses:write": ResponsesWrite,}PermissionIDs = map[Permission]int{@@ -57,6 +69,10 @@ var (FineTuningWrite: 8,FilesRead: 9,FilesWrite: 10,+ EvalsRead: 11,+ EvalsWrite: 12,+ ResponsesRead: 13,+ ResponsesWrite: 14,}IdToPermission = map[int]Permission{@@ -70,6 +86,10 @@ var (8: FineTuningWrite,9: FilesRead,10: FilesWrite,+ 11: EvalsRead,+ 12: EvalsWrite,+ 13: ResponsesRead,+ 14: ResponsesWrite,})diff --git a/pkg/analyzer/analyzers/openai/permissions.yaml b/pkg/analyzer/analyzers/openai/permissions.yamlindex 4efd163b5..56a6d5220 100644--- a/pkg/analyzer/analyzers/openai/permissions.yaml+++ b/pkg/analyzer/analyzers/openai/permissions.yaml@@ -9,3 +9,7 @@ permissions:- fine_tuning:write- files:read- files:write+- evals:read+- evals:write+- responses:read+- responses:writediff --git a/pkg/analyzer/analyzers/openai/result_output.json b/pkg/analyzer/analyzers/openai/result_output.jsonnew file mode 100644index 000000000..c667284f3--- /dev/null+++ b/pkg/analyzer/analyzers/openai/result_output.json@@ -0,0 +1,461 @@+{+ "AnalyzerType": 13,+ "Bindings": [+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "models:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "model_capabilities:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "assistants:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "assistants:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "threads:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "threads:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "fine_tuning:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "fine_tuning:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "files:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "files:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "evals:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "evals:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "responses:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Truffle Security Co",+ "FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "truffle-security-co"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "responses:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "models:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "model_capabilities:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "assistants:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "assistants:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "threads:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "threads:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "fine_tuning:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "fine_tuning:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "files:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "files:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "evals:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "evals:write",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "responses:read",+ "Parent": null+ }+ },+ {+ "Resource": {+ "Name": "Personal",+ "FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",+ "Type": "organization",+ "Metadata": {+ "description": "Personal org for [email protected]",+ "user": "user-ohfap0ky8lkatw97iskuhghv"+ },+ "Parent": null+ },+ "Permission": {+ "Value": "responses:write",+ "Parent": null+ }+ }+ ],+ "UnboundedResources": null,+ "Metadata": {+ "email": "[email protected]",+ "is_admin": "false",+ "is_restricted": "true",+ "mfa": "true",+ "user": "Dustin Decker"+ }+}\ No newline at end of filediff --git a/pkg/analyzer/analyzers/openai/scopes.go b/pkg/analyzer/analyzers/openai/scopes.goindex ca8d5a987..36ca9e538 100644--- a/pkg/analyzer/analyzers/openai/scopes.go+++ b/pkg/analyzer/analyzers/openai/scopes.go@@ -91,4 +91,26 @@ var SCOPES = []OpenAIScope{ReadPermission: FilesRead,WritePermission: FilesWrite,},+ {+ ReadTests: []analyzers.HttpStatusTest{+ {URL: BASE_URL + "/v1/evals", Method: "GET", Valid: []int{200}, Invalid: []int{401}, Type: analyzers.READ, Status: analyzers.PermissionStatus{}},+ },+ WriteTests: []analyzers.HttpStatusTest{+ {URL: BASE_URL + "/v1/evals", Method: "POST", Payload: POST_PAYLOAD, Valid: []int{400}, Invalid: []int{401}, Type: analyzers.WRITE, Status: analyzers.PermissionStatus{}},+ },+ Endpoints: []string{"/v1/evals"},+ ReadPermission: EvalsRead,+ WritePermission: EvalsWrite,+ },+ {+ ReadTests: []analyzers.HttpStatusTest{+ {URL: BASE_URL + "/v1/responses/1", Method: "GET", Valid: []int{400}, Invalid: []int{401}, Type: analyzers.READ, Status: analyzers.PermissionStatus{}},+ },+ WriteTests: []analyzers.HttpStatusTest{+ {URL: BASE_URL + "/v1/responses", Method: "POST", Payload: POST_PAYLOAD, Valid: []int{400}, Invalid: []int{401}, Type: analyzers.WRITE, Status: analyzers.PermissionStatus{}},+ },+ Endpoints: []string{"/v1/responses"},+ ReadPermission: ResponsesRead,+ WritePermission: ResponsesWrite,+ },}