Skip to content

Commit 9e4d0c9

Browse files
committed
Try to handle more errors for GraphQL Introspection
1 parent 7277210 commit 9e4d0c9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

modules/auxiliary/scanner/http/graphql_introspection_scanner.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,12 @@ def send_graphql_request(query)
239239
def process_errors(errors)
240240
return '' if errors&.empty?
241241

242-
errors.map { |error| " - #{error['message']}" }&.join("\n") || ''
242+
# APIs aren't consistent. Some have an error message, some have title & detail.
243+
# Match all the known cases so far, otherwise return the inspected value.
244+
245+
errors.map do |error|
246+
" - #{error['message'] || error['detail'] || error['description']}"
247+
end.join("\n") || ''
243248
end
244249

245250
# Check if the current endpoint is vulnerable to GraphQL Introspection information disclosure.
@@ -261,7 +266,7 @@ def check
261266
return Exploit::CheckCode::Vulnerable('The server has introspection enabled.')
262267
when 400
263268
parsed_body = JSON.parse!(res.body)
264-
error_messages = process_errors(parsed_body['errors'])
269+
error_messages = process_errors(parsed_body['errors'] || Array.wrap(parsed_body['error']))
265270
safe_message = "The server responded with an error status code and the following error(s) to the introspection request:\n#{error_messages}"
266271
return Exploit::CheckCode::Safe(safe_message)
267272
when 403
@@ -296,8 +301,8 @@ def run
296301
store_loot('graphql.schema', 'json', rhost, res.body, 'graphql-schema.json', 'GraphQL Schema Dump', graphql_service)
297302
else
298303
parsed_body = JSON.parse!(res.body)
299-
if parsed_body.include?('errors')
300-
print_error("#{rhost}:#{rport} - Server encountered the following error(s) (code: '#{res.code}'):\n#{process_errors(parsed_body['errors'])}")
304+
if parsed_body.include?('errors') || parsed_body.include?('error')
305+
print_error("#{rhost}:#{rport} - Server encountered the following error(s) (code: '#{res.code}'):\n#{process_errors(parsed_body['errors'] || Array.wrap(parsed_body['error']))}")
301306
else
302307
print_error("#{rhost}:#{rport} - Server replied with an unexpected status code: '#{res.code}'")
303308
end

0 commit comments

Comments
 (0)