{"id":42540,"library":"content-filter","title":"content-filter","description":"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.","status":"active","version":"1.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/efkan/content-filter","tags":["javascript","mongodb","mongodb security","mongo security","mongo protector","mongodb protector","mongodb protection","nosql protection","nosql security"],"install":[{"cmd":"npm install content-filter","lang":"bash","label":"npm"},{"cmd":"yarn add content-filter","lang":"bash","label":"yarn"},{"cmd":"pnpm add content-filter","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required to parse req.body before content-filter examines it.","package":"body-parser","optional":false}],"imports":[{"note":"ESM export is default; CommonJS require works but TypeScript may need 'esModuleInterop'.","wrong":"const filter = require('content-filter')","symbol":"default","correct":"import filter from 'content-filter'"},{"note":"The module exports a single function directly, not an object with a named export.","wrong":"const { filter } = require('content-filter')","symbol":"filter function","correct":"const filter = require('content-filter')"},{"note":"The exported function should be called (with optional config) to produce middleware; passing the function directly won't work.","wrong":"app.use(require('content-filter'))","symbol":"Express middleware","correct":"app.use(require('content-filter')())"}],"quickstart":{"code":"const express = require('express');\nconst bodyParser = require('body-parser');\nconst filter = require('content-filter');\n\nconst app = express();\napp.use(bodyParser.json());\napp.use(bodyParser.urlencoded({ extended: true }));\n\n// Apply content-filter with default settings\napp.use(filter());\n\napp.get('/', (req, res) => res.send('Hello world'));\napp.listen(3000, () => console.log('App listening on port 3000'));","lang":"javascript","description":"Shows how to integrate content-filter as Express middleware, including required body-parser setup."},"warnings":[{"fix":"npm install body-parser and use app.use(bodyParser.json()) and app.use(bodyParser.urlencoded({extended:true})) before the filter.","message":"body-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.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use app.use(filter()) instead of app.use(filter).","message":"The filter function must be called (with optional options) to return middleware; using app.use(filter) (without parentheses) will not work and may cause errors.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.1.2':30 'app':74 'attack':28 'bodi':13,78 'body-pars':77 'charact':17 'content':2,14,55 'content-filt':1 'depend':46,83 'e.g':25 'express.js':4 'filter':3,7,56 'forbidden':16 'general':54 'global':71 'html':12 'incom':8 'inject':27 'javascript':84 'latest':33 'level':75 'manual':63 'middlewar':5,69 'mongo':59,88,90 'mongo-sanit':58 'mongodb':26,85,86,92,94 'nosql':24,48,96,98 'packag':37 'parser':79 'pattern':20 'peer':82 'protect':22,95,97 'protector':91,93 'provid':21 'queri':67 'rare':41 'releas':35 'request':9 'requir':62,76 'sanit':60 'secur':87,89,99 'stabl':34,39 'unlik':57 'updat':42 'url':10 'usag':64 'use':52 'version':29 'word':18 'work':70","created_at":"2026-06-05T16:55:28.392944+00:00","updated_at":"2026-06-05T16:55:28.392944+00:00","problems":[{"fix":"Replace app.use(filter) with app.use(filter())","cause":"Attempting to use require('content-filter') directly as middleware without calling it.","error":"TypeError: filter is not a function"},{"fix":"Ensure body-parser is installed and the middleware is added before content-filter.","cause":"body-parser not installed or not used before content-filter, so req.body is undefined.","error":"Cannot read property 'post' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/efkan/content-filter#readme","github":"https://github.com/efkan/content-filter","docs":null,"changelog":null,"pypi":null,"npm":"content-filter","openapi_spec":null,"status_page":null,"smithery":null,"categories":["security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}