Skip to content

Commit 22fce03

Browse files
committed
fix: block fragment with introspection
1 parent a49c5f6 commit 22fce03

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

spec/ParseGraphQLServer.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,30 @@ describe('ParseGraphQLServer', () => {
770770
}
771771
});
772772

773+
it('should block __type introspection in fragments without master key', async () => {
774+
try {
775+
await apolloClient.query({
776+
query: gql`
777+
fragment TypeIntrospectionFields on Query {
778+
typeInfo: __type(name: "User") {
779+
name
780+
kind
781+
}
782+
}
783+
784+
query FragmentTypeIntrospection {
785+
...TypeIntrospectionFields
786+
}
787+
`,
788+
});
789+
790+
fail('should have thrown an error');
791+
} catch (e) {
792+
expect(e.message).toEqual('Response not successful: Received status code 403');
793+
expect(e.networkError.result.errors[0].message).toEqual('Introspection is not allowed');
794+
}
795+
});
796+
773797
it('should allow __type introspection with master key', async () => {
774798
const introspection = await apolloClient.query({
775799
query: gql`

src/GraphQL/ParseGraphQLServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const hasTypeIntrospection = (query) => {
2020
// Note: selection.name.value is the actual field name, so this correctly handles
2121
// aliases like "myAlias: __type(...)" where name.value === "__type"
2222
for (const definition of ast.definitions) {
23-
if (definition.kind === 'OperationDefinition' && definition.selectionSet) {
23+
if ((definition.kind === 'OperationDefinition' || definition.kind === 'FragmentDefinition') && definition.selectionSet) {
2424
for (const selection of definition.selectionSet.selections) {
2525
if (selection.kind === 'Field' && selection.name.value === '__type') {
2626
// GraphQL's introspection __type field requires a 'name' argument

0 commit comments

Comments
 (0)