Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstated Postman body scanning #3904

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions pkg/sources/postman/postman.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,47 @@ func (s *Source) scanHTTPRequest(ctx context.Context, chunksChan chan *sources.C
s.scanAuth(ctx, chunksChan, metadata, r.Auth, r.URL)
}

// We would scan the body, but currently the body has different radio buttons that can be scanned but only the selected one is scanned. The unselected radio button options can still
// have secrets in them but will not be scanned. The selction of the radio button will also change the secret metadata for that particular scanning pass and can create confusion for
// the user as to the status of a secret. We will reimplement at some point.
if r.Body.Mode != "" {
metadata.Type = originalType + " > body"
s.scanRequestBody(ctx, chunksChan, metadata, r.Body)
}
}

func (s *Source) scanRequestBody(ctx context.Context, chunksChan chan *sources.Chunk, m Metadata, b Body) {
if !m.fromLocal {
m.Link = m.Link + "?tab=body"
}
originalType := m.Type
switch b.Mode {
case "formdata":
m.Type = originalType + " > form data"
vars := VariableData{
KeyValues: b.FormData,
}
m.LocationType = source_metadatapb.PostmanLocationType_REQUEST_BODY_FORM_DATA
s.scanVariableData(ctx, chunksChan, m, vars)
m.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMAN
case "urlencoded":
m.Type = originalType + " > url encoded"
vars := VariableData{
KeyValues: b.URLEncoded,
}
m.LocationType = source_metadatapb.PostmanLocationType_REQUEST_BODY_URL_ENCODED
s.scanVariableData(ctx, chunksChan, m, vars)
m.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMAN
case "raw":
m.Type = originalType + " > raw"
data := b.Raw
m.LocationType = source_metadatapb.PostmanLocationType_REQUEST_BODY_RAW
s.scanData(ctx, chunksChan, s.formatAndInjectKeywords(s.buildSubstitueSet(m, data)), m)
m.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMAN
case "graphql":
m.Type = originalType + " > graphql"
data := b.GraphQL.Query + " " + b.GraphQL.Variables
m.LocationType = source_metadatapb.PostmanLocationType_REQUEST_BODY_GRAPHQL
s.scanData(ctx, chunksChan, s.formatAndInjectKeywords(s.buildSubstitueSet(m, data)), m)
m.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMAN
}
}

func (s *Source) scanHTTPResponse(ctx context.Context, chunksChan chan *sources.Chunk, m Metadata, response Response) {
Expand Down
Loading