Socket
Socket
Sign inDemoInstall

body-fingerprint

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

body-fingerprint - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

14

index.js

@@ -75,7 +75,13 @@ const multipartFingerprint = (req, _, next) => {

const order = [];
JSON.parse(req.json.raw.body, (key) => {
if (key) order.push(key);
});
try {
JSON.parse(req.json.raw.body, (key) => {
if (key) order.push(key);
});
} catch (error) {
req.json.error = error;
}
req.json.order = order;
req.json.fingerprint = order.join(",");
req.json.fingerprint = order.join();

@@ -82,0 +88,0 @@ const spaces = [];

{
"name": "body-fingerprint",
"version": "1.3.2",
"version": "1.3.3",
"description": "Tracks consumers by POST body",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -575,2 +575,117 @@ const assert = require("node:assert");

});
it("can parse spaces inner objects", () => {
const exampleJsonString = ` {
"a": 5,
"b": {
"c": "a\\n b"
}
}`;
const expected = [
" ",
"\n",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"\n",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"\n",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"\n",
" ",
" ",
" ",
" ",
" ",
" ",
"\n",
" ",
" ",
" ",
" ",
];
const req = new (class extends EventEmitter {
get headers() {
return {
"content-type": "application/json",
};
}
setEncoding() {}
})();
jsonFingerprint(req, res, next);
req.emit("data", exampleJsonString);
req.emit("end");
const {
json: { spaces: actual },
} = req;
assert.deepStrictEqual(actual, expected);
});
it("should silently fail on bad body", () => {
// no double quotes between property key "a"
const exampleJsonString = ' {a: "who\\r \\n ops" \r\n} \r';
const expected = [" ", " ", " ", " ", "\r", "\n", " ", "\r"];
const req = new (class extends EventEmitter {
get headers() {
return {
"content-type": "application/json",
};
}
setEncoding() {}
})();
jsonFingerprint(req, res, next);
req.emit("data", exampleJsonString);
req.emit("end");
const {
json: { spaces: actual },
} = req;
assert.deepStrictEqual(actual, expected);
});
it("should have error on fail parse", () => {
// no double quotes between property key "a"
const exampleJsonString = ' {a: "who\\r \\n ops" \r\n} \r';
const expected = "Unexpected token a in JSON at position 2";
const req = new (class extends EventEmitter {
get headers() {
return {
"content-type": "application/json",
};
}
setEncoding() {}
})();
jsonFingerprint(req, res, next);
req.emit("data", exampleJsonString);
req.emit("end");
const actual = req.json.error.message;
assert.equal(actual, expected);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc