mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Use json parser wrapper function to prevent pollution attacks (#13191)
This commit is contained in:
@@ -3,6 +3,7 @@ import { DocumentNode, getOperationAST, parse, Source } from 'graphql';
|
||||
import { InvalidPayloadException, InvalidQueryException, MethodNotAllowedException } from '../exceptions';
|
||||
import { GraphQLParams } from '../types';
|
||||
import asyncHandler from '../utils/async-handler';
|
||||
import { parseJSON } from '../utils/parse-json';
|
||||
|
||||
export const parseGraphQL: RequestHandler = asyncHandler(async (req, res, next) => {
|
||||
if (req.method !== 'GET' && req.method !== 'POST') {
|
||||
@@ -19,7 +20,7 @@ export const parseGraphQL: RequestHandler = asyncHandler(async (req, res, next)
|
||||
|
||||
if (req.query.variables) {
|
||||
try {
|
||||
variables = JSON.parse(req.query.variables as string);
|
||||
variables = parseJSON(req.query.variables as string);
|
||||
} catch {
|
||||
throw new InvalidQueryException(`Variables are invalid JSON.`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user