Skip to content

Commit 881c2f9

Browse files
authored
Reinstated Postman body scanning (#3904)
* Reinstated Postman body scanning * Gave scanBody a more specific name * Split out raw and grphql case. Took out default case
1 parent f2dc96e commit 881c2f9

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

pkg/sources/postman/postman.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,47 @@ func (s *Source) scanHTTPRequest(ctx context.Context, chunksChan chan *sources.C
550550
s.scanAuth(ctx, chunksChan, metadata, r.Auth, r.URL)
551551
}
552552

553-
// 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
554-
// 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
555-
// the user as to the status of a secret. We will reimplement at some point.
553+
if r.Body.Mode != "" {
554+
metadata.Type = originalType + " > body"
555+
s.scanRequestBody(ctx, chunksChan, metadata, r.Body)
556+
}
557+
}
558+
559+
func (s *Source) scanRequestBody(ctx context.Context, chunksChan chan *sources.Chunk, m Metadata, b Body) {
560+
if !m.fromLocal {
561+
m.Link = m.Link + "?tab=body"
562+
}
563+
originalType := m.Type
564+
switch b.Mode {
565+
case "formdata":
566+
m.Type = originalType + " > form data"
567+
vars := VariableData{
568+
KeyValues: b.FormData,
569+
}
570+
m.LocationType = source_metadatapb.PostmanLocationType_REQUEST_BODY_FORM_DATA
571+
s.scanVariableData(ctx, chunksChan, m, vars)
572+
m.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMAN
573+
case "urlencoded":
574+
m.Type = originalType + " > url encoded"
575+
vars := VariableData{
576+
KeyValues: b.URLEncoded,
577+
}
578+
m.LocationType = source_metadatapb.PostmanLocationType_REQUEST_BODY_URL_ENCODED
579+
s.scanVariableData(ctx, chunksChan, m, vars)
580+
m.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMAN
581+
case "raw":
582+
m.Type = originalType + " > raw"
583+
data := b.Raw
584+
m.LocationType = source_metadatapb.PostmanLocationType_REQUEST_BODY_RAW
585+
s.scanData(ctx, chunksChan, s.formatAndInjectKeywords(s.buildSubstitueSet(m, data)), m)
586+
m.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMAN
587+
case "graphql":
588+
m.Type = originalType + " > graphql"
589+
data := b.GraphQL.Query + " " + b.GraphQL.Variables
590+
m.LocationType = source_metadatapb.PostmanLocationType_REQUEST_BODY_GRAPHQL
591+
s.scanData(ctx, chunksChan, s.formatAndInjectKeywords(s.buildSubstitueSet(m, data)), m)
592+
m.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMAN
593+
}
556594
}
557595

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

0 commit comments

Comments
 (0)