Skip to content
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

Add verification of arbitrary claims #27

Merged
merged 1 commit into from
Apr 27, 2016

Conversation

toonetown
Copy link
Contributor

See #26 and #23 for details of this feature.

@toonetown toonetown mentioned this pull request Apr 26, 2016
within the system's leeway. This means that:
val >= (system_clock() - system_leeway) and val <= (system_clock() + system_leeway).
]]--
define_validator("is_at", function()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for asking if that's obvious, but in which validation context should one use this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use it, for example, to check the iat claim.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. I must be missing something.

In order to check the iat claim, I'd may check its value isn't greater than now (+/- leeway). Optionally I may enforce it's less than exp (+/- leeway), in order to assess the jwt integrity.

However, I'm not sure how checking iat equals now could be any reliable. A jwt is supposed to last for some time, and be reused across many calls, so as soon as the leeway is exceeded, this validation will be failing (even if the jwt is still valid (eg. not expired yet)).

It's far possible I have misunderstood your point. Would that be the case, i apologize in advance. However, I'd be a taker for any explanation you may share to help me get a better grasp at this subject.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fermaem
A jwt is supposed to last for some time, and be reused across many calls

This I believe is where the difference lies, I believe. There is actually no requirement that jwt tokens are reused - and we use single-use tokens in my application. We use iat (within the leeway) as a "quick" check for validity - and we also use jti to ensure that each token is only used once.

It would be the exact same thing as setting (on the client) nbf=now() and exp=now()+1 and putting that in the token. But it is smaller and more concise to use iat.

This check (server-side) might have been able to be replaced with _M.chain(_M.is_not_before(), _M.is_not_expired()) except for something is expired when it equals the date...meaning that the chain function will fail every time (because nothing is >=now() and <now()).

If it is not desired, I can remove this call...but it seems that it actually does fit a use case (mine 😄). Even if someone wanted to use it in validating a my_custom_claim claim, or something. There is just a "hole" (==) in between is_not_before (>=) and is_not_expired (<) which I think could be filled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also - thank you very much for the review - and please keep bringing up any issues that may be in the code (or even in my approach altogether). This is my first stab at it, and I think that needing to explain and defend what I chose to do and am doing is a valuable part of this review process. Perhaps there should be better documentation around this function or perhaps it should be removed entirely (if it encourages bad practices).

Copy link
Contributor

@fermaem fermaem Apr 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and we use single-use tokens in my application.

Oh! That now makes a lot more sense.

I haven't initially thought about this angle. Indeed, in order to enforce a single usage of each token within a limited timeframe, I would rather have relied on jti+nbf+exp (but that's because I kind of prefer explicitness 😉).

If it is not desired, I can remove this call...but it seems that it actually does fit a use case

Honestly, I don't know. This is actually the first time I see (or hear of) using the iat claim to fit that purpose. @SkyLothar Thoughts?

Perhaps there should be better documentation around this function

Would @SkyLothar like the validator, I think we should however add a tiny paragraph explaining in which context this validator should be used (and when it shouldn't).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @fermaem .
It's more explicit to use jti+nbf+exp to achieve your goal.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's really a interesting.
Add some explanation for your use case, you can leave the validator here if you want, it's your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would like to leave the validator...the main purpose of the validator library is to have some simple "common" checks...and I think that checking that a time is equal to now is a fairly decent check to have, regardless. I'll update the README with some explanation for the use case.

@SkyLothar
Copy link
Owner

That's a lot of code!
Thank you 👍

@SkyLothar SkyLothar merged commit bd9749d into SkyLothar:master Apr 27, 2016
@SkyLothar SkyLothar mentioned this pull request Apr 27, 2016
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants