fix: prevent possible nil pointer panics (#11728)

# Which Problems Are Solved

We found multiple cases where potentially a panic occurred or could
occur:
- when de/encrypting certain information
- returning apps without any configuration type (?)
- apple IdPs without a proper private key

# How the Problems Are Solved

- Added nil checks
- Check private key format for apple IdPs
- Added necessary helper function

# Additional Changes

Fixed i18n yaml where the IDP errors were indented under `org` instead
of directly under `errors`.

# Additional Context

- requires backport to v4.x

---------

Co-authored-by: Marco A. <[email protected]>
This commit is contained in:
Livio Spring
2026-03-16 14:30:17 +00:00
committed by GitHub
co-authored by Marco A.
parent 7c0e1750f3
commit 500821ce0c
33 changed files with 440 additions and 264 deletions
@@ -3,6 +3,9 @@
package events_test
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"testing"
"time"
@@ -14,6 +17,7 @@ import (
"github.com/zitadel/zitadel/backend/v3/domain"
"github.com/zitadel/zitadel/backend/v3/storage/database"
"github.com/zitadel/zitadel/backend/v3/storage/database/repository"
"github.com/zitadel/zitadel/internal/crypto"
zitadel_internal_domain "github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/integration"
"github.com/zitadel/zitadel/pkg/grpc/admin"
@@ -2012,7 +2016,7 @@ func TestServer_TestIDProviderInstanceReduces(t *testing.T) {
ClientId: "clientID",
TeamId: "teamIDteam",
KeyId: "keyIDKeyId",
PrivateKey: []byte("privateKey"),
PrivateKey: generatePrivateKeyPKCS8(t),
Scopes: []string{"scope"},
ProviderOptions: &idp_grpc.Options{
IsLinkingAllowed: false,
@@ -2064,7 +2068,7 @@ func TestServer_TestIDProviderInstanceReduces(t *testing.T) {
ClientId: "clientID",
TeamId: "teamIDteam",
KeyId: "keyIDKeyId",
PrivateKey: []byte("privateKey"),
PrivateKey: generatePrivateKeyPKCS8(t),
Scopes: []string{"scope"},
ProviderOptions: &idp_grpc.Options{
IsLinkingAllowed: false,
@@ -2095,7 +2099,7 @@ func TestServer_TestIDProviderInstanceReduces(t *testing.T) {
ClientId: "new_clientID",
TeamId: "new_teamID",
KeyId: "new_kKeyId",
PrivateKey: []byte("new_privateKey"),
PrivateKey: generatePrivateKeyPKCS8(t),
Scopes: []string{"new_scope"},
ProviderOptions: &idp_grpc.Options{
IsLinkingAllowed: true,
@@ -2361,3 +2365,11 @@ func defaultInstanceLDAPRequest(name string) *admin.AddLDAPProviderRequest {
},
}
}
func generatePrivateKeyPKCS8(t *testing.T) []byte {
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
require.NoError(t, err)
data, err := crypto.PrivateKeyToBytesPKCS8(privateKey)
require.NoError(t, err)
return data
}
@@ -1978,7 +1978,7 @@ func TestServer_TestIDProviderOrgReduces(t *testing.T) {
ClientId: "clientID",
TeamId: "teamIDteam",
KeyId: "keyIDKeyId",
PrivateKey: []byte("privateKey"),
PrivateKey: generatePrivateKeyPKCS8(t),
Scopes: []string{"scope"},
ProviderOptions: &idp_grpc.Options{
IsLinkingAllowed: false,
@@ -2030,7 +2030,7 @@ func TestServer_TestIDProviderOrgReduces(t *testing.T) {
ClientId: "clientID",
TeamId: "teamIDteam",
KeyId: "keyIDKeyId",
PrivateKey: []byte("privateKey"),
PrivateKey: generatePrivateKeyPKCS8(t),
Scopes: []string{"scope"},
ProviderOptions: &idp_grpc.Options{
IsLinkingAllowed: false,
@@ -2061,7 +2061,7 @@ func TestServer_TestIDProviderOrgReduces(t *testing.T) {
ClientId: "new_clientID",
TeamId: "new_teamID",
KeyId: "new_kKeyId",
PrivateKey: []byte("new_privateKey"),
PrivateKey: generatePrivateKeyPKCS8(t),
Scopes: []string{"new_scope"},
ProviderOptions: &idp_grpc.Options{
IsLinkingAllowed: true,