Installations
npm install express-requests-logger
Developer
ugolas
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
20.16.0
NPM Version
10.8.2
Statistics
43 Stars
107 Commits
20 Forks
16 Watching
22 Branches
20 Contributors
Updated on 28 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
1,090,977
Last day
13.6%
2,397
Compared to previous day
Last week
12.5%
12,866
Compared to previous week
Last month
1.6%
53,136
Compared to previous month
Last year
90.5%
479,659
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
express-request-logger
Middleware for logging request/responses in Express apps
Supported features
- Logging request
- Logging response
- Mask request body fields
- Exclude request body fields
- Exclude request specific headers
- Mask response body fields
- Exclude response body fields
- Exclude response specific headers
- Exclude specific URLs from logging
- Supported by Node v8 and above.
Installation
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm install express-requests-logger
API
1var audit = require('express-requests-logger')
audit(options)
Create an audit middleware with ther given options
.
options
the express-requests-logger
accepts the following properties in the options object.
logger
The logger to use for logging the request/response.
Package tested only with bunyan logger, but should work with any logger which has a info
method which takes an object.
shouldSkipAuditFunc
Should be a function, that returns boolean value to indicate whether to skip the audit for the current request. Usually the logic should be around the request/response params. Useful to provide a custom logic for cases we would want to skip logging specific request.
The default implementation of the function returns false.
Example, skipping logging of all success responses:
1shouldSkipAuditFunc: function(req, res){ 2 let shouldSkip = false; 3 if (res.statusCode === 200){ 4 // _bodyJson is added by this package 5 if (res._bodyJson.result === "success"){ 6 shouldSkip = true; 7 } 8 } 9 10 return shouldSkip; 11}
doubleAudit
true
- log once the request arrives (request details), and log after response is sent (both request and response). - Useful if there is a concern that the server will crash during the request and there is a need to log the request before it's processed.
false
- log only after the response is sent.
excludeURLs
Array of strings - if the request url matches one of the values in the array, the request/response won't be logged.
For example: if there is a path /v1/health
that we do not want to log, add:
1excludeURLs: ['health']
request
Specific configuration for requests
audit
Boolean - true
- include request in audit, false
- don't.
excludeBody
Array of strings - pass the fields you wish to exclude in the body of the requests (sensitive data like passwords, credit cards numbers etc..).
*
field - exclude all body
maskBody
Array of strings - pass the fields you wish to mask in the body of the requests (sensitive data like passwords, credit cards numbers etc..).
maskQuery
Array of strings - pass the fields you wish to mask in the query of the requests (sensitive data like passwords, credit cards numbers etc..).
excludeHeaders
Array of strings - pass the header names you wish to exclude from the audit (senstitive data like authorization headers etc..).
*
field - exclude all headers
maskHeaders
Array of strings - pass the fields you wish to mask in the headers of the requests (senstitive data like authorization headers etc..).
maxBodyLength
Restrict request body's logged content length (inputs other than positive integers will be ignored).
customMaskBodyFunc
Additional to mask options, you can add your own functionality to mask request body. This function will execute as a masking function before the package functions. The custom function gets the full express request and should return the masked body.
response
Specific configuration for responses
Doesn't print headers for Node below v6.9.2
Non JSON responses are not masked, and are logged as is. This is deducted from the response header content-type
audit
Boolean - true
- include response in audit, false
- don't.
excludeBody
Array of strings - pass the fields you wish to exclude in the body of the responses (sensitive data like passwords, credit cards numbers etc..).
*
field - exclude all body
maskBody
Array of strings - pass the fields you wish to mask in the body of the responses (sensitive data like passwords, credit cards numbers etc..).
excludeHeaders
Array of strings - pass the header names you wish to exclude from the audit (senstitive data like authorization headers etc..).
*
field - exclude all headers
maskHeaders
Array of strings - pass the fields you wish to mask in the headers of the responses (senstitive data like authorization headers etc..).
levels
Map of statusCodes to log levels. By default the audit is logged with level 'info'. It is possible to override it by configuration according to the statusCode of the response:
- Key: status code, or status code group: '2xx', '401', etc.. First we try to match by exact match (for example 400), if no key found by exact match we fallback to match bu group (4xx).
- Value: log level, valid values: 'trace', 'debug', 'info', 'warn', 'error'.
- Configuration errors are ignored and the log is info by default.
maxBodyLength
Restrict response body's logged content length (inputs other than positive integers will be ignored).
Example:
levels: {
"2xx":"info", // All 2xx responses are info
"401":"warn", // 401 are warn
"4xx':info", // All 4xx except 401 are info
"503":"warn",
"5xx":"error" // All 5xx except 503 are errors, 503 is warn,
}
Example
1app.use(audit({ 2 logger: logger, // Existing bunyan logger 3 excludeURLs: [‘health’, ‘metrics’], // Exclude paths which enclude 'health' & 'metrics' 4 request: { 5 maskBody: [‘password’], // Mask 'password' field in incoming requests 6 excludeHeaders: [‘authorization’], // Exclude 'authorization' header from requests 7 excludeBody: [‘creditCard’], // Exclude 'creditCard' field from requests body 8 maskHeaders: [‘header1’], // Mask 'header1' header in incoming requests 9 maxBodyLength: 50 // limit length to 50 chars + '...' 10 }, 11 response: { 12 maskBody: [‘session_token’] // Mask 'session_token' field in response body 13 excludeHeaders: [‘*’], // Exclude all headers from responses, 14 excludeBody: [‘*’], // Exclude all body from responses 15 maskHeaders: [‘header1’], // Mask 'header1' header in incoming requests 16 maxBodyLength: 50 // limit length to 50 chars + '...' 17 }, 18 shouldSkipAuditFunc: function(req, res){ 19 // Custom logic here.. i.e: return res.statusCode === 200 20 return false; 21 } 22}));
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/release.yaml:6
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yaml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/PayU/express-request-logger/ci.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yaml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/PayU/express-request-logger/ci.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yaml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/PayU/express-request-logger/ci.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yaml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/PayU/express-request-logger/ci.yaml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yaml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/PayU/express-request-logger/ci.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yaml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/PayU/express-request-logger/release.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yaml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/PayU/express-request-logger/release.yaml/master?enable=pin
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
Reason
Found 10/25 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yaml:1
- Warn: no topLevel permission defined: .github/workflows/release.yaml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 18 are checked with a SAST tool
Reason
10 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
Score
3.6
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More