Packages / fastify / Security

HighVulnerabilityGHSA-455w-c45v-86rgCVE-2022-39288Published 11 Oct 2022

fastify vulnerable to denial of service via malicious Content-Type

Affected releases · fastify

  • 4.x4.0.0 – 4.8.0Fixed in 4.8.1

On 4.x, the newest line:

npm install fastify@4.8.1
5.x
  1. Not affected

    5.0.0 – 5.12.7

    39 releases, latest

4.x
  1. Affected

    4.0.0 – 4.8.0

    16 releases

  2. Fixed

    4.8.1 – 4.29.1

    45 releases

300 stable releases of fastify, oldest to newest, one row per major.

Is your project affected?

Paste your package.json, or type the range you declare for fastify. It is read in your browser and sent nowhere.

What happens

Impact

An attacker can send an invalid Content-Type header that can cause the application to crash, leading to a possible Denial of Service attack. Only the v4.x line is affected.

(This was updated: upon a close inspection, v3.x is not affected after all).

Patches

Yes, update to > v4.8.0.

Workarounds

You can reject the malicious content types before the body parser enters in action.

  const badNames = Object.getOwnPropertyNames({}.__proto__)
  fastify.addHook('onRequest', async (req, reply) => {
    for (const badName of badNames) {
      if (req.headers['content-type'].indexOf(badName) > -1) {
        reply.code(415)
        throw new Error('Content type not supported')
      }
    }
  })

References

See the HackerOne report #1715536

For more information

Fastify security policy