fix(proxy): guard against empty signing key store in presigned URL auth (#12418)
signatureIsValid indexed signingKey[0] without checking the slice length. When the signing-key store returns an empty result without an error — which the "noop" store does, and OCIS_CACHE_STORE=noop also switches the presigned-URL signing-key store to noop — every signed-URL download panicked with "index out of range [0] with length 0" (recovered per request as a 502), so all signed-URL downloads failed. Guard the index access and return a real authentication error. The previous empty-value branch also returned a nil error, which would have accepted an empty signing key; it now returns an error so the request is rejected. Signed-off-by: David Walter <david.walter@kiteworks.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f3d2bc0557
commit
9296546be3
3 files changed
+50
-3
No files matched your search
@@ -0,0 +1,14 @@
|
||||
Bugfix: Prevent panic in presigned URL authentication when the signing key is missing
|
||||
|
||||
The presigned-URL authenticator read the per-user signing key from a store and
|
||||
indexed the first record without checking that the result was non-empty. When
|
||||
the store returns an empty result without an error — which the `noop` store
|
||||
does, and `OCIS_CACHE_STORE=noop` also switches the presigned-URL signing-key
|
||||
store to `noop` — every signed-URL request panicked with `index out of range
|
||||
[0] with length 0` (recovered per request as an HTTP 502), so all signed-URL
|
||||
downloads failed. The authenticator now guards the lookup and returns a normal
|
||||
authentication error instead of panicking; it also no longer returns a nil
|
||||
error when the stored key is empty.
|
||||
|
||||
https://github.com/owncloud/ocis/issues/12384
|
||||
https://github.com/owncloud/ocis/pull/12418
|
||||
@@ -150,9 +150,13 @@ func (m SignedURLAuthenticator) signatureIsValid(req *http.Request) (err error)
|
||||
m.Logger.Error().Err(err).Msg("could not retrieve signing key")
|
||||
return err
|
||||
}
|
||||
if len(signingKey[0].Value) == 0 {
|
||||
m.Logger.Error().Err(err).Msg("signing key empty")
|
||||
return err
|
||||
// A store may return an empty result set without an error (e.g. the "noop"
|
||||
// store, or a store that has no signing key for this user). Guard the index
|
||||
// access to avoid an out-of-range panic, and return a real error so the
|
||||
// request fails authentication instead of proceeding with an empty key.
|
||||
if len(signingKey) == 0 || len(signingKey[0].Value) == 0 {
|
||||
m.Logger.Error().Str("userid", c.Id.OpaqueId).Msg("signing key empty or not found")
|
||||
return errors.New("signing key not found")
|
||||
}
|
||||
u := m.buildUrlToSign(req)
|
||||
computedSignature := m.createSignature(u, signingKey[0].Value)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/services/proxy/pkg/config"
|
||||
revactx "github.com/owncloud/reva/v2/pkg/ctx"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -158,6 +159,34 @@ func TestSignedURLAuth_createSignature(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSignedURLAuth_validateEmptySigningKeyStore guards against an out-of-range
|
||||
// panic when the signing-key store returns no record without an error. This
|
||||
// happens with the "noop" store (e.g. when OCIS_CACHE_STORE=noop, which also
|
||||
// governs the presigned-URL signing-key store). The request must fail
|
||||
// authentication, not panic.
|
||||
func TestSignedURLAuth_validateEmptySigningKeyStore(t *testing.T) {
|
||||
pua := SignedURLAuthenticator{
|
||||
PreSignedURLConfig: config.PreSignedURL{
|
||||
AllowedHTTPMethods: []string{"get"},
|
||||
Enabled: true,
|
||||
},
|
||||
Store: store.NewNoopStore(),
|
||||
Logger: log.NewLogger(),
|
||||
Now: func() time.Time {
|
||||
tm, _ := time.Parse(time.RFC3339, "2019-05-14T11:02:00.000Z")
|
||||
return tm
|
||||
},
|
||||
}
|
||||
|
||||
u := userpb.User{Id: &userpb.UserId{OpaqueId: "useri"}, DisplayName: "Test User"}
|
||||
ctx := revactx.ContextSetUser(context.Background(), &u)
|
||||
r := httptest.NewRequest("", "http://cloud.example.net/?OC-Credential=alice&OC-Date=2019-05-14T11%3A01%3A58.135Z&OC-Expires=1200&OC-Verb=GET&OC-Signature=f9e53a1ee23caef10f72ec392c1b537317491b687bfdd224c782be197d9ca2b6", nil).WithContext(ctx)
|
||||
|
||||
var err error
|
||||
assert.NotPanics(t, func() { err = pua.validate(r) }, "validate must not panic when the signing key store is empty")
|
||||
assert.Error(t, err, "validate must reject the request when no signing key is found")
|
||||
}
|
||||
|
||||
func TestSignedURLAuth_validate(t *testing.T) {
|
||||
nowFunc := func() time.Time {
|
||||
t, _ := time.Parse(time.RFC3339, "2020-02-02T12:30:00.000Z")
|
||||
|
||||
Reference in new issue
Block a user