Registry / security / content-filter

content-filter

JSON →
library1.1.2jsnpmunverified

Express.js middleware that filters incoming request URLs and HTML body contents for forbidden characters, words, or patterns, providing protection against NoSQL (e.g., MongoDB) injection attacks. Version 1.1.2 is the latest stable release; the package is stable but rarely updated. It does not depend on NoSQL and can be used for general content filtering. Unlike mongo-sanitize, which requires manual usage at each query, this middleware works globally at the app level. Requires body-parser as a peer dependency.

npm install content-filter
INSTALL
IMPORT
SIG · CONTENT-FILTER
C
content-filter
securityjavascriptv1.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import filter from 'content-filter'
const filter = require('content-filter')
ESM export is default; CommonJS require works but TypeScript may need 'esModuleInterop'.
filter function
const filter = require('content-filter')
const { filter } = require('content-filter')
The module exports a single function directly, not an object with a named export.
Express middleware
app.use(require('content-filter')())
app.use(require('content-filter'))
The exported function should be called (with optional config) to produce middleware; passing the function directly won't work.

Shows how to integrate content-filter as Express middleware, including required body-parser setup.

const express = require('express'); const bodyParser = require('body-parser'); const filter = require('content-filter'); const app = express(); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); // Apply content-filter with default settings app.use(filter()); app.get('/', (req, res) => res.send('Hello world')); app.listen(3000, () => console.log('App listening on port 3000'));
Debug
Known issues
gotchabody-parser is required but not included. You must install body-parser separately, otherwise req.body will be undefined and content-filter will not filter body content.
fix
npm install body-parser and use app.use(bodyParser.json()) and app.use(bodyParser.urlencoded({extended:true})) before the filter.
affects: >=0.0.0
gotchaThe filter function must be called (with optional options) to return middleware; using app.use(filter) (without parentheses) will not work and may cause errors.
fix
Use app.use(filter()) instead of app.use(filter).
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: filter is not a function
Attempting to use require('content-filter') directly as middleware without calling it.
fix
Replace app.use(filter) with app.use(filter())
Cannot read property 'post' of undefined
body-parser not installed or not used before content-filter, so req.body is undefined.
fix
Ensure body-parser is installed and the middleware is added before content-filter.
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies
body-parserrequiredRequired to parse req.body before content-filter examines it.
Agent activity
30 hits · last 30 days
node
26
Amazon
1
Resources
content-filter — npm install content-filter · libregistry