mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-13 13:22:01 +00:00
Add GraphQL detection (#980)
* Add GraphQL detection * Change the abbreviation to `GQL` * Fix the `TestMacros` test case * Try to fix the security issues reported by Snyk * Run `go mod tidy` in `agent` directory * Upgrade `golang.org/x/crypto` * Downgrade `golang.org/x/crypto` * Downgrade `golang.org/x/crypto` * Downgrade `golang.org/x/crypto` * Upgrade to `github.com/vektah/gqlparser/v2 v2.4.2` * Run `go mod tidy` * Replace `github.com/vektah/gqlparser/v2` with its fork `github.com/mertyildiran/gqlparser/v2` to fix the vulns * Upgrade the `github.com/mertyildiran/gqlparser/v2 v2.4.6` * Don't upgrade `golang.org/x/net`
This commit is contained in:
31
tap/extensions/http/graphql.go
Normal file
31
tap/extensions/http/graphql.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mertyildiran/gqlparser/v2/ast"
|
||||
"github.com/mertyildiran/gqlparser/v2/parser"
|
||||
)
|
||||
|
||||
func isGraphQL(request map[string]interface{}) bool {
|
||||
if postData, ok := request["postData"].(map[string]interface{}); ok {
|
||||
if postData["mimeType"] == "application/json" {
|
||||
if text, ok := postData["text"].(string); ok {
|
||||
var data map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(text), &data); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if query, ok := data["query"].(string); ok {
|
||||
|
||||
_, err := parser.ParseQuery(&ast.Source{Name: "ff", Input: query})
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user