MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / maskPasswordFieldsInGQL

Function maskPasswordFieldsInGQL

audit/interceptor.go:248–294  ·  view source on GitHub ↗

password fields are accessible only via /admin endpoint hence, this will be only called with /admin endpoint

(req string)

Source from the content-addressed store, hash-verified

246// password fields are accessible only via /admin endpoint hence,
247// this will be only called with /admin endpoint
248func maskPasswordFieldsInGQL(req string) string {
249 var gqlReq schema.Request
250 err := json.Unmarshal([]byte(req), &gqlReq)
251 if err != nil {
252 glog.Errorf("unable to unmarshal gql request %v", err)
253 return req
254 }
255 query, gErr := parser.ParseQuery(&ast.Source{
256 Input: gqlReq.Query,
257 })
258 if gErr != nil {
259 glog.Errorf("unable to parse gql request %+v", gErr)
260 return req
261 }
262 if len(query.Operations) == 0 {
263 return req
264 }
265 var variableName string
266 for _, op := range query.Operations {
267 if op.Operation != ast.Mutation || len(op.SelectionSet) == 0 {
268 continue
269 }
270
271 for _, ss := range op.SelectionSet {
272 if f, ok := ss.(*ast.Field); ok && len(f.Arguments) > 0 {
273 variableName = getMaskedFieldVarName(f)
274 }
275 }
276 }
277
278 // no variable present
279 if variableName == "" {
280 regex, err := regexp.Compile(
281 `password[\s]?(.*?)[\s]?:[\s]?(.*?)[\s]?"[\s]?(.*?)[\s]?"`)
282 if err != nil {
283 return req
284 }
285 return regex.ReplaceAllString(req, "*******")
286 }
287 regex, err := regexp.Compile(
288 fmt.Sprintf(`"%s[\s]?(.*?)[\s]?"[\s]?(.*?)[\s]?:[\s]?(.*?)[\s]?"[\s]?(.*?)[\s]?"`,
289 variableName[1:]))
290 if err != nil {
291 return req
292 }
293 return regex.ReplaceAllString(req, "*******")
294}
295
296func getMaskedFieldVarName(f *ast.Field) string {
297 switch f.Name {

Callers 1

checkRequestBodyFunction · 0.85

Calls 2

getMaskedFieldVarNameFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…