---
title: "unsafe-formatted-url-host-port"
description: "Detect URL and network-address construction that breaks IPv6."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# unsafe-formatted-url-host-port

**Default severity:** `warning`

Formatting a URL authority or an address passed directly to a standard-library
network listener as `host:port` does not add the brackets required around IPv6
literals. `net.JoinHostPort` correctly handles hostnames, IPv4, and IPv6.

## Bad

```go
url := fmt.Sprintf("http://%s:%d/path", host, port)
```

## Good

```go
address := net.JoinHostPort(host, strconv.Itoa(port)); url := "http://" + address
```

Source: https://strider.gempir.com/analyzers/unsafe-formatted-url-host-port/index.mdx
