Skip to content

refactor: support percent-encoded /unix paths #10833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lidel
Copy link
Member

@lidel lidel commented Jun 9, 2025

Why

is breaking spec change that is incompatible with existing feature in Kubo, where users were able to provide old notation of /unix multiaddrs in both Addresses.API and Addresses.Gateway.

How

This is a PoC that aims to support
multiformats/multiaddr#174 while not breaking existing Kubo users.

TODO

This is a PoC that aims to support
multiformats/multiaddr#174
while not breaking existing Kubo users.

See TODO in daemon.go – likely we want to move this to
https://github.com/multiformats/go-multiaddr
@lidel lidel added the skip/changelog This change does NOT require a changelog entry label Jun 9, 2025
Comment on lines +709 to +726
// TODO: should a version of this live in https://github.com/multiformats/go-multiaddr
// so we dont need to duplicate code here and in client/rpc/api.go ?
func NormalizeUnixMultiaddr(address string) string {
// Support legacy and modern /unix addrs
// https://github.com/multiformats/multiaddr/pull/174
socketPath, err := url.PathUnescape(address)
if err != nil {
return address // nil, fmt.Errorf("failed to unescape /unix socket path: %w", err)
}
// Ensure the path is absolute
if !strings.HasPrefix(socketPath, string(filepath.Separator)) {
socketPath = string(filepath.Separator) + socketPath
}
// Normalize path
socketPath = filepath.Clean(socketPath)
return socketPath
}

Copy link
Member Author

@lidel lidel Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ @gammazero @MarcoPolo Thoughts on if this should live in go-multiaddr, or here?

IF It does not live in https://github.com/multiformats/go-multiaddr then multiformats/multiaddr#174 is effectively a dead spec IMO, because nobody will use percent-encoded version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. If we are going to support multiformats/multiaddr#174 then this should live in go-multiaddr

@lidel lidel mentioned this pull request Jun 9, 2025
46 tasks
if err != nil {
return address // nil, fmt.Errorf("failed to unescape /unix socket path: %w", err)
}
// Ensure the path is absolute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.b. in the latest version of the spec pr, relative paths are supported

return address // nil, fmt.Errorf("failed to unescape /unix socket path: %w", err)
}
// Ensure the path is absolute
if !strings.HasPrefix(socketPath, string(filepath.Separator)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !strings.HasPrefix(socketPath, string(filepath.Separator)) {
if !filepath.IsAbs(socketPath) {

}
// Ensure the path is absolute
if !strings.HasPrefix(socketPath, string(filepath.Separator)) {
socketPath = string(filepath.Separator) + socketPath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to prepend a separator, or should the current directory be prepended?

See filepath.Abs

Comment on lines +723 to +724
socketPath = filepath.Clean(socketPath)
return socketPath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
socketPath = filepath.Clean(socketPath)
return socketPath
return filepath.Clean(socketPath)

Comment on lines +709 to +726
// TODO: should a version of this live in https://github.com/multiformats/go-multiaddr
// so we dont need to duplicate code here and in client/rpc/api.go ?
func NormalizeUnixMultiaddr(address string) string {
// Support legacy and modern /unix addrs
// https://github.com/multiformats/multiaddr/pull/174
socketPath, err := url.PathUnescape(address)
if err != nil {
return address // nil, fmt.Errorf("failed to unescape /unix socket path: %w", err)
}
// Ensure the path is absolute
if !strings.HasPrefix(socketPath, string(filepath.Separator)) {
socketPath = string(filepath.Separator) + socketPath
}
// Normalize path
socketPath = filepath.Clean(socketPath)
return socketPath
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. If we are going to support multiformats/multiaddr#174 then this should live in go-multiaddr

@lidel lidel mentioned this pull request Jul 14, 2025
51 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip/changelog This change does NOT require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants