• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / storage / 29005879037

09 Jul 2026 08:46AM UTC coverage: 58.99% (-20.3%) from 79.254%
29005879037

Pull #1196

github

web-flow
Merge 7e8ebf9b4 into 1bfdcd74e
Pull Request #1196: chore(deps-dev): bump resolve-tspaths from 0.8.19 to 0.8.23

3509 of 6801 branches covered (51.6%)

Branch coverage included in aggregate %.

7436 of 11753 relevant lines covered (63.27%)

386.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.94
/src/http/plugins/header-validator.ts
1
import { ERRORS } from '@internal/errors'
2
import { hasInvalidHeaderValueChars } from '@internal/http/header'
3
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
4
import fastifyPlugin from 'fastify-plugin'
5

6
interface HeaderValidatorOptions {
7
  excludeUrls?: string[]
8
}
9

10
/**
11
 * Validates response headers before they're sent to prevent ERR_INVALID_CHAR crashes.
12
 *
13
 * Node.js throws ERR_INVALID_CHAR during writeHead() if headers contain control characters.
14
 * This hook validates headers in onSend (before writeHead) and throws InvalidHeaderChar error
15
 */
16
export const headerValidator = (options: HeaderValidatorOptions = {}) =>
285✔
17
  fastifyPlugin(
18
    async function headerValidatorPlugin(fastify: FastifyInstance) {
19
      fastify.addHook('onSend', (request: FastifyRequest, reply: FastifyReply, payload, done) => {
285✔
20
        if (options.excludeUrls?.includes(request.url.toLowerCase())) {
1,303!
21
          done(null, payload)
×
22
          return
×
23
        }
24

25
        const headers = reply.getHeaders()
1,303✔
26
        for (const key in headers) {
1,303✔
27
          if (!Object.prototype.hasOwnProperty.call(headers, key)) {
1,519!
28
            continue
×
29
          }
30
          const value = headers[key]
1,519✔
31
          if (typeof value === 'string') {
1,519✔
32
            if (hasInvalidHeaderValueChars(value)) {
1,479!
33
              throw ERRORS.InvalidHeaderChar(key, value)
×
34
            }
35
          } else if (Array.isArray(value)) {
40!
36
            for (let j = 0; j < value.length; j++) {
×
37
              const item = value[j]
×
38
              if (typeof item === 'string' && hasInvalidHeaderValueChars(item)) {
×
39
                throw ERRORS.InvalidHeaderChar(key, item)
×
40
              }
41
            }
42
          }
43
        }
44

45
        done(null, payload)
1,303✔
46
      })
47
    },
48
    { name: 'header-validator' }
49
  )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc