This repository was archived by the owner on Oct 29, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +27
-7
lines changed
Expand file tree Collapse file tree 4 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
66and this project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
77
8+ ## [ 3.4.2] - 2022-06-06
9+
10+ ### Fixed
11+
12+ - GraphQL - parsed operation name issue
13+
814## [ 3.4.1] - 2022-05-18
915
1016### Added
Original file line number Diff line number Diff line change 66[ PerimeterX] ( http://www.perimeterx.com ) Shared base for NodeJS enforcers
77=============================================================
88
9- > Latest stable version: [ v3.4.1 ] ( https://www.npmjs.com/package/perimeterx-node-core )
9+ > Latest stable version: [ v3.4.2 ] ( https://www.npmjs.com/package/perimeterx-node-core )
1010
1111This is a shared base implementation for PerimeterX Express enforcer and future NodeJS enforcers. For a fully functioning implementation example, see the [ Node-Express enforcer] ( https://github.com/PerimeterX/perimeterx-node-express/ ) implementation.
1212
Original file line number Diff line number Diff line change @@ -269,20 +269,34 @@ function getTokenObject(cookie, delimiter = ':') {
269269
270270function getGraphqlData ( req ) {
271271 const isGraphqlPath = req . path . includes ( 'graphql' ) || req . originalUrl . includes ( 'graphql' ) ;
272- if ( ! isGraphqlPath ) {
272+ if ( ! isGraphqlPath || ! req . body ) {
273273 return null ;
274274 }
275275
276- const query = req . body ? req . body [ ' query' ] : null ;
277- if ( ! query ) {
278- return new GraphqlData ( GraphqlOperationType . QUERY ) ;
276+ const { body, query } = getGraphqlBodyAndQuery ( req ) ;
277+ if ( ! body || ! query ) {
278+ return null ;
279279 }
280280
281281 const operationType = extractGraphqlOperationType ( query ) ;
282- const operationName = extractGraphqlOperationName ( query , req . body [ 'operationName' ] )
282+ const operationName = extractGraphqlOperationName ( query , body [ 'operationName' ] )
283283 return new GraphqlData ( operationType , operationName ) ;
284284}
285285
286+ function getGraphqlBodyAndQuery ( req ) {
287+ let body = { } ;
288+ let query = '' ;
289+
290+ try {
291+ body = typeof req . body === 'string' ? JSON . parse ( req . body ) : req . body ;
292+ query = body [ 'query' ] ;
293+ } catch ( err ) {
294+ // json parse error
295+ }
296+
297+ return { body, query } ;
298+ }
299+
286300function extractGraphqlOperationType ( query ) {
287301 const isGraphqlQueryShorthand = query [ 0 ] === '{' ;
288302 if ( isGraphqlQueryShorthand ) {
Original file line number Diff line number Diff line change 11{
22 "name" : " perimeterx-node-core" ,
3- "version" : " 3.4.1 " ,
3+ "version" : " 3.4.2 " ,
44 "description" : " PerimeterX NodeJS shared core for various applications to monitor and block traffic according to PerimeterX risk score" ,
55 "main" : " index.js" ,
66 "scripts" : {
You can’t perform that action at this time.
0 commit comments