ory / hydra

The most scalable and customizable OpenID Certified™ OpenID Connect and OAuth Provider on the market. Become an OpenID Connect and OAuth2 Provider over night. Broad support for related RFCs. Written in Go, cloud native, headless, API-first. Available as a service on Ory Network and for self-hosters.
https://www.ory.sh/?utm_source=github&utm_medium=banner&utm_campaign=hydra
Apache License 2.0
15.65k stars 1.5k forks source link

CLI crashes when arguments include custom HTTP headers #3370

Closed gingerich closed 2 years ago

gingerich commented 2 years ago

Preflight checklist

Describe the bug

Supplying custom HTTP headers via the --http-header flag causes the CLI to crash with panic: assignment to entry in nil map.

Reproducing the bug

  1. Install the latest version of Hydra CLI
  2. Run hydra list oauth2-clients --endpoint http://localhost:4445 --http-header "x-my-header: foobar"

Relevant log output

panic: assignment to entry in nil map

goroutine 1 [running]:
net/textproto.MIMEHeader.Add(...)
        /home/gitpod/go/src/net/textproto/header.go:15
net/http.Header.Add(...)
        /home/gitpod/go/src/net/http/header.go:31
github.com/ory/x/cmdx.NewClient(0x224b2c0?)
        /workspace/go/pkg/mod/github.com/ory/x@v0.0.514/cmdx/http.go:102 +0x5e6
github.com/ory/hydra/cmd/cliclient.NewClient(0xc0004c2600)
        /workspace/hydra/cmd/cliclient/client.go:37 +0x79
github.com/ory/hydra/cmd.NewListClientsCmd.func1(0xc0004c2600, {0xc00012f1a0?, 0x6?, 0x6?})
        /workspace/hydra/cmd/cmd_list_clients.go:24 +0x36
github.com/spf13/cobra.(*Command).execute(0xc0004c2600, {0xc00012f140, 0x6, 0x6})
        /workspace/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:916 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc0004ae000)
        /workspace/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        /workspace/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:968
github.com/ory/hydra/cmd.Execute()
        /workspace/hydra/cmd/root.go:101 +0x3a
main.main()
        /workspace/hydra/main.go:14 +0x69
exit status 2

Relevant configuration

No response

Version

2.0.2

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

Kubernetes

Additional Context

A quick investigation points to this line causing the issue https://github.com/ory/x/blob/v0.0.514/cmdx/http.go#L90. http.Header is a map so must be instantiated before using.

jonasbadstuebner commented 1 year ago

Is there an ETA for the new release including this fix? :)