🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

molindo-node-logger

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

molindo-node-logger - npm Package Compare versions

Comparing version

to
1.3.0

5

CHANGELOG.md
# Changelog
## 1.3.0
Limit the size of logged `variables` for `meta.graphql` in the middleware logger
via `maxGraphQLVariablesLength`. It's possible that `variables` is a big object that could bloat the payload.
## 1.2.0

@@ -4,0 +9,0 @@

23

lib/createLoggerMiddleware.js

@@ -28,3 +28,3 @@ 'use strict';

exports.default = ({ logger }) => {
exports.default = ({ logger, maxGraphQLVariablesLength = 512 }) => {
const router = new _express.Router();

@@ -48,5 +48,24 @@ return router.use(_bodyParser2.default.json(), _expressWinston2.default.logger({

if (req.method === 'POST' && req.body && req.body.operationName) {
let variables = undefined;
if (maxGraphQLVariablesLength === -1) {
variables = req.body.variables;
} else if (maxGraphQLVariablesLength === 0) {
// Keep variables undefined
variables = undefined;
} else if (maxGraphQLVariablesLength > 0) {
const stringifiedVariables = JSON.stringify(req.body.variables);
const isTooLarge = stringifiedVariables.length > maxGraphQLVariablesLength;
if (isTooLarge) {
variables = `${stringifiedVariables.substring(0, maxGraphQLVariablesLength)} […] max payload length reached (${maxGraphQLVariablesLength} chars)`;
} else {
variables = req.body.variables;
}
}
meta.graphql = {
operationName: req.body.operationName,
variables: req.body.variables
variables
};

@@ -53,0 +72,0 @@ }

2

package.json
{
"name": "molindo-node-logger",
"version": "1.2.0",
"version": "1.3.0",
"description": "A node.js logger that integrates well with the Molindo infrastructure.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -42,3 +42,5 @@ # molindo-node-logger

If you're running an express server, you can register the logger middleware to log HTTP requests.
If you're running an express server, you can register the logger middleware to
log HTTP requests. GraphQL requests get automatically detected and attached as
`meta.graphql`, with properties `operationName` and the respective `variables`.

@@ -54,1 +56,10 @@ ```js

```
The size of `meta.graphql.variables` can sometimes grow too large to log
effectively. To manage this, the `createLoggerMiddleware()` function provides a configurable parameter:
`maxGraphQLVariablesLength`.
#### Configuration of `maxGraphQLVariablesLength`
* Set `maxGraphQLVariablesLength` (default: 512), to set the maximum size of the `meta.graphql.variables` payload to be logged.
* Set `maxGraphQLVariablesLength` to `0` to completely turn off logging for `meta.graphql.variables`.
* Set `maxGraphQLVariablesLength` to `-1` to include the complete `meta.graphql.variables` payload without size restrictions.