caddyserver/caddy · error

could not parse octal permission bits in %s: %v

Error message

could not parse octal permission bits in %s: %v

What it means

Caddy's SplitUnixSocketPermissionsBits splits a unix socket address of the form 'path|mode' (e.g. '/run/caddy.sock|0600'). The part after '|' must be a valid octal number no larger than 32 bits. If strconv.ParseUint with base 8 fails, this error is returned, wrapping the underlying parse error.

Source

Thrown at internal/sockets.go:41

// SplitUnixSocketPermissionsBits takes a unix socket address in the
// unusual "path|bits" format (e.g. /run/caddy.sock|0222) and tries
// to split it into socket path (host) and permissions bits (port).
// Colons (":") can't be used as separator, as socket paths on Windows
// may include a drive letter (e.g. `unix/c:\absolute\path.sock`).
// Permission bits will default to 0200 if none are specified.
// Throws an error, if the first carrying bit does not
// include write perms (e.g. `0422` or `022`).
// Symbolic permission representation (e.g. `u=w,g=w,o=w`)
// is not supported and will throw an error for now!
func SplitUnixSocketPermissionsBits(addr string) (path string, fileMode fs.FileMode, err error) {
	addrSplit := strings.SplitN(addr, "|", 2)

	if len(addrSplit) == 2 {
		// parse octal permission bit string as uint32
		fileModeUInt64, err := strconv.ParseUint(addrSplit[1], 8, 32)
		if err != nil {
			return "", 0, fmt.Errorf("could not parse octal permission bits in %s: %v", addr, err)
		}
		fileMode = fs.FileMode(fileModeUInt64)

		// FileMode.String() returns a string like `-rwxr-xr--` for `u=rwx,g=rx,o=r` (`0754`)
		if string(fileMode.String()[2]) != "w" {
			return "", 0, fmt.Errorf("owner of the socket requires '-w-' (write, octal: '2') permissions at least; got '%s' in %s", fileMode.String()[1:4], addr)
		}

		return addrSplit[0], fileMode, nil
	}

	// default to 0200 (symbolic: `u=w,g=,o=`)
	// if no permission bits are specified
	return addr, 0o200, nil
}

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Use 3-4 octal digits after the pipe, e.g. '/run/caddy.sock|0600'.
  2. Remove the '|suffix' entirely to accept the default 0200 owner-write mode.
  3. If you need symbolic permissions, translate them to octal first (u=rw,g= -> 0260 style mapping) in your config generation, since symbolic input is not supported.
  4. Check for stray '|' characters or unexpanded variables in the address string.

Example fix

// before
unix/u=rw,g=r/run/caddy.sock
// after (symbolic not supported; octal only)
unix/run/caddy.sock|0640
Defensive patterns

Strategy: validation

Validate before calling

func validOctalSuffix(addr string) bool {
    parts := strings.SplitN(addr, "|", 2)
    if len(parts) != 2 {
        return true // no suffix; default 0200 applies
    }
    n, err := strconv.ParseUint(parts[1], 8, 32)
    return err == nil && n <= 0o7777
}

Prevention

When it happens

Trigger: Calling caddy.ParseNetworkAddress / listening on a unix address whose '|' suffix is not pure octal digits: 'u=rw,g=r' (symbolic modes are explicitly unsupported), '0x600' (hex prefix), '600 ' (trailing space), '77777777777' (exceeds 32-bit range), or an empty suffix like 'path|'.

Common situations: Users coming from chmod syntax write symbolic permissions ('u=rw') in the Caddyfile listen address. Others paste a decimal or hex mode, or a stray pipe character appears in the path. CI configs with templated modes often inject whitespace or an empty variable next to the '|'.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/65f2d066c5a84af8. Report an issue: GitHub.