Skip to content

Incorrect parsing of hostname on FastifyRequest when using IPv6 #5789

@David-van-der-Sluijs

Description

@David-van-der-Sluijs

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.0.0

Plugin version

No response

Node.js version

20.17.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

Sequoia

Description

This simple server:

import {fastify} from 'fastify';

const server = fastify({
    logger: true
});

server.get('/', (request, reply) => {
    console.log('Hostname: "' + request.hostname + '"');
    reply.send('Hello World!');
});

server.listen({port: 3040}, (err, address) => {
    console.log(`Server listening at ${address}`);
});

Prints:

Server listening at http://[::1]:3040
{"level":30,"time":1730060215348,"pid":34830,"hostname":"<redacted>","reqId":"req-1","req":{"method":"GET","url":"/","host":"[::1]:3040","remoteAddress":"::1","remotePort":63860},"msg":"incoming request"}
Hostname: "["

We can see that the hostname resolved to [ which is wrong.

Link to code that reproduces the bug

No response

Expected Behavior

The hostname should be [::1].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions