mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-30 07:58:51 +00:00
Merge commit from fork
* fix(crypto): use authenticated encryption for IDP intent tokens IDP intent tokens were encrypted with AES-CFB which provides no integrity protection, making them malleable. Switch to A256GCM via the existing AuthAlgorithm interface (EncryptToken/DecryptToken), the same approach already used for OIDC and session tokens. The idpConfigEncryption key type is widened from EncryptionAlgorithm to AuthEncryptionAlgorithm so that data-at-rest encryption (IDP client secrets, LDAP bind passwords, SAML keys) continues to use the CFB path unmodified. Co-authored-by: Cursor <[email protected]> * fix(proto): raise IDP intent token max length to 500 for authenticated tokens The switch to authenticated A256GCM (JWE compact serialization) makes IDP intent tokens longer (~270 chars) than the previous AES-CFB base64 output. Raise the max_len/max_length validation and OpenAPI constraints on every idp_intent_token field from 200 to 500 so the new tokens are accepted: user v2/v2beta (idp + user_service), session v2/v2beta, and resources user v3alpha. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Cursor <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
Cursor
parent
f3dcfa3db6
commit
9067605b66
@@ -428,7 +428,7 @@ func TestCommands_CreateIntent(t *testing.T) {
|
||||
func TestCommands_AuthFromProvider(t *testing.T) {
|
||||
type fields struct {
|
||||
eventstore func(t *testing.T) *eventstore.Eventstore
|
||||
secretCrypto crypto.EncryptionAlgorithm
|
||||
secretCrypto crypto.AuthEncryptionAlgorithm
|
||||
idGenerator id.Generator
|
||||
}
|
||||
type args struct {
|
||||
@@ -452,7 +452,7 @@ func TestCommands_AuthFromProvider(t *testing.T) {
|
||||
{
|
||||
"error no id generator",
|
||||
fields{
|
||||
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
secretCrypto: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(),
|
||||
idGenerator: mock.NewIDGeneratorExpectError(t, zerrors.ThrowInternal(nil, "", "error id")),
|
||||
},
|
||||
@@ -468,7 +468,7 @@ func TestCommands_AuthFromProvider(t *testing.T) {
|
||||
{
|
||||
"idp not existing",
|
||||
fields{
|
||||
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
secretCrypto: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectFilter(),
|
||||
),
|
||||
@@ -486,7 +486,7 @@ func TestCommands_AuthFromProvider(t *testing.T) {
|
||||
{
|
||||
"idp removed",
|
||||
fields{
|
||||
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
secretCrypto: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectFilter(
|
||||
eventFromEventPusherWithInstanceID(
|
||||
@@ -531,7 +531,7 @@ func TestCommands_AuthFromProvider(t *testing.T) {
|
||||
{
|
||||
"oauth auth redirect",
|
||||
fields{
|
||||
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
secretCrypto: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectFilter(
|
||||
eventFromEventPusherWithInstanceID(
|
||||
@@ -593,7 +593,7 @@ func TestCommands_AuthFromProvider(t *testing.T) {
|
||||
{
|
||||
"oauth auth redirect with login_hint",
|
||||
fields{
|
||||
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
secretCrypto: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectFilter(
|
||||
eventFromEventPusherWithInstanceID(
|
||||
@@ -656,7 +656,7 @@ func TestCommands_AuthFromProvider(t *testing.T) {
|
||||
{
|
||||
"migrated and push",
|
||||
fields{
|
||||
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
secretCrypto: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectFilter(
|
||||
eventFromEventPusherWithInstanceID(
|
||||
@@ -799,7 +799,7 @@ func assertRedirectAuthWithPKCE(t *testing.T, expected, actual idp.Auth) {
|
||||
func TestCommands_AuthFromProvider_SAML(t *testing.T) {
|
||||
type fields struct {
|
||||
eventstore func(t *testing.T) *eventstore.Eventstore
|
||||
secretCrypto crypto.EncryptionAlgorithm
|
||||
secretCrypto crypto.AuthEncryptionAlgorithm
|
||||
idGenerator id.Generator
|
||||
}
|
||||
type args struct {
|
||||
@@ -823,7 +823,7 @@ func TestCommands_AuthFromProvider_SAML(t *testing.T) {
|
||||
{
|
||||
"saml auth default redirect",
|
||||
fields{
|
||||
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
secretCrypto: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectFilter(
|
||||
eventFromEventPusherWithInstanceID(
|
||||
@@ -918,7 +918,7 @@ func TestCommands_AuthFromProvider_SAML(t *testing.T) {
|
||||
{
|
||||
"saml post auth",
|
||||
fields{
|
||||
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
secretCrypto: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectFilter(
|
||||
eventFromEventPusherWithInstanceID(
|
||||
@@ -1054,7 +1054,7 @@ func TestCommands_AuthFromProvider_SAML(t *testing.T) {
|
||||
func TestCommands_SucceedIDPIntent(t *testing.T) {
|
||||
type fields struct {
|
||||
eventstore func(t *testing.T) *eventstore.Eventstore
|
||||
idpConfigEncryption crypto.EncryptionAlgorithm
|
||||
idpConfigEncryption crypto.AuthEncryptionAlgorithm
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
@@ -1076,9 +1076,9 @@ func TestCommands_SucceedIDPIntent(t *testing.T) {
|
||||
{
|
||||
"encryption fails",
|
||||
fields{
|
||||
idpConfigEncryption: func() crypto.EncryptionAlgorithm {
|
||||
m := crypto.NewMockEncryptionAlgorithm(gomock.NewController(t))
|
||||
m.EXPECT().Encrypt(gomock.Any()).Return(nil, zerrors.ThrowInternal(nil, "id", "encryption failed"))
|
||||
idpConfigEncryption: func() crypto.AuthEncryptionAlgorithm {
|
||||
m := crypto.NewMockAuthEncryptionAlgorithm(gomock.NewController(t))
|
||||
m.EXPECT().EncryptToken(gomock.Any()).Return("", zerrors.ThrowInternal(nil, "id", "encryption failed"))
|
||||
return m
|
||||
}(),
|
||||
eventstore: expectEventstore(),
|
||||
@@ -1094,9 +1094,9 @@ func TestCommands_SucceedIDPIntent(t *testing.T) {
|
||||
{
|
||||
"token encryption fails",
|
||||
fields{
|
||||
idpConfigEncryption: func() crypto.EncryptionAlgorithm {
|
||||
m := crypto.NewMockEncryptionAlgorithm(gomock.NewController(t))
|
||||
m.EXPECT().Encrypt(gomock.Any()).DoAndReturn(func(value []byte) ([]byte, error) {
|
||||
idpConfigEncryption: func() crypto.AuthEncryptionAlgorithm {
|
||||
m := crypto.NewMockAuthEncryptionAlgorithm(gomock.NewController(t))
|
||||
m.EXPECT().EncryptToken(gomock.Any()).DoAndReturn(func(value string) (string, error) {
|
||||
return value, nil
|
||||
})
|
||||
m.EXPECT().Encrypt(gomock.Any()).Return(nil, zerrors.ThrowInternal(nil, "id", "encryption failed"))
|
||||
@@ -1122,7 +1122,7 @@ func TestCommands_SucceedIDPIntent(t *testing.T) {
|
||||
{
|
||||
"push",
|
||||
fields{
|
||||
idpConfigEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
idpConfigEncryption: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectPush(
|
||||
func() eventstore.Command {
|
||||
@@ -1173,7 +1173,7 @@ func TestCommands_SucceedIDPIntent(t *testing.T) {
|
||||
}),
|
||||
},
|
||||
res{
|
||||
token: "aWQ",
|
||||
token: "id",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1193,7 +1193,7 @@ func TestCommands_SucceedIDPIntent(t *testing.T) {
|
||||
func TestCommands_SucceedSAMLIDPIntent(t *testing.T) {
|
||||
type fields struct {
|
||||
eventstore func(t *testing.T) *eventstore.Eventstore
|
||||
idpConfigEncryption crypto.EncryptionAlgorithm
|
||||
idpConfigEncryption crypto.AuthEncryptionAlgorithm
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
@@ -1215,9 +1215,9 @@ func TestCommands_SucceedSAMLIDPIntent(t *testing.T) {
|
||||
{
|
||||
"encryption fails",
|
||||
fields{
|
||||
idpConfigEncryption: func() crypto.EncryptionAlgorithm {
|
||||
m := crypto.NewMockEncryptionAlgorithm(gomock.NewController(t))
|
||||
m.EXPECT().Encrypt(gomock.Any()).Return(nil, zerrors.ThrowInternal(nil, "id", "encryption failed"))
|
||||
idpConfigEncryption: func() crypto.AuthEncryptionAlgorithm {
|
||||
m := crypto.NewMockAuthEncryptionAlgorithm(gomock.NewController(t))
|
||||
m.EXPECT().EncryptToken(gomock.Any()).Return("", zerrors.ThrowInternal(nil, "id", "encryption failed"))
|
||||
return m
|
||||
}(),
|
||||
eventstore: expectEventstore(),
|
||||
@@ -1233,7 +1233,7 @@ func TestCommands_SucceedSAMLIDPIntent(t *testing.T) {
|
||||
{
|
||||
"push",
|
||||
fields{
|
||||
idpConfigEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
idpConfigEncryption: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectPush(
|
||||
idpintent.NewSAMLSucceededEvent(
|
||||
@@ -1265,16 +1265,16 @@ func TestCommands_SucceedSAMLIDPIntent(t *testing.T) {
|
||||
UserInfoProfile: oidc.UserInfoProfile{
|
||||
PreferredUsername: "username",
|
||||
},
|
||||
}),
|
||||
},
|
||||
res{
|
||||
token: "aWQ",
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
"push with userID",
|
||||
res{
|
||||
token: "id",
|
||||
},
|
||||
},
|
||||
{
|
||||
"push with userID",
|
||||
fields{
|
||||
idpConfigEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
idpConfigEncryption: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectPush(
|
||||
idpintent.NewSAMLSucceededEvent(
|
||||
@@ -1310,7 +1310,7 @@ func TestCommands_SucceedSAMLIDPIntent(t *testing.T) {
|
||||
userID: "user",
|
||||
},
|
||||
res{
|
||||
token: "aWQ",
|
||||
token: "id",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1381,7 +1381,7 @@ func TestCommands_RequestSAMLIDPIntent(t *testing.T) {
|
||||
func TestCommands_SucceedLDAPIDPIntent(t *testing.T) {
|
||||
type fields struct {
|
||||
eventstore func(t *testing.T) *eventstore.Eventstore
|
||||
idpConfigEncryption crypto.EncryptionAlgorithm
|
||||
idpConfigEncryption crypto.AuthEncryptionAlgorithm
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
@@ -1403,9 +1403,9 @@ func TestCommands_SucceedLDAPIDPIntent(t *testing.T) {
|
||||
{
|
||||
"encryption fails",
|
||||
fields{
|
||||
idpConfigEncryption: func() crypto.EncryptionAlgorithm {
|
||||
m := crypto.NewMockEncryptionAlgorithm(gomock.NewController(t))
|
||||
m.EXPECT().Encrypt(gomock.Any()).Return(nil, zerrors.ThrowInternal(nil, "id", "encryption failed"))
|
||||
idpConfigEncryption: func() crypto.AuthEncryptionAlgorithm {
|
||||
m := crypto.NewMockAuthEncryptionAlgorithm(gomock.NewController(t))
|
||||
m.EXPECT().EncryptToken(gomock.Any()).Return("", zerrors.ThrowInternal(nil, "id", "encryption failed"))
|
||||
return m
|
||||
}(),
|
||||
eventstore: expectEventstore(),
|
||||
@@ -1421,7 +1421,7 @@ func TestCommands_SucceedLDAPIDPIntent(t *testing.T) {
|
||||
{
|
||||
"push",
|
||||
fields{
|
||||
idpConfigEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
idpConfigEncryption: crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
eventstore: expectEventstore(
|
||||
expectPush(
|
||||
idpintent.NewLDAPSucceededEvent(
|
||||
@@ -1467,7 +1467,7 @@ func TestCommands_SucceedLDAPIDPIntent(t *testing.T) {
|
||||
),
|
||||
},
|
||||
res{
|
||||
token: "aWQ",
|
||||
token: "id",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1556,7 +1556,7 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
||||
"no tokens",
|
||||
args{
|
||||
&ldap.Session{},
|
||||
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
},
|
||||
res{
|
||||
accessToken: nil,
|
||||
@@ -1599,7 +1599,7 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
},
|
||||
res{
|
||||
accessToken: &crypto.CryptoValue{
|
||||
@@ -1628,7 +1628,7 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
},
|
||||
res{
|
||||
accessToken: &crypto.CryptoValue{
|
||||
@@ -1654,7 +1654,7 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
||||
IDToken: "idToken",
|
||||
},
|
||||
},
|
||||
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
},
|
||||
res{
|
||||
accessToken: &crypto.CryptoValue{
|
||||
@@ -1681,7 +1681,7 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
||||
IDToken: "idToken",
|
||||
},
|
||||
},
|
||||
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
},
|
||||
res{
|
||||
accessToken: nil,
|
||||
@@ -1702,7 +1702,7 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
},
|
||||
res{
|
||||
accessToken: &crypto.CryptoValue{
|
||||
@@ -1730,7 +1730,7 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||
crypto.CreateMockAuthEncryptionAlg(gomock.NewController(t)),
|
||||
},
|
||||
res{
|
||||
accessToken: &crypto.CryptoValue{
|
||||
|
||||
Reference in New Issue
Block a user