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

Tracks consumers by POST body


Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

body-fingerprint

Install

npm install body-fingerprint

Usage

const express = require("express");
const app = express();

const { bodyFingerprint, jsonFingerprint } = require("body-fingerprint");

app.use(bodyFingerprint);
app.use(jsonFingerprint);

app.get("/", (_, res) =>
  res.send(`
<script>
body = new FormData();
body.set('a', 'b');
body.set('c', 'd');
body.set('e', new File([], ''))
fetch('/', {
    method: 'post', 
    body})
    .then((res) => res.text())
    .then((res) => document.body.insertAdjacentHTML(
        'beforebegin',
        '<span style="white-space: pre-line">' + res + '</span>'
    ));
fetch('/', {
    method: 'post', 
    headers: {'content-type': 'application/json'},
    body: JSON.stringify({
        a: 'b',
        c: 'd', 
        e: {
            f: 'g'
        }
    })
})
    .then((res) => res.text())
    .then((res) => document.body.insertAdjacentHTML(
        'beforebegin',
        '<span style="white-space: pre-line">' + res + '</span>'
    ))    
</script>
`)
);

app.post("/", (req, res) => {
  res.send([req.multipart.fingerprint, req.json.fingerprint]);
});

app.listen(3000);

Multipart Fingerprint

Request:

POST /multipart HTTP/1.1
Host: example.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary1234567890123456

------WebKitFormBoundary1234567890123456
Content-Disposition: form-data; name="a"

b
------WebKitFormBoundary1234567890123456
Content-Disposition: form-data; name="c"

d
------WebKitFormBoundary1234567890123456
Content-Disposition: form-data; name="e"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary1234567890123456--

Generated req.multipart object:

{
  "parts": [
    {
      "attributes": {
        "order": ["name"]
      },
      "headers": {
        "order": ["Content-Disposition"]
      }
    },
    {
      "attributes": {
        "order": ["name"]
      },
      "headers": {
        "order": ["Content-Disposition"]
      }
    },
    {
      "attributes": {
        "order": ["name", "filename"]
      },
      "headers": {
        "order": ["Content-Disposition", "Content-Type"]
      }
    }
  ]
}

JSON Fingerprint

Request:

POST /json HTTP/1.1
Host: example.com
Content-Type: application/json

{
  a: 1,
  b: {
    c: 2,
    d: 3,
  }
}

Generated req.json object:

{
  "fingerprint": "a,c,d,b",
  "order": ["a", "c", "d", "b"],
  "spaces": [" ", "\r", " \r", ... "\r"] // spaces fingerprint of json structure
}

Test

npm test

Keywords

FAQs

Package last updated on 24 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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