@@ -95,6 +95,9 @@ protected function validateToken(): void
9595 */
9696 protected function hasClaim (string $ claim ): bool
9797 {
98+ if (empty ($ claim )) {
99+ return false ;
100+ }
98101 return $ this ->token ->claims ()->has ($ claim );
99102 }
100103
@@ -114,6 +117,9 @@ protected function hasClaim(string $claim): bool
114117 */
115118 protected function getClaim (string $ claim ): mixed
116119 {
120+ if (empty ($ claim )) {
121+ return null ;
122+ }
117123 return $ this ->token ->claims ()->get ($ claim );
118124 }
119125
@@ -137,12 +143,19 @@ protected function getAllClaims(): array
137143 */
138144 public static function base64ToPEMPublicKey (string $ data ): string
139145 {
146+ if (empty ($ data )) {
147+ throw new SSOException ('Empty base64 data provided for PEM conversion. ' );
148+ }
140149
141150 $ data = strtr ($ data , [
142151 "\r" => "" ,
143152 "\n" => "" ,
144153 ]);
145154
155+ if (empty ($ data )) {
156+ throw new SSOException ('Base64 data is empty after cleanup. ' );
157+ }
158+
146159 return
147160 "-----BEGIN PUBLIC KEY----- \n" .
148161 chunk_split ($ data , 64 ) .
@@ -191,12 +204,26 @@ public function getSignerKey(): Key
191204 */
192205 private function getKey (string $ appSecret ): Key
193206 {
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+
194212 if (strpos ($ appSecret , '----- ' ) === 0 ) {
213+ if (empty ($ appSecret )) {
214+ throw new SSOException ('Empty PEM key provided. ' );
215+ }
195216 $ key = InMemory::plainText ($ appSecret );
196217 } elseif (strpos ($ appSecret , 'file:// ' ) === 0 ) {
218+ if (empty ($ appSecret )) {
219+ throw new SSOException ('Empty file path provided. ' );
220+ }
197221 $ key = InMemory::file ($ appSecret );
198222 } else {
199- $ 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 );
200227 }
201228 return $ key ;
202229 }
0 commit comments