0.2.2 • Published 11 months ago

sanitware v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Express sanitizer middleware

Express middleware to sanitize JSON responses.

⚠️ When using this, please thoroughly test your code. My personal use case is very limited and I can make no guarantees about the effectivity of this package.

⚠️ This will only sanitize responses when sent using res.json(...) in Express.

Install

Install using

npm install sanitware

Usage

Using this is middleware is as simple as using it at the level desired.

It is used like any other Express middleware. More info can be found on the Express site.

It's recommended to use this at the finest level possible, i.e. only on the routes needed.

sanitize(sanitizeOn: string[] | string, positive: boolean)

This will remove any properties defined by sanitizeOn from the response body object sent with res.json.

sanitizeOn

Prop keys to clean (or keep) from the response object.

positive

The "direction" to sanitize. Positive sanitization will keep the given keys in the response body object. Negative sanitization will do the opposite, removing the given keys.

false (default): negative sanitization
true: positive sanitization. sanitize([], true) will return {}.

Example

This is an example of how to use this on the route-level of an Express app.

import { Router } from 'express';
import { sanitize } from 'sanitware';
// ...

const myCoolRoutes = Router();
const removeKeys = [
    'password',
    'PII',
    // etc...?
];
myCoolRoutes.use(sanitizer(removeKeys));
// ...

// routes, exports, etc...
0.2.2

11 months ago

0.2.1

12 months ago

0.2.0

12 months ago

0.1.0

12 months ago