Skip to content

Commit 6110908

Browse files
committed
Use JSON.generate for GraphQL Introspection queries
1 parent 4075e1a commit 6110908

File tree

1 file changed

+62
-65
lines changed

1 file changed

+62
-65
lines changed

modules/auxiliary/scanner/http/graphql_introspection_scanner.rb

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,15 @@ def process_query(query)
6464
# Create a small query, used to test if introspection is enabledo n the GraphQL endpoint.
6565
# @return [String] The processed introspection probe query.
6666
def introspection_probe_query
67-
raw_query = '{"query": "
67+
<<~EOF
6868
query {
6969
__schema {
7070
queryType {
7171
name
7272
}
7373
}
74-
}"
75-
}'
76-
process_query(raw_query)
74+
}
75+
EOF
7776
end
7877

7978
# Create a unique query that will try to dump the GraphQL schema.
@@ -88,79 +87,75 @@ def schema_dump_query
8887
type_reference: Rex::Text.rand_text_alpha(8)
8988
}
9089

91-
# Remove extra spaces, and new lines.
92-
# Remember, fragments need to be present at the end, outside the curly braces, but as part
93-
# of the quoted 'query' param.
94-
raw_query = "{\"query\": \"query {
95-
__schema {
96-
queryType {
97-
name
98-
}
99-
mutationType {
100-
name
101-
}
102-
subscriptionType {
103-
name
90+
# Fragments need to be present at the end, outside the curly braces of the 'query'
91+
<<~EOF
92+
query {
93+
__schema {
94+
queryType {
95+
name
96+
}
97+
mutationType {
98+
name
99+
}
100+
subscriptionType {
101+
name
102+
}
103+
types {
104+
...#{vars_map[:type_fragment]}
105+
}
106+
directives {
107+
name
108+
description
109+
args {
110+
...#{vars_map[:input_fragment]}
111+
}
112+
}
104113
}
105-
types {
106-
...#{vars_map[:type_fragment]}
114+
}
115+
fragment #{vars_map[:type_fragment]} on __Type {
116+
kind
117+
name
118+
description
119+
inputFields {
120+
...#{vars_map[:input_fragment]}
107121
}
108-
directives {
122+
fields(includeDeprecated: true) {
109123
name
110124
description
125+
isDeprecated
126+
deprecationReason
111127
args {
112128
...#{vars_map[:input_fragment]}
113129
}
130+
type {
131+
...#{vars_map[:type_reference]}
132+
}
114133
}
115-
}
116-
}
117-
fragment #{vars_map[:type_fragment]} on __Type {
118-
kind
119-
name
120-
description
121-
inputFields {
122-
...#{vars_map[:input_fragment]}
123-
}
124-
fields(includeDeprecated: true) {
125-
name
126-
description
127-
isDeprecated
128-
deprecationReason
129-
args {
134+
inputFields {
130135
...#{vars_map[:input_fragment]}
131136
}
132-
type {
137+
interfaces {
138+
...#{vars_map[:type_reference]}
139+
}
140+
enumValues(includeDeprecated: true) {
141+
name
142+
description
143+
isDeprecated
144+
deprecationReason
145+
}
146+
possibleTypes {
133147
...#{vars_map[:type_reference]}
134148
}
135149
}
136-
inputFields {
137-
...#{vars_map[:input_fragment]}
138-
}
139-
interfaces {
140-
...#{vars_map[:type_reference]}
141-
}
142-
enumValues(includeDeprecated: true) {
150+
fragment #{vars_map[:input_fragment]} on __InputValue {
143151
name
144152
description
145-
isDeprecated
146-
deprecationReason
147-
}
148-
possibleTypes {
149-
...#{vars_map[:type_reference]}
150-
}
151-
}
152-
fragment #{vars_map[:input_fragment]} on __InputValue {
153-
name
154-
description
155-
defaultValue
156-
type {
157-
...#{vars_map[:type_reference]}
153+
defaultValue
154+
type {
155+
...#{vars_map[:type_reference]}
156+
}
158157
}
159-
}
160-
fragment #{vars_map[:type_reference]} on __Type {
161-
kind
162-
name
163-
ofType {
158+
fragment #{vars_map[:type_reference]} on __Type {
164159
kind
165160
name
166161
ofType {
@@ -169,12 +164,14 @@ def schema_dump_query
169164
ofType {
170165
kind
171166
name
167+
ofType {
168+
kind
169+
name
170+
}
172171
}
173172
}
174173
}
175-
}
176-
\"}"
177-
process_query(raw_query)
174+
EOF
178175
end
179176

180177
# Report a GraphQL instance on the current host and port.
@@ -239,7 +236,7 @@ def send_graphql_request(query)
239236
'headers' => {
240237
'Accept' => 'application/json'
241238
},
242-
'data' => query
239+
'data' => JSON.generate({ query: query })
243240
)
244241
end
245242

0 commit comments

Comments
 (0)