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

supabase / storage / 28361311259

29 Jun 2026 09:12AM UTC coverage: 78.808% (+0.009%) from 78.799%
28361311259

push

github

web-flow
fix: make hooks sync unless needed (#1183)

Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>

5095 of 7025 branches covered (72.53%)

Branch coverage included in aggregate %.

37 of 42 new or added lines in 6 files covered. (88.1%)

1 existing line in 1 file now uncovered.

10059 of 12204 relevant lines covered (82.42%)

422.25 hits per line

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

85.29
/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 = {}) =>
298✔
17
  fastifyPlugin(
18
    async function headerValidatorPlugin(fastify: FastifyInstance) {
19
      fastify.addHook('onSend', (request: FastifyRequest, reply: FastifyReply, payload, done) => {
298✔
20
        if (options.excludeUrls?.includes(request.url.toLowerCase())) {
1,312!
NEW
21
          done(null, payload)
×
NEW
22
          return
×
23
        }
24

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

45
        done(null, payload)
1,306✔
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