-
-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty ttl #250
Comments
Hi, Disclaimer: the following point of view is not the POV of the Lexik team but my opinion about the exp claim You are right as per the RFC7519 the But this bundle does not break the RFC. You missed a very important line:
As you can imagine, in an authentication context, an immortal JWT is a serious problem: if it is compromised you allow a malicious application to get access on your data... for life! There is a way to avoid such threat: a revocation system to reject Jose that are compromised. Moreover, there is a way to get a new token when the current one expired: refresh tokens. This bundle does not support those tokens out of the box. However a great bundle adds this feature. To conclude: in an authentication context,
|
Nice links, but yeah those are totally making sense to me and I'm aware of the consequences of having an endless JWT.
Just changing the key would ban every tokens won't it?
Those feel more a hack to me. I mean it's weird to just refresh the token before it expires instead of simply having an endless JWT. I understand your POV on this, but why can't it be a feature for those who don't want their token to expire? |
With the v2.0 of the bundle, you can create your own encoder. The problem when you change your keys is that all valid tokens become invalid. |
Seems a good solution when you've a security issue related to tokens :). Nice about the custom encoder, I'll do this. Thanks! |
Hi @soyuka, To be honest, I was not aware of that the As well explained by @Spomky, claims may be judged mandatory depending on the context. The JOSE libraries on which our token encoders are based on may allow to do not have these claims, of course because they don't have to care about the context in which tokens will be used.
You do not refresh the token before it expires but after, that is one of the advantages of refresh tokens in addition of you don't need to force your users to resubmit their credentials. It is not a hack at all, but a way to keep tokens secure and do not bother users, just involving one more hit to the datastore, that's something acceptable in an authentication context. As said by Spomky, you can easily create your own encoder based on ours. |
Ok I need to take a deeper look into this! Still, imagine the following scenario:
Seems overkill, but ofc it may be a solution!
Totally agreed, but my context is not really the same as an open application which would have to consider such issues. |
That's always better than re-login :) and imho widely acceptable. Depending on the context, I personally use refresh tokens to perform the same validity checks on the authenticated user as during the first username/password authentication, this way I don't perform these checks at each (JWT) authenticated request, and so keep a security net which is to see the changes made on a user become effective as soon as its token expires. Note that in combination you can set a very long
Look at the link given by Spomky, it's easy to try. If you really want to create your own encoder with an infinite lifetime because you don't need to prevent such issues, I can still try to give you my better advices for rewriting the less possible. // src/AppBundle/Services/ExpUnawareEncoder.php
<?php
namespace AppBundle\Services;
use Lexik\Bundle\JWTAuthenticationBundle\Encoder\DefaultEncoder;
use Lexik\Bundle\JWTAuthenticationBundle\Exception\JWTDecodeFailureException;
final class ExpUnawareEncoder extends DefaultEncoder
{
public function decode($token)
{
try {
$jws = $this->jwsProvider->load($token);
} catch (InvalidArgumentException $e) {
throw new JWTDecodeFailureException(JWTDecodeFailureException::INVALID_TOKEN, 'Invalid JWT Token', $e);
}
if ($jws->isInvalid()) {
throw new JWTDecodeFailureException(JWTDecodeFailureException::INVALID_TOKEN, 'Invalid JWT Token');
}
if (!$jws->isVerified()) {
throw new JWTDecodeFailureException(JWTDecodeFailureException::UNVERIFIED_TOKEN, 'Unable to verify the given JWT through the given configuration. If the "lexik_jwt_authentication.encoder" encryption options have been changed since your last authentication, please renew the token. If the problem persists, verify that the configured keys/passphrase are valid.');
}
return $jws->getPayload();
}
} # src/AppBundle/Resources/config/services.yml
services:
# ...
app.jwt_encoder:
class: AppBundle\Services\ExpUnawareEncoder
arguments: [ '@lexik_jwt_authentication.jws_provider.default' ] # app/config/config.yml
lexik_jwt_authentication:
# ...
encoder:
service: app.jwt_encoder Because I squashed your contribution and made a breaking change ^^ |
😸 so kind of you, thanks!! |
Ok, so because this also checks for |
@soyuka The encoder being the only one to throw an exception, why is it needed to override the provdider and the |
Oh nevermind I thought LoadedJWS was setting Your implementation works fine, thanks! |
my use case for a token with infinite lifetime is development. obviously for production we would use a separate private/public key value. I guess for now I will just extend the lifetime. |
Good point I think. We could allow null depending on |
yeah f.e. |
are you willing to reopen this ticket if the scope of token's without ttl is limited to debug mode being enabled? |
Reopening, I'm on it. |
Fixed in e1a0f37. |
May you release this one? Thanks! |
@soyuka I will do for the end of the week, I would like to see if we can easily leverage some symfony 3.3 features beforehand. |
thx! |
released in 2.4.0 |
@lsmith77 you mentioned private/public key value for production. |
With this changes is not suppoused to be changed the UPGRADE file too? Right now it says this:
|
#117 breaks exp should be optional.
#233
I haven't studied the spomky-labs/jose library so I'm not sure if 0 is considered as unlimited or not.
The text was updated successfully, but these errors were encountered: