Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent infinite loop on invalid introspection #1509

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/utilities/__tests__/buildClientSchema-test.js
Expand Up @@ -844,4 +844,41 @@ describe('Type System: build schema from introspection', () => {
buildClientSchema(introspection);
});
});

describe('prevents infinite recursion on invalid introspection', () => {
it('recursive interfaces', () => {
const introspection = {
__schema: {
types: [
{
name: 'Foo',
kind: 'OBJECT',
fields: [],
interfaces: [{ name: 'Foo' }],
},
],
},
};
expect(() => buildClientSchema(introspection)).to.throw(
'Expected Foo to be a GraphQL Interface type.',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change it thrown:

Maximum call stack size exceeded

);
});

it('recursive union', () => {
const introspection = {
__schema: {
types: [
{
name: 'Foo',
kind: 'UNION',
possibleTypes: [{ name: 'Foo' }],
},
],
},
};
expect(() => buildClientSchema(introspection)).to.throw(
'Expected Foo to be a GraphQL Object type.',
);
});
});
});
4 changes: 2 additions & 2 deletions src/utilities/buildClientSchema.js
Expand Up @@ -221,7 +221,7 @@ export function buildClientSchema(
return new GraphQLObjectType({
name: objectIntrospection.name,
description: objectIntrospection.description,
interfaces: objectIntrospection.interfaces.map(getInterfaceType),
interfaces: () => objectIntrospection.interfaces.map(getInterfaceType),
fields: () => buildFieldDefMap(objectIntrospection),
});
}
Expand All @@ -248,7 +248,7 @@ export function buildClientSchema(
return new GraphQLUnionType({
name: unionIntrospection.name,
description: unionIntrospection.description,
types: unionIntrospection.possibleTypes.map(getObjectType),
types: () => unionIntrospection.possibleTypes.map(getObjectType),
});
}

Expand Down