File tree Expand file tree Collapse file tree
src/main/java/org/opensearch/security/authtoken/jwt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ public class JwtVendor {
4242 private final JoseJwtProducer jwtProducer ;
4343 private final LongSupplier timeProvider ;
4444 private final EncryptionDecryptionUtil encryptionDecryptionUtil ;
45+ private final Integer defaultExpirySeconds = 300 ;
46+ private final Integer maxExpirySeconds = 600 ;
4547
4648 public JwtVendor (final Settings settings , final Optional <LongSupplier > timeProvider ) {
4749 JoseJwtProducer jwtProducer = new JoseJwtProducer ();
@@ -126,7 +128,11 @@ public String createJwt(
126128
127129 jwtClaims .setNotBefore (nowAsMillis );
128130
129- expirySeconds = (expirySeconds == null ) ? 300 : expirySeconds ;
131+ if (expirySeconds > maxExpirySeconds ) {
132+ throw new Exception ("The provided expiration time exceeds the maximum allowed duration of " + maxExpirySeconds + " seconds" );
133+ }
134+
135+ expirySeconds = (expirySeconds == null ) ? defaultExpirySeconds : Math .min (expirySeconds , maxExpirySeconds );
130136 if (expirySeconds <= 0 ) {
131137 throw new Exception ("The expiration time should be a positive integer" );
132138 }
You can’t perform that action at this time.
0 commit comments