password fields are accessible only via /admin endpoint hence, this will be only called with /admin endpoint
(req string)
| 246 | // password fields are accessible only via /admin endpoint hence, |
| 247 | // this will be only called with /admin endpoint |
| 248 | func 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 | |
| 296 | func getMaskedFieldVarName(f *ast.Field) string { |
| 297 | switch f.Name { |
no test coverage detected
searching dependent graphs…