Home / File/ proto-poisoning.test.js — fastify Source File

proto-poisoning.test.js — fastify Source File

Architecture documentation for proto-poisoning.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const Fastify = require('..')
const { test } = require('node:test')

test('proto-poisoning error', async (t) => {
  t.plan(2)

  const fastify = Fastify()

  fastify.post('/', (request, reply) => {
    t.assert.fail('handler should not be called')
  })

  t.after(() => fastify.close())

  const fastifyServer = await fastify.listen({ port: 0 })

  const result = await fetch(fastifyServer, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: '{ "__proto__": { "a": 42 } }'
  })

  t.assert.ok(!result.ok)
  t.assert.strictEqual(result.status, 400)
})

test('proto-poisoning remove', async (t) => {
  t.plan(3)

  const fastify = Fastify({ onProtoPoisoning: 'remove' })

  t.after(() => fastify.close())

  fastify.post('/', (request, reply) => {
    t.assert.strictEqual(undefined, Object.assign({}, request.body).a)
    reply.send({ ok: true })
  })

  const fastifyServer = await fastify.listen({ port: 0 })

  const result = await fetch(fastifyServer, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: '{ "__proto__": { "a": 42 }, "b": 42 }'
  })

  t.assert.ok(result.ok)
  t.assert.strictEqual(result.status, 200)
})

test('proto-poisoning ignore', async (t) => {
  t.plan(3)

  const fastify = Fastify({ onProtoPoisoning: 'ignore' })

  fastify.post('/', (request, reply) => {
    t.assert.strictEqual(42, Object.assign({}, request.body).a)
    reply.send({ ok: true })
// ... (86 more lines)

Frequently Asked Questions

What does proto-poisoning.test.js do?
proto-poisoning.test.js is a source file in the fastify codebase, written in javascript.
Where is proto-poisoning.test.js in the architecture?
proto-poisoning.test.js is located at test/proto-poisoning.test.js (directory: test).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free