Skip to content
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

Backport of Vault-4010 Unauthenticated panic when processing "help" requests into release/1.9.x #14709

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/14704.txt
@@ -0,0 +1,3 @@
```release-note:bug
core: Fix panic for help request URL paths without /v1/ prefix
```
6 changes: 6 additions & 0 deletions http/help.go
@@ -1,7 +1,9 @@
package http

import (
"errors"
"net/http"
"strings"

"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/sdk/logical"
Expand Down Expand Up @@ -31,6 +33,10 @@ func handleHelp(core *vault.Core, w http.ResponseWriter, r *http.Request) {
respondError(w, http.StatusBadRequest, nil)
return
}
if !strings.HasPrefix(r.URL.Path, "/v1/") {
respondError(w, http.StatusNotFound, errors.New("Missing /v1/ prefix in path. Use vault path-help command to retrieve API help for paths"))
return
}
path := ns.TrimmedPath(r.URL.Path[len("/v1/"):])

req := &logical.Request{
Expand Down
6 changes: 5 additions & 1 deletion http/help_test.go
Expand Up @@ -13,7 +13,11 @@ func TestHelp(t *testing.T) {
defer ln.Close()
TestServerAuth(t, addr, token)

resp := testHttpGet(t, "", addr+"/v1/sys/mounts?help=1")
// request without /v1/ prefix
resp := testHttpGet(t, token, addr+"/?help=1")
testResponseStatus(t, resp, 404)

resp = testHttpGet(t, "", addr+"/v1/sys/mounts?help=1")
if resp.StatusCode != http.StatusBadRequest {
t.Fatal("expected bad request with no token")
}
Expand Down