Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Differentiate postman folder from request when at collection root (#3912)
Casey Trand50cafeee7a9
diff --git a/pkg/sources/postman/postman.go b/pkg/sources/postman/postman.goindex bbc2e416b..bf53012b5 100644--- a/pkg/sources/postman/postman.go+++ b/pkg/sources/postman/postman.go@@ -329,16 +329,15 @@ func (s *Source) scanCollection(ctx context.Context, chunksChan chan *sources.Ch}for _, item := range collection.Items {- s.scanItem(ctx, chunksChan, collection, metadata, item)+ s.scanItem(ctx, chunksChan, collection, metadata, item, "")}}-func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, collection Collection, metadata Metadata, item Item) {+func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, collection Collection, metadata Metadata, item Item, parentItemId string) {s.attemptToAddKeyword(item.Name)// override the base collection metadata with item-specific metadata- metadata.FolderID = item.IDmetadata.Type = FOLDER_TYPEif metadata.FolderName != "" {// keep track of the folder hierarchy@@ -353,13 +352,22 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, c}// recurse through the foldersfor _, subItem := range item.Items {- s.scanItem(ctx, chunksChan, collection, metadata, subItem)+ s.scanItem(ctx, chunksChan, collection, metadata, subItem, item.UID)}+ // The assignment of the folder ID to be the current item UID is due to wanting to assume that your current item is a folder unless you have request data inside of your item.+ // If your current item is a folder, you will want the folder ID to match the UID of the current item.+ // If your current item is a request, you will want the folder ID to match the UID of the parent folder.+ // If the request is at the root of a collection and has no parent folder, the folder ID will be empty.+ metadata.FolderID = item.UID// check if there are any requests in the folderif item.Request.Method != "" {metadata.FolderName = strings.Replace(metadata.FolderName, (" > " + item.Name), "", -1)- metadata.RequestID = item.ID+ metadata.FolderID = parentItemId+ if metadata.FolderID == "" {+ metadata.FolderName = ""+ }+ metadata.RequestID = item.UIDmetadata.RequestName = item.Namemetadata.Type = REQUEST_TYPEif item.UID != "" {@@ -381,14 +389,6 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, cfor _, event := range item.Events {s.scanEvent(ctx, chunksChan, metadata, event)}-- if metadata.RequestID != "" {- metadata.LocationType = source_metadatapb.PostmanLocationType_REQUEST_AUTHORIZATION- } else if metadata.FolderID != "" {- metadata.LocationType = source_metadatapb.PostmanLocationType_FOLDER_AUTHORIZATION- } else if metadata.CollectionInfo.UID != "" {- metadata.LocationType = source_metadatapb.PostmanLocationType_COLLECTION_AUTHORIZATION- }// an auth all by its lonesome could be inherited to subfolders and requestss.scanAuth(ctx, chunksChan, metadata, item.Auth, item.Request.URL)metadata.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMANdiff --git a/pkg/sources/postman/postman_client.go b/pkg/sources/postman/postman_client.goindex 9c3c01010..0d2733797 100644--- a/pkg/sources/postman/postman_client.go+++ b/pkg/sources/postman/postman_client.go@@ -109,7 +109,7 @@ type Item struct {Request Request `json:"request,omitempty"`Response []Response `json:"response,omitempty"`Description string `json:"description,omitempty"`- UID string `json:"uid,omitempty"` //Need to use this to get the collection via API+ UID string `json:"uid,omitempty"` //Need to use this to get the collection via API. The UID is a concatenation of the ID and the user ID of whoever created the item.}type Auth struct {