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

[Security] get queries did not run through validation #424

Merged
merged 5 commits into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

### VNEXT
* **Security Fix** GET queries did not run through validation ([@DxCx](https://github.com/DxCx)) on [#424](https://github.com/apollographql/graphql-server/pull/424)

### v0.8.0
* Persist `window.location.hash` on URL updates [#386](https://github.com/apollographql/graphql-server/issues/386)
Expand Down
7 changes: 1 addition & 6 deletions packages/graphql-server-core/src/runHttpQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ export async function runHttpQuery(handlerArguments: Array<any>, request: HttpQu
try {
let query = requestParams.query;
if ( isGetRequest ) {
if (typeof query === 'string') {
// preparse the query incase of GET so we can assert the operation.
query = parse(query);
}

if ( ! isQueryOperation(query, requestParams.operationName) ) {
if ( ! isQueryOperation(parse(query), requestParams.operationName) ) {
throw new HttpQueryError(405, `GET supports only query operation`, false, {
'Allow': 'POST',
});
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-server-core/src/runQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function doRunQuery(options: QueryOptions): Promise<ExecutionResult> {
logFunction({action: LogAction.request, step: LogStep.status, key: 'operationName', data: options.operationName});

// if query is already an AST, don't parse or validate
// XXX: This refers the operations-store flow.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by this comment exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i wanted to disable getting to runQuery with document parsed to eliminate this flow at all.
but i've seen the module-operation-store depends on that "feature".

if (typeof options.query === 'string') {
try {
// TODO: time this with log function
Expand Down
25 changes: 22 additions & 3 deletions packages/graphql-server-express/src/apolloServerHttp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,33 @@ describe(`GraphQL-HTTP (apolloServer) tests for ${version} express`, () => {
const response = await request(app)
.post(urlString())
.send({
query: '{test(who: 123)}',
query: '{notExists}',
});

expect(response.status).to.equal(400);
expect(JSON.parse(response.text)).to.deep.equal({
errors: [ {
message: 'Argument \"who\" has invalid value 123.\nExpected type \"String\", found 123.',
locations: [ { line: 1, column: 12 } ],
message: 'Cannot query field \"notExists\" on type \"QueryRoot\".',
locations: [ { line: 1, column: 2 } ],
} ]
});
});

it('handles type validation (GET)', async () => {
const app = express();

app.use(urlString(), graphqlExpress({
schema: TestSchema
}));

const response = await request(app)
.get(urlString({ query: '{notExists}' }))

expect(response.status).to.equal(400);
expect(JSON.parse(response.text)).to.deep.equal({
errors: [ {
message: 'Cannot query field \"notExists\" on type \"QueryRoot\".',
locations: [ { line: 1, column: 2 } ],
} ]
});
});
Expand Down
1 change: 0 additions & 1 deletion packages/graphql-server-restify/src/restifyApollo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { graphiqlRestify, graphqlRestify } from './restifyApollo';
import testSuite, { schema, CreateAppOptions } from 'graphql-server-integration-testsuite';
import { expect } from 'chai';
import { GraphQLOptions } from 'graphql-server-core';
import 'mocha';

function createApp(options: CreateAppOptions = {}) {
const server = restify.createServer({
Expand Down
5 changes: 4 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ require('../packages/graphql-server-express/dist/connectApollo.test');
require('../packages/graphql-server-hapi/dist/hapiApollo.test');
(NODE_MAJOR_VERSION >= 6) && require('../packages/graphql-server-micro/dist/microApollo.test');
(NODE_MAJOR_VERSION >= 7) && require('../packages/graphql-server-koa/dist/koaApollo.test');
require('../packages/graphql-server-restify/dist/restifyApollo.test');
require('../packages/graphql-server-lambda/dist/lambdaApollo.test');
require('../packages/graphql-server-express/dist/apolloServerHttp.test');

// XXX: Running restify last as it breaks http.
// for more info: https://github.com/restify/node-restify/issues/700
require('../packages/graphql-server-restify/dist/restifyApollo.test');