Beispiel
body-parser 1.20.1
Verifiziertes Beispiel für npm body-parser 1.20.1. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand: bodyParser.json() parses…
sha256:b23d09566185da65568c6f3573aa9ee15b62205803b42e08293d534fa607548b
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-11-21 |
Fall
HOW- Ziel
- verify pkg:npm/body-parser@1.20.1
- Pakete
- Umgebung
- node 22.23.2
- Erstellt
- 2026-11-21T19:22:42Z
Contract
- bodyParser.json() parses application/json objects, arrays, and empty payloads (content-length: 0 -> {}) into req.body with req._body = true, and skips non-matching Content-Type requests
- bodyParser.json() rejects JSON primitives and malformed JSON with 400 SyntaxError (entity.parse.failed) in default strict mode, while strict: false accepts primitives
- bodyParser.json() supports reviver, limit (413 entity.too.large), verify (403 entity.verify.failed; non-function throws TypeError), gzip inflate (415 encoding.unsupported when false), and UTF charset validation (415 charset.unsupported)
- bodyParser.urlencoded() parses nested structures with extended: true, flat keys on a null-prototype object with extended: false, and enforces parameterLimit (413 parameters.too.many)
- bodyParser.raw() parses application/octet-stream into a Buffer, supports custom type predicate functions, and enforces byte limits (413 entity.too.large)
- bodyParser.text() parses text/plain and custom MIME types (e.g. text/html) into UTF-8 strings and skips non-matching Content-Type requests
Dateien
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
Quelltext
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:npm/body-parser@1.20.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/body-parser@1.20.1
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:6b8980a68df49e82025409dc7b93cb2404908431816814b7c51b314f27f026d7","constraints":{"executionContext":"node"},"contract":["bodyParser.json() parses application/json objects, arrays, and empty payloads (content-length: 0 -\u003e {}) into req.body with req._body = true, and skips non-matching Content-Type requests","bodyParser.json() rejects JSON primitives and malformed JSON with 400 SyntaxError (entity.parse.failed) in default strict mode, while strict: false accepts primitives","bodyParser.json() supports reviver, limit (413 entity.too.large), verify (403 entity.verify.failed; non-function throws TypeError), gzip inflate (415 encoding.unsupported when false), and UTF charset validation (415 charset.unsupported)","bodyParser.urlencoded() parses nested structures with extended: true, flat keys on a null-prototype object with extended: false, and enforces parameterLimit (413 parameters.too.many)","bodyParser.raw() parses application/octet-stream into a Buffer, supports custom type predicate functions, and enforces byte limits (413 entity.too.large)","bodyParser.text() parses text/plain and custom MIME types (e.g. text/html) into UTF-8 strings and skips non-matching Content-Type requests"],"goal":"verify pkg:npm/body-parser@1.20.1","kind":"HOW","packages":["pkg:npm/body-parser@1.20.1"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/body-parser@1.20.1"],"schemaVersion":1,"subject":"pkg:npm/body-parser@1.20.1","verifierAdapter":"node-typescript@1"}
'use strict';
const { PassThrough } = require('node:stream');
const bodyParser = require('body-parser');
/**
* Create configured body-parser@1.20.1 middleware instances.
*
* @param {object} [options]
* @returns {{ json: Function, urlencoded: Function, raw: Function, text: Function }}
*/
function createParsers(options = {}) {
return {
json: bodyParser.json(options.json),
urlencoded: bodyParser.urlencoded({ extended: true, ...options.urlencoded }),
raw: bodyParser.raw(options.raw),
text: bodyParser.text(options.text)
};
}
/**
* Invoke a body-parser middleware offline against an in-memory Node.js stream.
*
* @param {Function} middleware
* @param {{ payload?: Buffer | string | null, headers?: Record<string, string> }} input
* @returns {Promise<{ req: PassThrough, body: unknown, parsed: boolean | undefined }>}
*/
function invokeParser(middleware, { payload = null, headers = {} } = {}) {
return new Promise((resolve, reject) => {
const req = new PassThrough();
const normalizedHeaders = {};
for (const [key, value] of Object.entries(headers)) {
normalizedHeaders[key.toLowerCase()] = value;
}
let buf = null;
if (payload !== null && payload !== undefined) {
buf = Buffer.isBuffer(payload) ? payload : Buffer.from(String(payload), 'utf8');
if (normalizedHeaders['content-length'] === undefined && normalizedHeaders['transfer-encoding'] === undefined) {
normalizedHeaders['content-length'] = String(buf.length);
}
}
req.headers = normalizedHeaders;
req.method = 'POST';
req.url = '/ingest';
const res = {};
middleware(req, res, (err) => {
if (err) {
reject(err);
return;
}
resolve({ req, body: req.body, parsed: req._body });
});
if (buf !== null) {
req.end(buf);
} else {
req.end();
}
});
}
module.exports = {
bodyParser,
createParsers,
invokeParser
};
{
"name": "body-parser-verify-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "body-parser-verify-sample",
"version": "1.0.0",
"dependencies": {
"body-parser": "1.20.1"
}
},
"node_modules/body-parser": {
"version": "1.20.1",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
"integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
"license": "MIT",
"dependencies": {
"bytes": "3.1.2",
"content-type": "~1.0.4",
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.2.0",
"http-errors": "2.0.0",
"iconv-lite": "0.4.24",
"on-finished": "2.4.1",
"qs": "6.11.0",
"raw-body": "2.5.1",
"type-is": "~1.6.18",
"unpipe": "1.0.0"
},
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/bytes": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/call-bound": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"get-intrinsic": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/content-type": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"license": "MIT",
"dependencies": {
"ms": "2.0.0"
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/destroy": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
"license": "MIT",
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
"license": "MIT"
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz",
"integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
"integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/http-errors": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
"license": "MIT",
"dependencies": {
"depd": "2.0.0",
"inherits": "2.0.4",
"setprototypeof": "1.2.0",
"statuses": "2.0.1",
"toidentifier": "1.0.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"license": "MIT"
},
"node_modules/object-inspect": {
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.14.0.tgz",
"integrity": "sha512-IVgHNlp/jwQX271+Xzoq9LZNTWXxZK+cEOrGBOBxXNbn7fapnZ+Ts6TVMgNOuAezwG2wdtnMX97tTPK6VEnuOQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/on-finished": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
"license": "MIT",
"dependencies": {
"ee-first": "1.1.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/qs": {
"version": "6.11.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
"license": "BSD-3-Clause",
"dependencies": {
"side-channel": "^1.0.4"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/raw-body": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
"integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
"license": "MIT",
"dependencies": {
"bytes": "3.1.2",
"http-errors": "2.0.0",
"iconv-lite": "0.4.24",
"unpipe": "1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
},
"node_modules/setprototypeof": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
"license": "ISC"
},
"node_modules/side-channel": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz",
"integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.4",
"side-channel-list": "^1.0.1",
"side-channel-map": "^1.0.1",
"side-channel-weakmap": "^1.0.2"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-list": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz",
"integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.4"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-map": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-weakmap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3",
"side-channel-map": "^1.0.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/statuses": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/toidentifier": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
"license": "MIT",
"engines": {
"node": ">=0.6"
}
},
"node_modules/type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
"license": "MIT",
"dependencies": {
"media-typer": "0.3.0",
"mime-types": "~2.1.24"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
}
}
}
{
"name": "body-parser-verify-sample",
"version": "1.0.0",
"private": true,
"description": "Minimal offline contract sample verifying body-parser@1.20.1 middleware behavior.",
"main": "index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"body-parser": "1.20.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/body-parser@1.20.1",
"kind": "HOW",
"packages": [
"pkg:npm/body-parser@1.20.1"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const assert = require('node:assert/strict');
const zlib = require('node:zlib');
const { bodyParser, createParsers, invokeParser } = require('../index.js');
async function verifyJsonParser() {
const { json } = createParsers();
// Object payload
const objRes = await invokeParser(json, {
headers: { 'content-type': 'application/json' },
payload: JSON.stringify({ item: 'widget', count: 3 })
});
assert.deepEqual(objRes.body, { item: 'widget', count: 3 });
assert.equal(objRes.parsed, true);
// Array payload
const arrRes = await invokeParser(json, {
headers: { 'content-type': 'application/json' },
payload: JSON.stringify([1, 2, 3])
});
assert.deepEqual(arrRes.body, [1, 2, 3]);
assert.equal(arrRes.parsed, true);
// Empty payload (content-length: 0)
const emptyRes = await invokeParser(json, {
headers: { 'content-type': 'application/json', 'content-length': '0' },
payload: Buffer.alloc(0)
});
assert.deepEqual(emptyRes.body, {});
assert.equal(emptyRes.parsed, true);
// Non-matching Content-Type is skipped
const skipRes = await invokeParser(json, {
headers: { 'content-type': 'text/plain' },
payload: '{"ignored":true}'
});
assert.deepEqual(skipRes.body, {});
assert.equal(skipRes.parsed, undefined);
// Strict mode rejects JSON primitive by default
await assert.rejects(
() =>
invokeParser(json, {
headers: { 'content-type': 'application/json' },
payload: '"primitive"'
}),
(err) => err instanceof SyntaxError && err.status === 400 && err.type === 'entity.parse.failed'
);
// Malformed JSON rejected with 400 entity.parse.failed
await assert.rejects(
() =>
invokeParser(json, {
headers: { 'content-type': 'application/json' },
payload: '{"broken":'
}),
(err) => err instanceof SyntaxError && err.status === 400 && err.type === 'entity.parse.failed'
);
// Non-strict mode accepts JSON primitives
const nonStrict = bodyParser.json({ strict: false });
const primRes = await invokeParser(nonStrict, {
headers: { 'content-type': 'application/json' },
payload: '"primitive"'
});
assert.equal(primRes.body, 'primitive');
assert.equal(primRes.parsed, true);
// Reviver option transforms parsed values
const reviverParser = bodyParser.json({
reviver: (key, value) => (key === 'amount' ? value * 10 : value)
});
const revivedRes = await invokeParser(reviverParser, {
headers: { 'content-type': 'application/json' },
payload: JSON.stringify({ amount: 5 })
});
assert.deepEqual(revivedRes.body, { amount: 50 });
// Limit option enforces maximum payload size
const smallLimit = bodyParser.json({ limit: '10b' });
await assert.rejects(
() =>
invokeParser(smallLimit, {
headers: { 'content-type': 'application/json' },
payload: JSON.stringify({ message: 'exceeds-ten-bytes' })
}),
(err) => err.status === 413 && err.type === 'entity.too.large'
);
// Verify hook runs on raw buffer and turns thrown error into 403 entity.verify.failed
let capturedRaw = null;
const verifiedParser = bodyParser.json({
verify: (req, _res, buf, encoding) => {
capturedRaw = buf.toString(encoding || 'utf8');
if (req.headers['x-sig'] !== 'valid') {
throw new Error('signature mismatch');
}
}
});
const okVerify = await invokeParser(verifiedParser, {
headers: { 'content-type': 'application/json', 'x-sig': 'valid' },
payload: '{"ok":true}'
});
assert.deepEqual(okVerify.body, { ok: true });
assert.equal(capturedRaw, '{"ok":true}');
await assert.rejects(
() =>
invokeParser(verifiedParser, {
headers: { 'content-type': 'application/json', 'x-sig': 'bad' },
payload: '{"ok":false}'
}),
(err) => err.status === 403 && err.type === 'entity.verify.failed'
);
// Non-function verify throws TypeError synchronously
assert.throws(() => bodyParser.json({ verify: 'not-a-function' }), TypeError);
// Gzip inflation enabled by default and rejected when inflate: false
const gzipped = zlib.gzipSync(Buffer.from(JSON.stringify({ compressed: true }), 'utf8'));
const inflatedRes = await invokeParser(json, {
headers: { 'content-type': 'application/json', 'content-encoding': 'gzip' },
payload: gzipped
});
assert.deepEqual(inflatedRes.body, { compressed: true });
const noInflate = bodyParser.json({ inflate: false });
await assert.rejects(
() =>
invokeParser(noInflate, {
headers: { 'content-type': 'application/json', 'content-encoding': 'gzip' },
payload: gzipped
}),
(err) => err.status === 415 && err.type === 'encoding.unsupported'
);
// Unsupported non-UTF charset rejected with 415 charset.unsupported
await assert.rejects(
() =>
invokeParser(json, {
headers: { 'content-type': 'application/json; charset=latin1' },
payload: '{"a":1}'
}),
(err) => err.status === 415 && err.type === 'charset.unsupported'
);
}
async function verifyUrlencodedParser() {
// Extended mode (qs) parses nested objects and arrays
const extendedParser = bodyParser.urlencoded({ extended: true });
const extRes = await invokeParser(extendedParser, {
headers: { 'content-type': 'application/x-www-form-urlencoded' },
payload: 'profile[role]=maintainer&tags[]=node&tags[]=cjs'
});
assert.deepEqual(extRes.body, {
profile: { role: 'maintainer' },
tags: ['node', 'cjs']
});
assert.equal(extRes.parsed, true);
// Simple mode (querystring) keeps bracket keys flat on a null-prototype object
const simpleParser = bodyParser.urlencoded({ extended: false });
const simpleRes = await invokeParser(simpleParser, {
headers: { 'content-type': 'application/x-www-form-urlencoded' },
payload: 'a=1&profile[role]=maintainer'
});
assert.equal(Object.getPrototypeOf(simpleRes.body), null);
assert.deepEqual(
simpleRes.body,
Object.assign(Object.create(null), {
a: '1',
'profile[role]': 'maintainer'
})
);
assert.equal(simpleRes.parsed, true);
// parameterLimit enforced with 413 parameters.too.many
const limitedParams = bodyParser.urlencoded({ extended: true, parameterLimit: 2 });
await assert.rejects(
() =>
invokeParser(limitedParams, {
headers: { 'content-type': 'application/x-www-form-urlencoded' },
payload: 'a=1&b=2&c=3'
}),
(err) => err.status === 413 && err.type === 'parameters.too.many'
);
}
async function verifyRawParser() {
const { raw } = createParsers();
const payload = Buffer.from([0x00, 0x01, 0xfe, 0xff]);
const rawRes = await invokeParser(raw, {
headers: { 'content-type': 'application/octet-stream' },
payload
});
assert.equal(Buffer.isBuffer(rawRes.body), true);
assert.equal(rawRes.body.equals(payload), true);
assert.equal(rawRes.parsed, true);
// Custom predicate type matcher + limit enforcement
const customRaw = bodyParser.raw({
type: (req) => req.headers['x-binary'] === '1',
limit: 3
});
const okSmall = await invokeParser(customRaw, {
headers: { 'content-type': 'application/custom', 'x-binary': '1' },
payload: Buffer.from([1, 2, 3])
});
assert.equal(okSmall.body.equals(Buffer.from([1, 2, 3])), true);
await assert.rejects(
() =>
invokeParser(customRaw, {
headers: { 'content-type': 'application/custom', 'x-binary': '1' },
payload: Buffer.from([1, 2, 3, 4])
}),
(err) => err.status === 413 && err.type === 'entity.too.large'
);
}
async function verifyTextParser() {
const { text } = createParsers();
const plainRes = await invokeParser(text, {
headers: { 'content-type': 'text/plain' },
payload: 'hello body-parser'
});
assert.equal(plainRes.body, 'hello body-parser');
assert.equal(plainRes.parsed, true);
const htmlParser = bodyParser.text({ type: 'text/html', defaultCharset: 'utf-8' });
const htmlRes = await invokeParser(htmlParser, {
headers: { 'content-type': 'text/html' },
payload: '<p>ok</p>'
});
assert.equal(htmlRes.body, '<p>ok</p>');
assert.equal(htmlRes.parsed, true);
const skippedText = await invokeParser(htmlParser, {
headers: { 'content-type': 'text/plain' },
payload: 'ignored'
});
assert.deepEqual(skippedText.body, {});
assert.equal(skippedText.parsed, undefined);
}
async function main() {
await verifyJsonParser();
await verifyUrlencodedParser();
await verifyRawParser();
await verifyTextParser();
console.log('body-parser@1.20.1 contract passed');
}
main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
Ursprungs-Seeder
anonym