Skip to content

Commit

Permalink
Add hostname check in registry URL on login
Browse files Browse the repository at this point in the history
Signed-off-by: Vlad Cherkasov <[email protected]>
  • Loading branch information
Vlad Cherkasov authored and kttyt committed May 5, 2024
1 parent 647ccf3 commit 47e373f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cli/command/registry/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"net/url"
"strings"

"github.com/docker/cli/cli"
Expand Down Expand Up @@ -97,6 +98,16 @@ func verifyloginOptions(dockerCli command.Cli, opts *loginOptions) error {
opts.password = strings.TrimSuffix(string(contents), "\n")
opts.password = strings.TrimSuffix(opts.password, "\r")
}

if opts.serverAddress != "" {
u, err := url.Parse(opts.serverAddress)
if err != nil {
return errors.Errorf("Invalid server address: %s", opts.serverAddress)
}
if u.Host == "" {
return errors.Errorf("Server address must include a hostname: %s", opts.serverAddress)
}
}
return nil
}

Expand Down

0 comments on commit 47e373f

Please sign in to comment.