npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-request-audit

v1.0.3

Published

Middleware for auditing request/responses in Express apps

Downloads

240

Readme

NPM Version Build Status Test Coverage NPM Downloads MIT License

express-request-audit

Middleware for auditing request/responses in Express apps.

This work is derivated from express-requests-logger.

Supported features

  • Auditing request
  • Auditing 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:

$ npm install express-request-audit

API

var audit = require('express-request-audit')

audit(options)

Create an audit middleware with ther given options.

options

the express-request-audit accepts the following properties in the options object.

auditor

The auditor function that will act as s sink for the request/response stream of events.

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:

excludeURLs: ['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..).

maxBodyLength

Restrict response body's logged content length (inputs other than positive integers will be ignored).

Example

app.use(audit({
    auditor: function(event) {
        foo.doSomethingWith(event);
    }, 
    excludeURLs: [‘health’, ‘metrics’], // Exclude paths which enclude 'health' & 'metrics'
    request: {
        maskBody: [‘password’], // Mask 'password' field in incoming requests
        excludeHeaders: [‘authorization’], // Exclude 'authorization' header from requests
        excludeBody: [‘creditCard’], // Exclude 'creditCard' field from requests body
        maskHeaders: [‘header1’], // Mask 'header1' header in incoming requests
        maxBodyLength: 50 // limit length to 50 chars + '...'
    },
    response: {
        maskBody: [‘session_token’] // Mask 'session_token' field in response body
        excludeHeaders: [‘*’], // Exclude all headers from responses,
        excludeBody: [‘*’], // Exclude all body from responses
        maskHeaders: [‘header1’], // Mask 'header1' header in incoming requests
        maxBodyLength: 50 // limit length to 50 chars + '...'
    }
}));