Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.

Commit 9cc9643

Browse files
authored
Merge pull request #249 from PerimeterX/release/v3.4.2
Release/v3.4.2
2 parents e19d41d + da9f950 commit 9cc9643

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and 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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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
1111
This 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

lib/pxutil.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,20 +269,34 @@ function getTokenObject(cookie, delimiter = ':') {
269269

270270
function 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+
286300
function extractGraphqlOperationType(query) {
287301
const isGraphqlQueryShorthand = query[0] === '{';
288302
if (isGraphqlQueryShorthand) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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": {

0 commit comments

Comments
 (0)