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

supabase / storage / 30106451275

24 Jul 2026 03:42PM UTC coverage: 80.304% (-0.1%) from 80.45%
30106451275

Pull #1266

github

web-flow
Merge 763a5d0b6 into 42bb7886c
Pull Request #1266: fix: simpler caches by outcome and metrics

5618 of 7536 branches covered (74.55%)

Branch coverage included in aggregate %.

43 of 48 new or added lines in 3 files covered. (89.58%)

2458 existing lines in 106 files now uncovered.

10731 of 12823 relevant lines covered (83.69%)

411.64 hits per line

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

86.49
/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?: Set<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 = {}) =>
301✔
17
  fastifyPlugin(
18
    async function headerValidatorPlugin(fastify: FastifyInstance) {
19
      const excludeUrls = options.excludeUrls?.size ? options.excludeUrls : undefined
298✔
20

21
      fastify.addHook('onSend', (request: FastifyRequest, reply: FastifyReply, payload, done) => {
298✔
22
        if (excludeUrls?.has(request.url)) {
1,374!
23
          done(null, payload)
×
24
          return
×
25
        }
26

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

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

© 2026 Coveralls, Inc