Skip to content

Find, verify, and analyze leaked credentials

Feature: Airtable Analyzer for Personal Access Tokens (#3941)

Nabeel Alam59c6f2d1b279
diff --git a/pkg/analyzer/analyzers/airtable/airtableoauth/airtable.go b/pkg/analyzer/analyzers/airtable/airtableoauth/airtable.go
new file mode 100644
index 000000000..d54c589c2
--- /dev/null
+++ b/pkg/analyzer/analyzers/airtable/airtableoauth/airtable.go
@@ -0,0 +1,79 @@
+package airtableoauth
+
+import (
+ "errors"
+
+ "github.com/fatih/color"
+
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/airtable/common"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/config"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/context"
+)
+
+var _ analyzers.Analyzer = (*Analyzer)(nil)
+
+type Analyzer struct {
+ Cfg *config.Config
+}
+
+func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeAirtableOAuth }
+
+func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) {
+ token, ok := credInfo["token"]
+ if !ok {
+ return nil, errors.New("token not found in credInfo")
+ }
+
+ userInfo, err := common.FetchAirtableUserInfo(token)
+ if err != nil {
+ return nil, err
+ }
+
+ var basesInfo *common.AirtableBases
+ baseScope := common.PermissionStrings[common.SchemaBasesRead]
+ if hasScope(userInfo.Scopes, baseScope) {
+ basesInfo, _ = common.FetchAirtableBases(token)
+ }
+
+ return common.MapToAnalyzerResult(userInfo, basesInfo), nil
+}
+
+func AnalyzeAndPrintPermissions(cfg *config.Config, token string) {
+ userInfo, err := common.FetchAirtableUserInfo(token)
+ if err != nil {
+ color.Red("[x] Error : %s", err.Error())
+ return
+ }
+
+ color.Green("[!] Valid Airtable OAuth2 Access Token\n\n")
+ printUserAndPermissions(userInfo)
+
+ baseScope := common.PermissionStrings[common.SchemaBasesRead]
+ if hasScope(userInfo.Scopes, baseScope) {
+ var basesInfo *common.AirtableBases
+ basesInfo, _ = common.FetchAirtableBases(token)
+ common.PrintBases(basesInfo)
+ }
+}
+
+func hasScope(scopes []string, target string) bool {
+ for _, scope := range scopes {
+ if scope == target {
+ return true
+ }
+ }
+ return false
+}
+
+func printUserAndPermissions(info *common.AirtableUserInfo) {
+ scopeStatusMap := make(map[string]bool)
+ for _, scope := range common.PermissionStrings {
+ scopeStatusMap[scope] = false
+ }
+ for _, scope := range info.Scopes {
+ scopeStatusMap[scope] = true
+ }
+
+ common.PrintUserAndPermissions(info, scopeStatusMap)
+}
diff --git a/pkg/analyzer/analyzers/airtable/airtable_test.go b/pkg/analyzer/analyzers/airtable/airtableoauth/airtable_test.go
similarity index 99%
rename from pkg/analyzer/analyzers/airtable/airtable_test.go
rename to pkg/analyzer/analyzers/airtable/airtableoauth/airtable_test.go
index 6b14814df..402cbf5ac 100644
--- a/pkg/analyzer/analyzers/airtable/airtable_test.go
+++ b/pkg/analyzer/analyzers/airtable/airtableoauth/airtable_test.go
@@ -1,4 +1,4 @@
-package airtable
+package airtableoauth
import (
_ "embed"
diff --git a/pkg/analyzer/analyzers/airtable/expected_output.json b/pkg/analyzer/analyzers/airtable/airtableoauth/expected_output.json
similarity index 94%
rename from pkg/analyzer/analyzers/airtable/expected_output.json
rename to pkg/analyzer/analyzers/airtable/airtableoauth/expected_output.json
index 133a704e0..43e6fda2b 100644
--- a/pkg/analyzer/analyzers/airtable/expected_output.json
+++ b/pkg/analyzer/analyzers/airtable/airtableoauth/expected_output.json
@@ -1,5 +1,5 @@
{
- "AnalyzerType": 22,
+ "AnalyzerType": 28,
"Bindings": [
{
"Resource": {
diff --git a/pkg/analyzer/analyzers/airtable/airtablepat/airtable.go b/pkg/analyzer/analyzers/airtable/airtablepat/airtable.go
new file mode 100644
index 000000000..4b5fca66c
--- /dev/null
+++ b/pkg/analyzer/analyzers/airtable/airtablepat/airtable.go
@@ -0,0 +1,240 @@
+package airtablepat
+
+import (
+ _ "embed"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "strings"
+
+ "github.com/fatih/color"
+
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/airtable/common"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/config"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/context"
+)
+
+var _ analyzers.Analyzer = (*Analyzer)(nil)
+
+type Analyzer struct {
+ Cfg *config.Config
+}
+
+func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeAirtablePat }
+
+var scopeStatusMap = make(map[string]bool)
+
+func getEndpoint(endpointName common.EndpointName) (common.Endpoint, bool) {
+ return common.GetEndpoint(endpointName)
+}
+
+func getScopeEndpoint(scope string) (common.Endpoint, bool) {
+ return common.GetScopeEndpoint(scope)
+}
+
+func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) {
+ token, ok := credInfo["token"]
+ if !ok {
+ return nil, errors.New("token not found in credInfo")
+ }
+
+ userInfo, err := common.FetchAirtableUserInfo(token)
+ if err != nil {
+ return nil, err
+ }
+
+ scopeStatusMap[common.PermissionStrings[common.UserEmailRead]] = userInfo.Email != nil
+
+ var basesInfo *common.AirtableBases
+ granted, err := determineScope(token, common.SchemaBasesRead, nil)
+ if err != nil {
+ return nil, err
+ }
+ if granted {
+ basesInfo, err = common.FetchAirtableBases(token)
+ if err != nil {
+ return nil, err
+ }
+ // If bases are fetched, determine the token scopes
+ err := determineScopes(token, basesInfo)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ return mapToAnalyzerResult(userInfo, basesInfo), nil
+}
+
+func AnalyzeAndPrintPermissions(cfg *config.Config, token string) {
+ userInfo, err := common.FetchAirtableUserInfo(token)
+ if err != nil {
+ color.Red("[x] Error : %s", err.Error())
+ return
+ }
+
+ scopeStatusMap[common.PermissionStrings[common.UserEmailRead]] = userInfo.Email != nil
+
+ var basesInfo *common.AirtableBases
+ basesReadPermission := common.SchemaBasesRead
+ if granted, err := determineScope(token, basesReadPermission, nil); granted {
+ if err != nil {
+ color.Red("[x] Error : %s", err.Error())
+ return
+ }
+ basesInfo, _ = common.FetchAirtableBases(token)
+ err := determineScopes(token, basesInfo)
+ if err != nil {
+ color.Red("[x] Error : %s", err.Error())
+ return
+ }
+ }
+
+ color.Green("[!] Valid Airtable Personal Access Token\n\n")
+
+ common.PrintUserAndPermissions(userInfo, scopeStatusMap)
+ if scopeStatusMap[common.PermissionStrings[basesReadPermission]] {
+ common.PrintBases(basesInfo)
+ }
+}
+
+// determineScope checks whether the given token has the specified permission by making an API call.
+//
+// The function performs the following actions:
+// - Determines the appropriate API Endpoint based on the input scope/permission.
+// - Constructs an HTTP request using the endpoint's URL, method, and required IDs.
+// If the URL contains path parameters (e.g., "{baseID}"), they must be replaced using `requiredIDs`.
+// - Sends the request and analyzes the response to determine if the token has the requested permission.
+//
+// Returns `true` if the token has the permission, `false` otherwise.
+// If an error occurs, it returns false along with the encountered error.
+func determineScope(token string, perm common.Permission, requiredIDs map[string]string) (bool, error) {
+ scopeString := common.PermissionStrings[perm]
+ endpoint, exists := getScopeEndpoint(scopeString)
+ if !exists {
+ return false, nil
+ }
+
+ url := endpoint.URL
+ if requiredIDs != nil {
+ for _, key := range endpoint.RequiredIDs {
+ if value, ok := requiredIDs[key]; ok {
+ url = strings.Replace(url, fmt.Sprintf("{%s}", key), value, -1)
+ }
+ }
+ }
+
+ resp, err := common.CallAirtableAPI(token, endpoint.Method, url)
+ if err != nil {
+ return false, err
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode == endpoint.ExpectedSuccessStatus {
+ scopeStatusMap[scopeString] = true
+ return true, nil
+ }
+
+ // If the response status is not 200 OK, we need to verify if the error is as expected
+ if endpoint.ExpectedErrorResponse != nil {
+ var result map[string]any
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return false, err
+ }
+
+ errorInfo, ok := result["error"].(map[string]any)
+ if !ok {
+ // If no error is found in the response, the scope is unverified
+ return false, nil
+ }
+ errorType, ok := errorInfo["type"].(string)
+ if !ok || errorType != endpoint.ExpectedErrorResponse.Type {
+ // If "type" is missing from the error body, or mismatches the expected type, the scope is unverified
+ return false, nil
+ }
+
+ // The token lacks the scope/permission to fulfill the request
+ scopeStatusMap[scopeString] = false
+ return false, nil
+ }
+
+ // Can not determine scope as the expected error is unknown
+ return false, nil
+}
+
+func determineScopes(token string, basesInfo *common.AirtableBases) error {
+ if basesInfo == nil || len(basesInfo.Bases) == 0 {
+ return nil
+ }
+
+ for _, base := range basesInfo.Bases {
+ requiredIDs := map[string]string{"baseID": base.ID}
+ tableScopesDetermined := false
+
+ // Verify token "webhooks:manage" permission
+ _, err := determineScope(token, common.WebhookManage, requiredIDs)
+ if err != nil {
+ return err
+ }
+ // Verify token "block:manage" permission
+ _, err = determineScope(token, common.BlockManage, requiredIDs)
+ if err != nil {
+ return err
+ }
+
+ if base.Schema == nil || len(base.Schema.Tables) == 0 {
+ return nil
+ }
+
+ // Verifying scopes that require an existing table
+ for _, table := range base.Schema.Tables {
+ requiredIDs["tableID"] = table.ID
+
+ if !tableScopesDetermined {
+ _, err = determineScope(token, common.SchemaBasesWrite, requiredIDs)
+ if err != nil {
+ return err
+ }
+ _, err = determineScope(token, common.DataRecordsWrite, requiredIDs)
+ if err != nil {
+ return err
+ }
+ tableScopesDetermined = true
+ }
+
+ granted, err := determineScope(token, common.DataRecordsRead, requiredIDs)
+ if err != nil {
+ return err
+ }
+ if !granted {
+ continue
+ }
+ // Verifying scopes that require an existing "record" and the "data records read" permission
+ records, err := fetchAirtableRecords(token, base.ID, table.ID)
+ if err != nil {
+ return err
+ }
+ for _, record := range records {
+ requiredIDs["recordID"] = record.ID
+ _, err = determineScope(token, common.DataRecordcommentsRead, requiredIDs)
+ if err != nil {
+ return err
+ }
+ break
+ }
+ if len(records) != 0 {
+ break
+ }
+ }
+ }
+ return nil
+}
+
+func mapToAnalyzerResult(userInfo *common.AirtableUserInfo, basesInfo *common.AirtableBases) *analyzers.AnalyzerResult {
+ for scope, status := range scopeStatusMap {
+ if status {
+ userInfo.Scopes = append(userInfo.Scopes, scope)
+ }
+ }
+ return common.MapToAnalyzerResult(userInfo, basesInfo)
+}
diff --git a/pkg/analyzer/analyzers/airtable/airtablepat/airtable_test.go b/pkg/analyzer/analyzers/airtable/airtablepat/airtable_test.go
new file mode 100644
index 000000000..33cd6f74e
--- /dev/null
+++ b/pkg/analyzer/analyzers/airtable/airtablepat/airtable_test.go
@@ -0,0 +1,100 @@
+package airtablepat
+
+import (
+ _ "embed"
+ "encoding/json"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/config"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/context"
+)
+
+//go:embed expected_output.json
+var expectedOutput []byte
+
+func TestAnalyzer_Analyze(t *testing.T) {
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
+ defer cancel()
+ testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors5")
+ if err != nil {
+ t.Fatalf("could not get test secrets from GCP: %s", err)
+ }
+
+ tests := []struct {
+ name string
+ token string
+ want string // JSON string
+ wantErr bool
+ }{
+ {
+ token: testSecrets.MustGetField("AIRTABLEOAUTH_TOKEN"),
+ name: "valid Airtable Personal Access Token",
+ want: string(expectedOutput),
+ wantErr: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ a := Analyzer{Cfg: &config.Config{}}
+ got, err := a.Analyze(ctx, map[string]string{"token": tt.token})
+ if (err != nil) != tt.wantErr {
+ t.Errorf("Analyzer.Analyze() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+
+ // bindings need to be in the same order to be comparable
+ sortBindings(got.Bindings)
+
+ // Marshal the actual result to JSON
+ gotJSON, err := json.Marshal(got)
+ if err != nil {
+ t.Fatalf("could not marshal got to JSON: %s", err)
+ }
+
+ // Parse the expected JSON string
+ var wantObj analyzers.AnalyzerResult
+ if err := json.Unmarshal([]byte(tt.want), &wantObj); err != nil {
+ t.Fatalf("could not unmarshal want JSON string: %s", err)
+ }
+
+ // bindings need to be in the same order to be comparable
+ sortBindings(wantObj.Bindings)
+
+ // Marshal the expected result to JSON (to normalize)
+ wantJSON, err := json.Marshal(wantObj)
+ if err != nil {
+ t.Fatalf("could not marshal want to JSON: %s", err)
+ }
+
+ // Compare the JSON strings
+ if string(gotJSON) != string(wantJSON) {
+ // Pretty-print both JSON strings for easier comparison
+ var gotIndented, wantIndented []byte
+ gotIndented, err = json.MarshalIndent(got, "", " ")
+ if err != nil {
+ t.Fatalf("could not marshal got to indented JSON: %s", err)
+ }
+ wantIndented, err = json.MarshalIndent(wantObj, "", " ")
+ if err != nil {
+ t.Fatalf("could not marshal want to indented JSON: %s", err)
+ }
+ t.Errorf("Analyzer.Analyze() = %s, want %s", gotIndented, wantIndented)
+ }
+ })
+ }
+}
+
+// Helper function to sort bindings
+func sortBindings(bindings []analyzers.Binding) {
+ sort.SliceStable(bindings, func(i, j int) bool {
+ if bindings[i].Resource.Name == bindings[j].Resource.Name {
+ return bindings[i].Permission.Value < bindings[j].Permission.Value
+ }
+ return bindings[i].Resource.Name < bindings[j].Resource.Name
+ })
+}
diff --git a/pkg/analyzer/analyzers/airtable/airtablepat/expected_output.json b/pkg/analyzer/analyzers/airtable/airtablepat/expected_output.json
new file mode 100644
index 000000000..e5b39db56
--- /dev/null
+++ b/pkg/analyzer/analyzers/airtable/airtablepat/expected_output.json
@@ -0,0 +1,39 @@
+{
+ "AnalyzerType": 29,
+ "Bindings": [
+ {
+ "Resource": {
+ "Name": "usraS0CjAASH3XMpU",
+ "FullyQualifiedName": "usraS0CjAASH3XMpU",
+ "Type": "user",
+ "Metadata": {},
+ "Parent": null
+ },
+ "Permission": {
+ "Value": "data.records:read",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "usraS0CjAASH3XMpU",
+ "FullyQualifiedName": "usraS0CjAASH3XMpU",
+ "Type": "user",
+ "Metadata": {},
+ "Parent": null
+ },
+ "Permission": {
+ "Value": "schema.bases:read",
+ "Parent": null
+ }
+ }
+ ],
+ "UnboundedResources": [
+ {
+ "Name": "Client Leads and Sales Management",
+ "FullyQualifiedName": "appzRyj5Q9R9kK6cF",
+ "Type": "base",
+ "Parent": null
+ }
+ ]
+}
\ No newline at end of file
diff --git a/pkg/analyzer/analyzers/airtable/airtablepat/requests.go b/pkg/analyzer/analyzers/airtable/airtablepat/requests.go
new file mode 100644
index 000000000..2afac070e
--- /dev/null
+++ b/pkg/analyzer/analyzers/airtable/airtablepat/requests.go
@@ -0,0 +1,38 @@
+package airtablepat
+
+import (
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "strings"
+
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/airtable/common"
+)
+
+type AirtableRecordsResponse struct {
+ Records []common.AirtableEntity `json:"records"`
+}
+
+func fetchAirtableRecords(token string, baseID string, tableID string) ([]common.AirtableEntity, error) {
+ endpoint, exists := getEndpoint(common.ListRecordsEndpoint)
+ if !exists {
+ return nil, fmt.Errorf("endpoint for ListRecordsEndpoint does not exist")
+ }
+ url := strings.Replace(strings.Replace(endpoint.URL, "{baseID}", baseID, -1), "{tableID}", tableID, -1)
+ resp, err := common.CallAirtableAPI(token, "GET", url)
+ if err != nil {
+ return nil, err
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ return nil, fmt.Errorf("failed to fetch Airtable records, status: %d", resp.StatusCode)
+ }
+
+ var recordsResponse AirtableRecordsResponse
+ if err := json.NewDecoder(resp.Body).Decode(&recordsResponse); err != nil {
+ return nil, err
+ }
+
+ return recordsResponse.Records, nil
+}
diff --git a/pkg/analyzer/analyzers/airtable/airtable.go b/pkg/analyzer/analyzers/airtable/common/common.go
similarity index 54%
rename from pkg/analyzer/analyzers/airtable/airtable.go
rename to pkg/analyzer/analyzers/airtable/common/common.go
index fb7598f85..3a976a80c 100644
--- a/pkg/analyzer/analyzers/airtable/airtable.go
+++ b/pkg/analyzer/analyzers/airtable/common/common.go
@@ -1,86 +1,40 @@
-//go:generate generate_permissions permissions.yaml permissions.go airtable
-package airtable
+//go:generate generate_permissions permissions.yaml permissions.go common
+package common
import (
"encoding/json"
- "errors"
"fmt"
"net/http"
"os"
+ "strings"
"github.com/fatih/color"
"github.com/jedib0t/go-pretty/v6/table"
+
"github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers"
- "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/config"
- "github.com/trufflesecurity/trufflehog/v3/pkg/context"
)
-var _ analyzers.Analyzer = (*Analyzer)(nil)
-
-type Analyzer struct {
- Cfg *config.Config
-}
-
-func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeAirtable }
-
-type AirtableUserInfo struct {
- ID string `json:"id"`
- Email *string `json:"email,omitempty"`
- Scopes []string `json:"scopes"`
-}
-
-type AirtableBases struct {
- Bases []struct {
- ID string `json:"id"`
- Name string `json:"name"`
- } `json:"bases"`
-}
-
-func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) {
- token, ok := credInfo["token"]
- if !ok {
- return nil, errors.New("token not found in credInfo")
- }
-
- userInfo, err := fetchAirtableUserInfo(token)
+func CallAirtableAPI(token string, method string, url string) (*http.Response, error) {
+ req, err := http.NewRequest(method, url, nil)
if err != nil {
return nil, err
}
+ req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
- var basesInfo *AirtableBases
- if hasScope(userInfo.Scopes, PermissionStrings[SchemaBasesRead]) {
- basesInfo, _ = fetchAirtableBases(token)
- }
-
- return mapToAnalyzerResult(userInfo, basesInfo), nil
-}
-
-func AnalyzeAndPrintPermissions(cfg *config.Config, token string) {
- userInfo, err := fetchAirtableUserInfo(token)
+ resp, err := http.DefaultClient.Do(req)
if err != nil {
- color.Red("[x] Error : %s", err.Error())
- return
+ return nil, err
}
- color.Green("[!] Valid Airtable OAuth2 Access Token\n\n")
- printUserAndPermissions(userInfo)
-
- if hasScope(userInfo.Scopes, PermissionStrings[SchemaBasesRead]) {
- var basesInfo *AirtableBases
- basesInfo, _ = fetchAirtableBases(token)
- printBases(basesInfo)
- }
+ return resp, nil
}
-func fetchAirtableUserInfo(token string) (*AirtableUserInfo, error) {
- url := "https://api.airtable.com/v0/meta/whoami"
- req, err := http.NewRequest("GET", url, nil)
- if err != nil {
- return nil, err
+func FetchAirtableUserInfo(token string) (*AirtableUserInfo, error) {
+ endpoint, exists := GetEndpoint(GetUserInfoEndpoint)
+ if !exists {
+ return nil, fmt.Errorf("endpoint for GetUserInfoEndpoint does not exist")
}
- req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
-
- resp, err := http.DefaultClient.Do(req)
+ resp, err := CallAirtableAPI(token, endpoint.Method, endpoint.URL)
if err != nil {
return nil, err
}
@@ -98,15 +52,12 @@ func fetchAirtableUserInfo(token string) (*AirtableUserInfo, error) {
return &userInfo, nil
}
-func fetchAirtableBases(token string) (*AirtableBases, error) {
- url := "https://api.airtable.com/v0/meta/bases"
- req, err := http.NewRequest("GET", url, nil)
- if err != nil {
- return nil, err
+func FetchAirtableBases(token string) (*AirtableBases, error) {
+ endpoint, exists := GetEndpoint(ListBasesEndpoint)
+ if !exists {
+ return nil, fmt.Errorf("endpoint for ListBasesEndpoint does not exist")
}
- req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
-
- resp, err := http.DefaultClient.Do(req)
+ resp, err := CallAirtableAPI(token, endpoint.Method, endpoint.URL)
if err != nil {
return nil, err
}
@@ -121,25 +72,50 @@ func fetchAirtableBases(token string) (*AirtableBases, error) {
return nil, err
}
+ // Fetch schema for each base
+ for i, base := range basesInfo.Bases {
+ schema, err := fetchBaseSchema(token, base.ID)
+ if err != nil {
+ basesInfo.Bases[i].Schema = nil
+ } else {
+ basesInfo.Bases[i].Schema = schema
+ }
+ }
+
return &basesInfo, nil
}
-func hasScope(scopes []string, target string) bool {
- for _, scope := range scopes {
- if scope == target {
- return true
- }
+func fetchBaseSchema(token string, baseID string) (*Schema, error) {
+ endpoint, exists := GetEndpoint(GetBaseSchemaEndpoint)
+ if !exists {
+ return nil, fmt.Errorf("endpoint for GetBaseSchemaEndpoint does not exist")
+ }
+ url := strings.Replace(endpoint.URL, "{baseID}", baseID, -1)
+ resp, err := CallAirtableAPI(token, endpoint.Method, url)
+ if err != nil {
+ return nil, err
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ return nil, fmt.Errorf("failed to fetch schema for base %s, status: %d", baseID, resp.StatusCode)
+ }
+
+ var schema Schema
+ if err := json.NewDecoder(resp.Body).Decode(&schema); err != nil {
+ return nil, err
}
- return false
+
+ return &schema, nil
}
-func mapToAnalyzerResult(userInfo *AirtableUserInfo, basesInfo *AirtableBases) *analyzers.AnalyzerResult {
+func MapToAnalyzerResult(userInfo *AirtableUserInfo, basesInfo *AirtableBases) *analyzers.AnalyzerResult {
if userInfo == nil {
return nil
}
result := analyzers.AnalyzerResult{
- AnalyzerType: analyzers.AnalyzerTypeAirtable,
+ AnalyzerType: analyzers.AnalyzerTypeAirtableOAuth,
}
var permissions []analyzers.Permission
for _, scope := range userInfo.Scopes {
@@ -172,7 +148,7 @@ func mapToAnalyzerResult(userInfo *AirtableUserInfo, basesInfo *AirtableBases) *
return &result
}
-func printUserAndPermissions(info *AirtableUserInfo) {
+func PrintUserAndPermissions(info *AirtableUserInfo, scopeStatusMap map[string]bool) {
color.Yellow("[i] User:")
t1 := table.NewWriter()
email := "N/A"
@@ -188,21 +164,35 @@ func printUserAndPermissions(info *AirtableUserInfo) {
color.Yellow("\n[i] Scopes:")
t2 := table.NewWriter()
t2.SetOutputMirror(os.Stdout)
- t2.AppendHeader(table.Row{"Scope", "Permission"})
- for _, scope := range info.Scopes {
- for i, permission := range scope_mapping[scope] {
- scope_string := ""
+ t2.AppendHeader(table.Row{"Scope", "Permission", "Status"})
+ for _, scope := range PermissionStrings {
+ scopeStatus := "Could not verify"
+ if status, ok := scopeStatusMap[scope]; ok {
+ if status {
+ scopeStatus = "Granted"
+ } else {
+ scopeStatus = "Denied"
+ }
+ }
+ permissions, ok := GetScopePermissions(scope)
+ if !ok {
+ continue
+ }
+ for i, permission := range permissions {
+ scopeString := ""
if i == 0 {
- scope_string = scope
+ scopeString = scope
}
- t2.AppendRow(table.Row{color.GreenString(scope_string), color.GreenString(permission)})
+ t2.AppendRow(table.Row{color.GreenString(scopeString), color.GreenString(permission), color.GreenString(scopeStatus)})
+ scopeStatus = ""
}
+ t2.AppendSeparator()
}
t2.Render()
fmt.Printf("%s: https://airtable.com/developers/web/api/scopes\n", color.GreenString("Ref"))
}
-func printBases(bases *AirtableBases) {
+func PrintBases(bases *AirtableBases) {
color.Yellow("\n[i] Bases:")
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
diff --git a/pkg/analyzer/analyzers/airtable/common/endpoints.go b/pkg/analyzer/analyzers/airtable/common/endpoints.go
new file mode 100644
index 000000000..13e7e7115
--- /dev/null
+++ b/pkg/analyzer/analyzers/airtable/common/endpoints.go
@@ -0,0 +1,133 @@
+package common
+
+import "net/http"
+
+type ErrorResponse struct {
+ Type string
+}
+
+type Endpoint struct {
+ URL string
+ Method string
+ RequiredIDs []string
+ RequiredPermission *string
+ ExpectedSuccessStatus int
+ ExpectedErrorResponse *ErrorResponse
+}
+
+type EndpointName int
+
+const (
+ GetUserInfoEndpoint EndpointName = iota
+ ListBasesEndpoint EndpointName = iota
+ UpdateBaseEndpoint EndpointName = iota
+ GetBaseSchemaEndpoint EndpointName = iota
+ ListRecordsEndpoint EndpointName = iota
+ CreateRecordEndpoint EndpointName = iota
+ ListRecordCommentsEndpoint EndpointName = iota
+ ListWebhooksEndpoint EndpointName = iota
+ ListBlockInstallationsEndpoint EndpointName = iota
+)
+
+var endpoints map[EndpointName]Endpoint
+
+func init() {
+ endpoints = map[EndpointName]Endpoint{
+ GetUserInfoEndpoint: {
+ URL: "https://api.airtable.com/v0/meta/whoami",
+ Method: "GET",
+ },
+ ListBasesEndpoint: {
+ URL: "https://api.airtable.com/v0/meta/bases",
+ Method: "GET",
+ RequiredPermission: GetRequiredPermission(SchemaBasesRead),
+ ExpectedSuccessStatus: http.StatusOK,
+ ExpectedErrorResponse: &ErrorResponse{
+ Type: "INVALID_PERMISSIONS_OR_MODEL_NOT_FOUND",
+ },
+ },
+ UpdateBaseEndpoint: {
+ URL: "https://api.airtable.com/v0/meta/bases/{baseID}/tables/{tableID}",
+ Method: "PATCH",
+ RequiredIDs: []string{"baseID", "tableID"},
+ RequiredPermission: GetRequiredPermission(SchemaBasesWrite),
+ ExpectedSuccessStatus: http.StatusUnprocessableEntity,
+ ExpectedErrorResponse: &ErrorResponse{
+ Type: "INVALID_PERMISSIONS_OR_MODEL_NOT_FOUND",
+ },
+ },
+ GetBaseSchemaEndpoint: {
+ URL: "https://api.airtable.com/v0/meta/bases/{baseID}/tables",
+ Method: "GET",
+ RequiredIDs: []string{"baseID"},
+ RequiredPermission: GetRequiredPermission(SchemaBasesRead),
+ ExpectedSuccessStatus: http.StatusOK,
+ ExpectedErrorResponse: &ErrorResponse{
+ Type: "INVALID_PERMISSIONS_OR_MODEL_NOT_FOUND",
+ },
+ },
+ ListRecordsEndpoint: {
+ URL: "https://api.airtable.com/v0/{baseID}/{tableID}",
+ Method: "GET",
+ RequiredIDs: []string{"baseID", "tableID"},
+ RequiredPermission: GetRequiredPermission(DataRecordsRead),
+ ExpectedSuccessStatus: http.StatusOK,
+ ExpectedErrorResponse: &ErrorResponse{
+ Type: "INVALID_PERMISSIONS_OR_MODEL_NOT_FOUND",
+ },
+ },
+ CreateRecordEndpoint: {
+ URL: "https://api.airtable.com/v0/{baseID}/{tableID}",
+ Method: "POST",
+ RequiredIDs: []string{"baseID", "tableID"},
+ RequiredPermission: GetRequiredPermission(DataRecordsWrite),
+ ExpectedSuccessStatus: http.StatusUnprocessableEntity,
+ ExpectedErrorResponse: &ErrorResponse{
+ Type: "INVALID_PERMISSIONS_OR_MODEL_NOT_FOUND",
+ },
+ },
+ ListRecordCommentsEndpoint: {
+ URL: "https://api.airtable.com/v0/{baseID}/{tableID}/{recordID}/comments",
+ Method: "GET",
+ RequiredIDs: []string{"baseID", "tableID", "recordID"},
+ RequiredPermission: GetRequiredPermission(DataRecordcommentsRead),
+ ExpectedSuccessStatus: http.StatusOK,
+ ExpectedErrorResponse: &ErrorResponse{
+ Type: "INVALID_PERMISSIONS_OR_MODEL_NOT_FOUND",
+ },
+ },
+ ListWebhooksEndpoint: {
+ URL: "https://api.airtable.com/v0/bases/{baseID}/webhooks",
+ Method: "GET",
+ RequiredIDs: []string{"baseID"},
+ RequiredPermission: GetRequiredPermission(WebhookManage),
+ ExpectedSuccessStatus: http.StatusOK,
+ ExpectedErrorResponse: &ErrorResponse{
+ Type: "INVALID_PERMISSIONS_OR_MODEL_NOT_FOUND",
+ },
+ },
+ ListBlockInstallationsEndpoint: {
+ URL: "https://api.airtable.com/v0/meta/bases/{baseID}/blockInstallations",
+ Method: "GET",
+ RequiredIDs: []string{"baseID"},
+ RequiredPermission: GetRequiredPermission(BlockManage),
+ ExpectedSuccessStatus: http.StatusOK,
+ ExpectedErrorResponse: &ErrorResponse{
+ Type: "INVALID_PERMISSIONS_OR_MODEL_NOT_FOUND",
+ },
+ },
+ }
+}
+
+func GetRequiredPermission(permission Permission) *string {
+ if val, exists := PermissionStrings[permission]; exists {
+ return &val
+ }
+ return nil
+}
+
+// GetEndpoint returns the endpoint object for the provided name and whether it exists
+func GetEndpoint(name EndpointName) (Endpoint, bool) {
+ endpoint, exists := endpoints[name]
+ return endpoint, exists
+}
diff --git a/pkg/analyzer/analyzers/airtable/common/models.go b/pkg/analyzer/analyzers/airtable/common/models.go
new file mode 100644
index 000000000..862489b4f
--- /dev/null
+++ b/pkg/analyzer/analyzers/airtable/common/models.go
@@ -0,0 +1,23 @@
+package common
+
+type AirtableUserInfo struct {
+ ID string `json:"id"`
+ Email *string `json:"email,omitempty"`
+ Scopes []string `json:"scopes"`
+}
+
+type AirtableBases struct {
+ Bases []struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ Schema *Schema `json:"schema,omitempty"`
+ } `json:"bases"`
+}
+
+type Schema struct {
+ Tables []AirtableEntity `json:"tables"`
+}
+
+type AirtableEntity struct {
+ ID string `json:"id"`
+}
diff --git a/pkg/analyzer/analyzers/airtable/permissions.go b/pkg/analyzer/analyzers/airtable/common/permissions.go
similarity index 99%
rename from pkg/analyzer/analyzers/airtable/permissions.go
rename to pkg/analyzer/analyzers/airtable/common/permissions.go
index 3329082e0..45f043f2c 100644
--- a/pkg/analyzer/analyzers/airtable/permissions.go
+++ b/pkg/analyzer/analyzers/airtable/common/permissions.go
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
-package airtable
+package common
import "errors"
diff --git a/pkg/analyzer/analyzers/airtable/permissions.yaml b/pkg/analyzer/analyzers/airtable/common/permissions.yaml
similarity index 100%
rename from pkg/analyzer/analyzers/airtable/permissions.yaml
rename to pkg/analyzer/analyzers/airtable/common/permissions.yaml
diff --git a/pkg/analyzer/analyzers/airtable/scopes.go b/pkg/analyzer/analyzers/airtable/common/scopes.go
similarity index 74%
rename from pkg/analyzer/analyzers/airtable/scopes.go
rename to pkg/analyzer/analyzers/airtable/common/scopes.go
index 91de3c9fe..b8ec67d07 100644
--- a/pkg/analyzer/analyzers/airtable/scopes.go
+++ b/pkg/analyzer/analyzers/airtable/common/scopes.go
@@ -1,6 +1,6 @@
-package airtable
+package common
-var scope_mapping = map[string][]string{
+var scopeToPermissions = map[string][]string{
// Basic Scopes
"data.records:read": {
"List records",
@@ -47,6 +47,7 @@ var scope_mapping = map[string][]string{
"user.email:read": {
"See the user's email address",
},
+
// Enterprise scopes
"enterprise.groups:read": {
"Get user group",
@@ -141,3 +142,34 @@ var scope_mapping = map[string][]string{
"Move base",
},
}
+
+var scopeToEndpointName = map[string]EndpointName{
+ "schema.bases:read": ListBasesEndpoint,
+ "schema.bases:write": UpdateBaseEndpoint,
+ "webhook:manage": ListWebhooksEndpoint,
+ "block:manage": ListBlockInstallationsEndpoint,
+ "data.records:read": ListRecordsEndpoint,
+ "data.records:write": CreateRecordEndpoint,
+ "data.recordComments:read": ListRecordCommentsEndpoint,
+}
+
+var scopeToEndpoint map[string]Endpoint
+
+func init() {
+ scopeToEndpoint = make(map[string]Endpoint)
+ for scope, endpointName := range scopeToEndpointName {
+ if endpoint, exists := GetEndpoint(endpointName); exists {
+ scopeToEndpoint[scope] = endpoint
+ }
+ }
+}
+
+func GetScopePermissions(scope string) ([]string, bool) {
+ permission, exists := scopeToPermissions[scope]
+ return permission, exists
+}
+
+func GetScopeEndpoint(scope string) (Endpoint, bool) {
+ endpoint, exists := scopeToEndpoint[scope]
+ return endpoint, exists
+}
diff --git a/pkg/analyzer/analyzers/analyzers.go b/pkg/analyzer/analyzers/analyzers.go
index 7c8c4fbc2..27233b30d 100644
--- a/pkg/analyzer/analyzers/analyzers.go
+++ b/pkg/analyzer/analyzers/analyzers.go
@@ -85,43 +85,45 @@ const (
AnalyzerTypeTwilio
AnalyzerTypePrivateKey
AnalyzerTypeNotion
- AnalyzerTypeAirtable
AnalyzerTypeDigitalOcean
AnalyzerTypePlanetScale
+ AnalyzerTypeAirtableOAuth
+ AnalyzerTypeAirtablePat
// Add new items here with AnalyzerType prefix
)
// analyzerTypeStrings maps the enum to its string representation.
var analyzerTypeStrings = map[AnalyzerType]string{
- AnalyzerTypeInvalid: "Invalid",
- AnalyzerTypeAirbrake: "Airbrake",
- AnalyzerTypeAirtable: "Airtable",
- AnalyzerAnthropic: "Anthropic",
- AnalyzerTypeAsana: "Asana",
- AnalyzerTypeBitbucket: "Bitbucket",
- AnalyzerTypeDigitalOcean: "DigitalOcean",
- AnalyzerTypeDockerHub: "DockerHub",
- AnalyzerTypeElevenLabs: "ElevenLabs",
- AnalyzerTypeGitHub: "GitHub",
- AnalyzerTypeGitLab: "GitLab",
- AnalyzerTypeHuggingFace: "HuggingFace",
- AnalyzerTypeMailchimp: "Mailchimp",
- AnalyzerTypeMailgun: "Mailgun",
- AnalyzerTypeMySQL: "MySQL",
- AnalyzerTypeOpenAI: "OpenAI",
- AnalyzerTypeOpsgenie: "Opsgenie",
- AnalyzerTypePostgres: "Postgres",
- AnalyzerTypePostman: "Postman",
- AnalyzerTypeSendgrid: "Sendgrid",
- AnalyzerTypeShopify: "Shopify",
- AnalyzerTypeSlack: "Slack",
- AnalyzerTypeSourcegraph: "Sourcegraph",
- AnalyzerTypeSquare: "Square",
- AnalyzerTypeStripe: "Stripe",
- AnalyzerTypeTwilio: "Twilio",
- AnalyzerTypePrivateKey: "PrivateKey",
- AnalyzerTypeNotion: "Notion",
- AnalyzerTypePlanetScale: "PlanetScale",
+ AnalyzerTypeInvalid: "Invalid",
+ AnalyzerTypeAirbrake: "Airbrake",
+ AnalyzerAnthropic: "Anthropic",
+ AnalyzerTypeAsana: "Asana",
+ AnalyzerTypeBitbucket: "Bitbucket",
+ AnalyzerTypeDigitalOcean: "DigitalOcean",
+ AnalyzerTypeDockerHub: "DockerHub",
+ AnalyzerTypeElevenLabs: "ElevenLabs",
+ AnalyzerTypeGitHub: "GitHub",
+ AnalyzerTypeGitLab: "GitLab",
+ AnalyzerTypeHuggingFace: "HuggingFace",
+ AnalyzerTypeMailchimp: "Mailchimp",
+ AnalyzerTypeMailgun: "Mailgun",
+ AnalyzerTypeMySQL: "MySQL",
+ AnalyzerTypeOpenAI: "OpenAI",
+ AnalyzerTypeOpsgenie: "Opsgenie",
+ AnalyzerTypePostgres: "Postgres",
+ AnalyzerTypePostman: "Postman",
+ AnalyzerTypeSendgrid: "Sendgrid",
+ AnalyzerTypeShopify: "Shopify",
+ AnalyzerTypeSlack: "Slack",
+ AnalyzerTypeSourcegraph: "Sourcegraph",
+ AnalyzerTypeSquare: "Square",
+ AnalyzerTypeStripe: "Stripe",
+ AnalyzerTypeTwilio: "Twilio",
+ AnalyzerTypePrivateKey: "PrivateKey",
+ AnalyzerTypeNotion: "Notion",
+ AnalyzerTypePlanetScale: "PlanetScale",
+ AnalyzerTypeAirtableOAuth: "AirtableOAuth",
+ AnalyzerTypeAirtablePat: "AirtablePat",
// Add new mappings here
}
diff --git a/pkg/analyzer/analyzers/planetscale/expected_output.json b/pkg/analyzer/analyzers/planetscale/expected_output.json
index afece58a2..4a63175c7 100644
--- a/pkg/analyzer/analyzers/planetscale/expected_output.json
+++ b/pkg/analyzer/analyzers/planetscale/expected_output.json
@@ -1 +1 @@
-{"AnalyzerType":28,"Bindings":[{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"connect_branch","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"connect_production_branch","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"create_branch","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"create_deploy_request","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"read_backups","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"read_branch","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"read_database","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"read_deploy_request","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"restore_backup","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"restore_production_branch_backup","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"write_database","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"create_databases","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_audit_logs","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_databases","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_invoices","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_oauth_applications","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_oauth_tokens","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_organization","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"write_oauth_tokens","Parent":null}}],"UnboundedResources":null,"Metadata":null}
\ No newline at end of file
+{"AnalyzerType":27,"Bindings":[{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"connect_branch","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"connect_production_branch","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"create_branch","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"create_deploy_request","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"read_backups","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"read_branch","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"read_database","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"read_deploy_request","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"restore_backup","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"restore_production_branch_backup","Parent":null}},{"Resource":{"Name":"detector-db","FullyQualifiedName":"planetscale.com/database/9p2lzxigxod0","Type":"Database","Metadata":null,"Parent":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null}},"Permission":{"Value":"write_database","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"create_databases","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_audit_logs","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_databases","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_invoices","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_oauth_applications","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_oauth_tokens","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"read_organization","Parent":null}},{"Resource":{"Name":"detectors","FullyQualifiedName":"planetscale.com/organization/hn31ztkm9u15","Type":"Organization","Metadata":null,"Parent":null},"Permission":{"Value":"write_oauth_tokens","Parent":null}}],"UnboundedResources":null,"Metadata":null}
\ No newline at end of file
diff --git a/pkg/analyzer/cli.go b/pkg/analyzer/cli.go
index 073f8dd08..b632c3d70 100644
--- a/pkg/analyzer/cli.go
+++ b/pkg/analyzer/cli.go
@@ -6,7 +6,8 @@ import (
"github.com/alecthomas/kingpin/v2"
"github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/airbrake"
- "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/airtable"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/airtable/airtableoauth"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/airtable/airtablepat"
"github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/anthropic"
"github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/asana"
"github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/bitbucket"
@@ -98,13 +99,15 @@ func Run(keyType string, secretInfo SecretInfo) {
dockerhub.AnalyzeAndPrintPermissions(secretInfo.Cfg, secretInfo.Parts["username"], secretInfo.Parts["pat"])
case "anthropic":
anthropic.AnalyzeAndPrintPermissions(secretInfo.Cfg, secretInfo.Parts["key"])
- case "airtable":
- airtable.AnalyzeAndPrintPermissions(secretInfo.Cfg, secretInfo.Parts["key"])
case "digitalocean":
digitalocean.AnalyzeAndPrintPermissions(secretInfo.Cfg, secretInfo.Parts["key"])
case "elevenlabs":
elevenlabs.AnalyzeAndPrintPermissions(secretInfo.Cfg, secretInfo.Parts["key"])
case "planetscale":
planetscale.AnalyzeAndPrintPermissions(secretInfo.Cfg, secretInfo.Parts["id"], secretInfo.Parts["token"])
+ case "airtableoauth":
+ airtableoauth.AnalyzeAndPrintPermissions(secretInfo.Cfg, secretInfo.Parts["key"])
+ case "airtablepat":
+ airtablepat.AnalyzeAndPrintPermissions(secretInfo.Cfg, secretInfo.Parts["key"])
}
}
diff --git a/pkg/detectors/airtablepersonalaccesstoken/airtablepersonalaccesstoken.go b/pkg/detectors/airtablepersonalaccesstoken/airtablepersonalaccesstoken.go
index aa9d53fa3..b771d9aa1 100644
--- a/pkg/detectors/airtablepersonalaccesstoken/airtablepersonalaccesstoken.go
+++ b/pkg/detectors/airtablepersonalaccesstoken/airtablepersonalaccesstoken.go
@@ -54,6 +54,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
s1.Verified = isVerified
s1.ExtraData = extraData
s1.SetVerificationError(verificationErr, match)
+
+ if s1.Verified {
+ s1.AnalysisInfo = map[string]string{"token": match}
+ }
}
results = append(results, s1)