Registry / security / perfect-express-sanitizer

perfect-express-sanitizer

JSON →
library2.0.2jsnpmunverified

perfect-express-sanitizer is an Express.js middleware and utility library for sanitizing user input against Cross-Site Scripting (XSS), SQL injection, and NoSQL injection attacks. Version 2.0.2, released periodically, provides middleware to clean request body, query, and headers. It supports custom forbidden keywords and regular expressions, customizable cleanup levels, and can be used standalone for string sanitation. Unlike express-validator or helmet, this package focuses specifically on input sanitization with aggressive removal of malicious patterns, though it has limited documentation and may produce false positives.

npm install perfect-express-sanitizer
INSTALL
IMPORT
SIG · PERFECT-EXPRESS-SA
P
perfect-express-sanitizer
securityjavascriptv2.0.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 (require)
const sanitizer = require('perfect-express-sanitizer');
import sanitizer from 'perfect-express-sanitizer';
Package does not export ESM; use CommonJS require().
sanitize.prepareSanitize
const result = sanitizer.sanitize.prepareSanitize(input, options);
const result = sanitizer.prepareSanitize(input, options);
Method is nested under .sanitize object.
clean (middleware)
sanitizer.clean({ xss: true, sql: true });
sanitizer({ xss: true });
Middleware factory is .clean(), not the default export.

Sets up Express middleware to automatically sanitize request body, query, and headers.

const express = require('express'); const sanitizer = require('perfect-express-sanitizer'); const app = express(); app.use(express.json()); app.use(sanitizer.clean({ xss: true, noSql: true, sql: true, level: 5 })); app.post('/message', (req, res) => { res.json({ sanitizedBody: req.body }); }); app.listen(3000, () => console.log('Running on port 3000'));
Debug
Known issues
breakingPre-1.0 versions had different API (e.g., direct function call instead of .clean()).
fix
Update to v2 and use sanitizer.clean({...}) or sanitizer.sanitize.prepareSanitize().
affects: <1.0.0
deprecatedSome options like 'sql' and 'noSql' might be deprecated in future versions.
fix
Check changelog for option removals; use 'level' to control aggressiveness.
affects: >=2.0.0
gotchaSanitization may corrupt legitimate data (e.g., removing safe SQL keywords). Use low 'level' or customize forbidden tags.
fix
Set level: 2-3 and add exceptions via customizeFile or forbiddenTags.
affects: >=1.0.0
gotchaNo official TypeScript definitions; TypeScript projects may need custom type declarations.
fix
Create a .d.ts file or use @ts-ignore.
affects: >=1.0.0
gotchaSanitization applies to entire req.body/query/headers; cannot target specific fields.
fix
Use sanitizer.sanitize.prepareSanitize() on individual strings instead of middleware.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: sanitizer.clean is not a function
Incorrect import or using old version where API used direct function call.
fix
Ensure version >=1.0.0 and use const sanitizer = require('perfect-express-sanitizer'); then sanitizer.clean({...}).
Cannot find module 'perfect-express-sanitizer'
Package not installed or typo in package name.
fix
Run 'npm install perfect-express-sanitizer' and verify package.json.
ReferenceError: sanitizer is not defined
Missing require() statement or variable scoping error.
fix
Add const sanitizer = require('perfect-express-sanitizer'); at the top of your file.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
perfect-express-sanitizer — npm install perfect-express-sanitizer · libregistry