Skip to content

Find, verify, and analyze leaked credentials

Postman workspace enumeration (#3925)

Casey Tran6f1e9187dbdd
diff --git a/pkg/sources/postman/postman.go b/pkg/sources/postman/postman.go
index b2838ae6a..6aa2ccacf 100644
--- a/pkg/sources/postman/postman.go
+++ b/pkg/sources/postman/postman.go
@@ -180,11 +180,12 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
// Scan workspaces
for _, workspaceID := range s.conn.Workspaces {
- w, err := s.client.GetWorkspace(workspaceID)
+ w, err := s.client.GetWorkspace(ctx, workspaceID)
if err != nil {
return fmt.Errorf("error getting workspace %s: %w", workspaceID, err)
}
s.SetProgressOngoing(fmt.Sprintf("Scanning workspace %s", workspaceID), "")
+ ctx.Logger().V(2).Info("scanning workspace from workspaces given", "workspace", workspaceID)
if err = s.scanWorkspace(ctx, chunksChan, w); err != nil {
return fmt.Errorf("error scanning workspace %s: %w", workspaceID, err)
}
@@ -206,10 +207,11 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
// Scan personal workspaces (from API token)
if s.conn.Workspaces == nil && s.conn.Collections == nil && s.conn.Environments == nil && s.conn.GetToken() != "" {
- workspaces, err := s.client.EnumerateWorkspaces()
+ workspaces, err := s.client.EnumerateWorkspaces(ctx)
if err != nil {
return fmt.Errorf("error enumerating postman workspaces: %w", err)
}
+ ctx.Logger().V(2).Info("enumerated workspaces", "workspaces", workspaces)
for _, workspace := range workspaces {
s.SetProgressOngoing(fmt.Sprintf("Scanning workspace %s", workspace.ID), "")
if err = s.scanWorkspace(ctx, chunksChan, workspace); err != nil {
@@ -307,7 +309,7 @@ func (s *Source) scanWorkspace(ctx context.Context, chunksChan chan *sources.Chu
// scanCollection scans a collection and all its items, folders, and requests.
// locally scoped Metadata is updated as we drill down into the collection.
func (s *Source) scanCollection(ctx context.Context, chunksChan chan *sources.Chunk, metadata Metadata, collection Collection) {
- ctx.Logger().V(2).Info("starting scanning collection", collection.Info.Name, "uuid", collection.Info.UID)
+ ctx.Logger().V(2).Info("starting to scan collection", "collection_name", collection.Info.Name, "collection_uuid", collection.Info.UID)
metadata.CollectionInfo = collection.Info
metadata.Type = COLLECTION_TYPE
s.attemptToAddKeyword(collection.Info.Name)
@@ -637,7 +639,7 @@ func (s *Source) scanHTTPResponse(ctx context.Context, chunksChan chan *sources.
func (s *Source) scanVariableData(ctx context.Context, chunksChan chan *sources.Chunk, m Metadata, variableData VariableData) {
if len(variableData.KeyValues) == 0 {
- ctx.Logger().V(2).Info("no variables to scan", "type", m.Type, "uuid", m.FullID)
+ ctx.Logger().V(2).Info("no variables to scan", "type", m.Type, "item_uuid", m.FullID)
return
}
@@ -673,12 +675,14 @@ func (s *Source) scanVariableData(ctx context.Context, chunksChan chan *sources.
func (s *Source) scanData(ctx context.Context, chunksChan chan *sources.Chunk, data string, metadata Metadata) {
if data == "" {
+ ctx.Logger().V(3).Info("Data string is empty", "workspace_id", metadata.WorkspaceUUID)
return
}
if metadata.FieldType == "" {
metadata.FieldType = metadata.Type
}
+ ctx.Logger().V(3).Info("Generating chunk and passing it to the channel", "link", metadata.Link)
chunksChan <- &sources.Chunk{
SourceType: s.Type(),
SourceName: s.name,
diff --git a/pkg/sources/postman/postman_client.go b/pkg/sources/postman/postman_client.go
index 0d2733797..c939ac8be 100644
--- a/pkg/sources/postman/postman_client.go
+++ b/pkg/sources/postman/postman_client.go
@@ -7,6 +7,8 @@ import (
"net/http"
"time"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/context"
+
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
)
@@ -249,8 +251,8 @@ func (c *Client) getPostmanReq(url string, headers map[string]string) (*http.Res
// EnumerateWorkspaces returns the workspaces for a given user (both private, public, team and personal).
// Consider adding additional flags to support filtering.
-func (c *Client) EnumerateWorkspaces() ([]Workspace, error) {
- var workspaces []Workspace
+func (c *Client) EnumerateWorkspaces(ctx context.Context) ([]Workspace, error) {
+ ctx.Logger().V(2).Info("enumerating workspaces")
workspacesObj := struct {
Workspaces []Workspace `json:"workspaces"`
}{}
@@ -258,27 +260,37 @@ func (c *Client) EnumerateWorkspaces() ([]Workspace, error) {
r, err := c.getPostmanReq("https://api.getpostman.com/workspaces", nil)
if err != nil {
err = fmt.Errorf("could not get workspaces")
- return workspaces, err
+ return nil, err
}
body, err := io.ReadAll(r.Body)
if err != nil {
err = fmt.Errorf("could not read response body for workspaces")
- return workspaces, err
+ return nil, err
}
r.Body.Close()
if err := json.Unmarshal([]byte(body), &workspacesObj); err != nil {
err = fmt.Errorf("could not unmarshal workspaces JSON")
- return workspaces, err
+ return nil, err
+ }
+
+ for i, workspace := range workspacesObj.Workspaces {
+ tempWorkspace, err := c.GetWorkspace(ctx, workspace.ID)
+ if err != nil {
+ return nil, fmt.Errorf("could not get workspace %q (%s) during enumeration: %w", workspace.Name, workspace.ID, err)
+ }
+ workspacesObj.Workspaces[i] = tempWorkspace
+
+ ctx.Logger().V(3).Info("individual workspace getting added to the slice", "workspace", workspacesObj.Workspaces[i])
}
return workspacesObj.Workspaces, nil
}
// GetWorkspace returns the workspace for a given workspace
-func (c *Client) GetWorkspace(workspaceUUID string) (Workspace, error) {
- var workspace Workspace
+func (c *Client) GetWorkspace(ctx context.Context, workspaceUUID string) (Workspace, error) {
+ ctx.Logger().V(2).Info("getting workspace", "workspace", workspaceUUID)
obj := struct {
Workspace Workspace `json:"workspace"`
}{}
@@ -287,19 +299,19 @@ func (c *Client) GetWorkspace(workspaceUUID string) (Workspace, error) {
r, err := c.getPostmanReq(url, nil)
if err != nil {
err = fmt.Errorf("could not get workspace: %s", workspaceUUID)
- return workspace, err
+ return Workspace{}, err
}
body, err := io.ReadAll(r.Body)
if err != nil {
err = fmt.Errorf("could not read response body for workspace: %s", workspaceUUID)
- return workspace, err
+ return Workspace{}, err
}
r.Body.Close()
if err := json.Unmarshal([]byte(body), &obj); err != nil {
err = fmt.Errorf("could not unmarshal workspace JSON for workspace: %s", workspaceUUID)
- return workspace, err
+ return Workspace{}, err
}
return obj.Workspace, nil