Gathering detailed insights and metrics for body-parser-xml
Gathering detailed insights and metrics for body-parser-xml
Gathering detailed insights and metrics for body-parser-xml
Gathering detailed insights and metrics for body-parser-xml
npm install body-parser-xml
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.4
Supply Chain
99.5
Quality
75.5
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
37 Stars
52 Commits
10 Forks
3 Watchers
10 Branches
5 Contributors
Updated on May 10, 2024
Latest Version
2.0.5
Package Id
body-parser-xml@2.0.5
Unpacked Size
15.98 kB
Size
5.51 kB
File Count
10
NPM Version
8.15.0
Node Version
16.17.0
Published on
Apr 11, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Adds XML parsing to the body-parser library, so you can convert incoming XML data into a JSON representation.
This is really useful if you want to deal with plain old JavaScript objects, but you need to interface with XML APIs.
npm install express body-parser body-parser-xml
This library adds an xml
method to the body-parser
object.
Initialise like so:
1const bodyParser = require('body-parser'); 2require('body-parser-xml')(bodyParser);
Once initialised, you can use it just like any other body-parser
middleware:
1const app = require('express')(); 2app.use(bodyParser.xml());
This will parse any XML-based request and place it as a JavaScript object on req.body
for your route handlers to use.
An XML-based request is determined by the value of the Content-Type
header. By default, any Content-Type
header ending in /xml
or +xml
will be parsed as XML. For example, the following Content-Types will all match:
text/xml
application/xml
application/rss+xml
If you need to match against a custom Content-Type
header, pass in the type
to match as an option (see below).
You can also pass in options:
1app.use(bodyParser.xml(options));
The options
object accepts any of the following keys:
Specify the default character set for the text content if the charset is not specified in the Content-Type
header of the request. Defaults to utf-8
.
When set to true
, then deflated (compressed) bodies will be inflated; when false
, deflated bodies are rejected. Defaults to true
.
Controls the maximum request body size. If this is a number, then the value specifies the number of bytes; if it is a string, the value is passed to the bytes library for parsing. Defaults to '100kb'
.
The type option is used to determine what media type the middleware will parse. This option can be a string, array of strings, or a function. If not a function, type option is passed directly to the type-is library and this can be an extension name (like xml), a mime type (like application/xml), or a mime type with a wildcard (like / or _/xml). If a function, the type option is called as fn(req) and the request is parsed if it returns a truthy value. Defaults to ['_/xml', '+xml']
.
The verify
option, if supplied, is called as verify(req, res, buf, encoding)
, where buf
is a Buffer
of the raw request body and encoding
is the encoding of the request. The parsing can be aborted by throwing an error.
This option controls the behaviour of the XML parser. You can pass any option that is supported by the xml2js library: see here for a list of these options.
1const express = require('express'); 2const bodyParser = require('body-parser'); 3 4require('body-parser-xml')(bodyParser); 5 6const app = express(); 7app.use( 8 bodyParser.xml({ 9 limit: '1MB', // Reject payload bigger than 1 MB 10 xmlParseOptions: { 11 normalize: true, // Trim whitespace inside text nodes 12 normalizeTags: true, // Transform tags to lowercase 13 explicitArray: false, // Only put nodes in array if >1 14 }, 15 }), 16); 17 18app.post('/users', function (req, res, body) { 19 // Any request with an XML payload will be parsed 20 // and a JavaScript object produced on req.body 21 // corresponding to the request payload. 22 console.log(req.body); 23 res.status(200).end(); 24});
This library was born out of a frustration that express-xml-bodyparser, the most popular XML-parsing library for express, doesn't support the regular body-parser
options - in particular, limiting the payload size.
This library was written to use body-parser
's text parser under the hood, and then passes the parsed string into the XML parser. We can therefore take advantage of body-parser
's regular options, and support limiting the payload size, amongst other things.
MIT
7.6/10
Summary
body-parser-xml vulnerable to Prototype Pollution
Affected Versions
< 2.0.3
Patched Versions
2.0.3
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 2/22 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
17 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More