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

Added support for GraphQL #76

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
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
37 changes: 19 additions & 18 deletions internal/security_utils/global_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,25 @@ type ResponseInfo struct {
}

type RequestInfo struct {
Body string `json:"body"`
Headers map[string]string `json:"headers"`
URL string `json:"url"`
RawRequest string `json:"rawRequest"`
Method string `json:"method"`
ContentType string `json:"contentType"`
ContextPath string `json:"contextPath"`
ClientIP string `json:"clientIP"`
ClientPort string `json:"clientPort"`
ServerPort string `json:"serverPort"`
Protocol string `json:"protocol"`
ParameterMap map[string][]string `json:"parameterMap"`
IsGRPC bool `json:"isGrpc"`
ServerName string `json:"serverName"`
DataTruncated bool `json:"dataTruncated"`
BodyReader SecWriter `json:"-"`
Route string `json:"route"`
URI string `json:"requestURI"`
Body string `json:"body"`
Headers map[string]string `json:"headers"`
URL string `json:"url"`
RawRequest string `json:"rawRequest"`
Method string `json:"method"`
ContentType string `json:"contentType"`
ContextPath string `json:"contextPath"`
ClientIP string `json:"clientIP"`
ClientPort string `json:"clientPort"`
ServerPort string `json:"serverPort"`
Protocol string `json:"protocol"`
ParameterMap map[string][]string `json:"parameterMap"`
IsGRPC bool `json:"isGrpc"`
ServerName string `json:"serverName"`
DataTruncated bool `json:"dataTruncated"`
BodyReader SecWriter `json:"-"`
Route string `json:"route"`
URI string `json:"requestURI"`
CustomDataType map[string]string `json:"customDataType"`
}

type SecWriter struct {
Expand Down
1 change: 1 addition & 0 deletions internal/security_utils/security_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Secureiface interface {
AssociateGoRoutine(caller, callee int64)
AssociateGrpcDataBytes([]byte) bool
AssociateGrpcInfo(bool, bool)
AssociategraphqlInfo(bool, bool)
InitSyms() error
CalculateOutboundApiId()
AssociateGrpcData(string, string)
Expand Down
18 changes: 18 additions & 0 deletions security_implementation/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,24 @@ func (k Secureimpl) NewGoroutineLinker(req interface{}) {
}
}

func (k Secureimpl) AssociategraphqlInfo(isQuery, isVariable bool) {
request := getRequest(getID())
if request == nil {
logger.Debugln("(AssociategraphqlInfo) Request Not Found")
return
}
if request.Request.CustomDataType == nil {
request.Request.CustomDataType = map[string]string{}
}
if isQuery {
request.Request.CustomDataType["*.query"] = "GRAPHQL_QUERY"
}
if isVariable {
request.Request.CustomDataType["*.variables"] = "GRAPHQL_VARIABLE"
}

}

/**
* Implementation for goroutines (created and deleted)
*/
Expand Down
11 changes: 5 additions & 6 deletions security_instrumentation/sec_httpfuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"net"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -81,11 +80,11 @@ func (httpFuzz SecHttpFuzz) ExecuteFuzzRequest(fuzzRequest *sechandler.FuzzRequr
secConfig.GlobalInfo.IastReplayRequest.IncreaseReplayRequestFailed()
return
}

v, err := url.ParseQuery(req.URL.RawQuery)
if err == nil {
req.URL.RawQuery = v.Encode()
}
req, _ = http.NewRequest(fuzzRequest.Method, fuzzRequestURL, strings.NewReader(fuzzRequest.Body))
// v, err := url.ParseQuery(req.URL.RawQuery)
// if err == nil {
// req.URL.RawQuery = v.Encode()
// }

for headerKey, headerValue := range fuzzRequest.Headers {
value := fmt.Sprintf("%v", headerValue)
Expand Down
17 changes: 17 additions & 0 deletions security_intercept/intercept.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ func SendEvent(caseType string, data ...interface{}) interface{} {
dynamodbHandler(data...)
case "REDIS":
redisHandler(data...)
case "GRAPHQL":
graphqlHandler(data...)

}
return nil
Expand Down Expand Up @@ -968,6 +970,21 @@ func redisHandler(data ...interface{}) {
secConfig.Secure.SendEvent("REDIS_DB_COMMAND", "REDIS", data)
}

func graphqlHandler(data ...interface{}) {
if data == nil || !isAgentInitialized() {
return
}
if len(data) < 2 {
return
}
query, ok := data[0].(bool)
variable, ok1 := data[1].(bool)
if ok && ok1 {
secConfig.Secure.AssociategraphqlInfo(query, variable)
}

}

func panicHandler(data ...interface{}) {

if nil == data || len(data) == 0 || !isAgentInitialized() {
Expand Down
Loading