fix: use base64 record keys to prevent separator clashes with subjects or sessionIds that contain a dot

This commit is contained in:
Florian Schade
2026-02-26 09:08:17 +01:00
committed by Christian Richter
parent a5f5009f9d
commit 8d99cf3f8b
4 changed files with 265 additions and 146 deletions
+9 -9
View File
@@ -17,6 +17,7 @@ import (
"github.com/opencloud-eu/opencloud/pkg/log"
"github.com/opencloud-eu/opencloud/pkg/oidc"
"github.com/opencloud-eu/opencloud/services/proxy/pkg/staticroutes"
)
const (
@@ -115,22 +116,21 @@ func (m *OIDCAuthenticator) getClaims(token string, req *http.Request) (map[stri
m.Logger.Error().Err(err).Msg("failed to write to userinfo cache")
}
subject, sessionId := strings.Join(strings.Fields(aClaims.Subject), ""), strings.Join(strings.Fields(aClaims.SessionID), "")
// if no session id is present, we can't do a session lookup,
// so we can skip the cache entry for that.
if sessionId == "" {
return
}
// if the claim has no subject, we can leave it empty,
// it's important to keep the dot in the key to prevent
// sufix and prefix exploration in the cache.
//
// ok: {key: ".sessionId"}
// ok: {key: "subject."}
// ok: {key: "subject.sessionId"}
key := strings.Join([]string{subject, sessionId}, ".")
subjectSessionKey, err := staticroutes.NewRecordKey(aClaims.Subject, aClaims.SessionID)
if err != nil {
m.Logger.Error().Err(err).Msg("failed to build subject.session")
return
}
if err := m.userInfoCache.Write(&store.Record{
Key: key,
Key: subjectSessionKey,
Value: []byte(encodedHash),
Expiry: time.Until(expiration),
}); err != nil {