@@ -25,6 +25,9 @@ abstract class AbstractToken
2525
2626 private Configuration $ config ;
2727
28+ /**
29+ * @var Constraint[]
30+ */
2831 private array $ constraints ;
2932
3033 /**
@@ -92,6 +95,9 @@ protected function validateToken(): void
9295 */
9396 protected function hasClaim (string $ claim ): bool
9497 {
98+ if (empty ($ claim )) {
99+ return false ;
100+ }
95101 return $ this ->token ->claims ()->has ($ claim );
96102 }
97103
@@ -102,13 +108,25 @@ protected function hasClaim(string $claim): bool
102108 *
103109 * @return mixed
104110 */
105- protected function getClaim (string $ claim )
111+ /**
112+ * Get a claim without checking for existence.
113+ *
114+ * @param string $claim name.
115+ *
116+ * @return mixed
117+ */
118+ protected function getClaim (string $ claim ): mixed
106119 {
120+ if (empty ($ claim )) {
121+ return null ;
122+ }
107123 return $ this ->token ->claims ()->get ($ claim );
108124 }
109125
110126 /**
111127 * Get an array of all available claims and their values.
128+ *
129+ * @return array<string, mixed>
112130 */
113131 protected function getAllClaims (): array
114132 {
@@ -125,12 +143,19 @@ protected function getAllClaims(): array
125143 */
126144 public static function base64ToPEMPublicKey (string $ data ): string
127145 {
146+ if (empty ($ data )) {
147+ throw new SSOException ('Empty base64 data provided for PEM conversion. ' );
148+ }
128149
129150 $ data = strtr ($ data , [
130151 "\r" => "" ,
131152 "\n" => "" ,
132153 ]);
133154
155+ if (empty ($ data )) {
156+ throw new SSOException ('Base64 data is empty after cleanup. ' );
157+ }
158+
134159 return
135160 "-----BEGIN PUBLIC KEY----- \n"
136161 . chunk_split ($ data , 64 )
@@ -179,12 +204,26 @@ public function getSignerKey(): Key
179204 */
180205 private function getKey (string $ appSecret ): Key
181206 {
207+ // Ensure the app secret is not empty to satisfy strict non-empty-string requirements
208+ if (!trim ($ appSecret )) {
209+ throw new SSOException ('Empty appSecret provided when creating signer key. ' );
210+ }
211+
182212 if (strpos ($ appSecret , '----- ' ) === 0 ) {
213+ if (empty ($ appSecret )) {
214+ throw new SSOException ('Empty PEM key provided. ' );
215+ }
183216 $ key = InMemory::plainText ($ appSecret );
184217 } elseif (strpos ($ appSecret , 'file:// ' ) === 0 ) {
218+ if (empty ($ appSecret )) {
219+ throw new SSOException ('Empty file path provided. ' );
220+ }
185221 $ key = InMemory::file ($ appSecret );
186222 } else {
187- $ key = InMemory::plainText (self ::base64ToPEMPublicKey ($ appSecret ));
223+ $ pem = self ::base64ToPEMPublicKey ($ appSecret );
224+ // After our validation in base64ToPEMPublicKey, we know $pem is non-empty
225+ /** @var non-empty-string $pem */
226+ $ key = InMemory::plainText ($ pem );
188227 }
189228 return $ key ;
190229 }
0 commit comments