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

3.5.4 - token time-window validation #2185

Closed
elarlang opened this issue Oct 23, 2024 · 18 comments · Fixed by #2373
Closed

3.5.4 - token time-window validation #2185

elarlang opened this issue Oct 23, 2024 · 18 comments · Fixed by #2373
Labels
1) Discussion ongoing Issue is opened and assigned but no clear proposal yet 6) PR awaiting review V3 _5.0 - prep This needs to be addressed to prepare 5.0

Comments

@elarlang
Copy link
Collaborator

elarlang commented Oct 23, 2024

Spin-off from #1917

Current requirement:

# Description L1 L2 L3 CWE
3.5.4 [ADDED] Verify that stateless tokens are checked for expiration before processing them further. 613

It should be more abstract and cover "time window" when the token is valid.

To check the expiration, we need to require exp to be present and set. It is not set for example for refresh tokens when offline_access is used.

Technically it should also cover to check nbf (Not Before).

Related RFC https://datatracker.ietf.org/doc/html/rfc7519

  • exp - optional
  • nbf - optional

So the requirement need to validate the "time-window", and it can be validated, if nbf and/or exp claims are provided in the token (both are optional).

@elarlang elarlang added 1) Discussion ongoing Issue is opened and assigned but no clear proposal yet V3 labels Oct 23, 2024
@tghosth tghosth added the _5.0 - prep This needs to be addressed to prepare 5.0 label Oct 23, 2024
@elarlang
Copy link
Collaborator Author

Something like that?

Verify that stateless token is allowed to be used at the time of checking, using not-before ('nbf' claim in JWT) and expires ('exp' claim in JWT) values, if those are provided in the token.

@elarlang elarlang added the 4) proposal for review Issue contains clear proposal for add/change something label Oct 23, 2024
@randomstuff
Copy link
Contributor

For reference some wording about "iat" and "nbf" (but not "exp") from FAPI 2.0:

to accommodate clock offsets, shall accept JWTs with an iat or nbf timestamp between 0 and 10 seconds in the future but shall reject JWTs with an iat or nbf timestamp greater than 60 seconds in the future.

@elarlang
Copy link
Collaborator Author

I would not put iat here that quickly. From this you can assume are the clocks synced, but it is not meant for time-window validation.

@randomstuff
Copy link
Contributor

I would not put iat here that quickly. From this you can assume are the clocks synced, but it is not meant for time-window validation.

Note that for DPoP, "iat" is the value used to check the validity of the DPoP proof.

Verify that stateless token is allowed to be used at the time of checking, using not-before ('nbf' claim in JWT) and expires ('exp' claim in JWT) values, if those are provided in the token.

I'm wondering if there is something missing here (?):

  • it is the consumer of the token which must verify that the token is allowed to be used […]
  • and we must verify that the consumer of the token verifies that the token is allowed to be used.

So this should be something like:

Verify the the consumer of a stateless token verifies that stateless token is allowed to be used at the time of checking, using not-before ('nbf' claim in JWT) and expires ('exp' claim in JWT) values, if those are provided in the token.

@randomstuff
Copy link
Contributor

What about something like:

Verify that the consumer of a stateless token accepts the token only if the verification time is within this validity time span in the token (if present). For example, for JWTs, this is typically conveyed using the 'nbf' and 'exp' claims.

or

Verify that the consumer of a stateless tokens honors the validity time span associated with the token (if present). For example, for JWTs, this is typically conveyed using the 'nbf' and 'exp' claims.

@elarlang
Copy link
Collaborator Author

elarlang commented Oct 28, 2024

From last 2 proposals I prefer the first one. This "honors" feels a bit out of context, we need to use a strong and clear term such as "must" from https://datatracker.ietf.org/doc/html/rfc2119.

(if present) feels like it is written for the token "if token is present", I think it should be repositioned to be clearly apply to time-window claims.

consumer - it can be there, but I think it is not necessary. If something is going to use the content from the token, is is consuming the content and is consumer by nature. Is there any other interpretation that we need to clarify this?

@elarlang
Copy link
Collaborator Author

Rechecking it again, I think this one good enough:

Verify the the consumer of a stateless token verifies that stateless token is allowed to be used at the time of checking, using not-before ('nbf' claim in JWT) and expires ('exp' claim in JWT) values, if those are provided in the token.

@randomstuff - any changes or improvement to apply from your last proposal comment taking into account my last comment?

@elarlang
Copy link
Collaborator Author

Some more versions:

  • Verify that the stateless token is allowed to be used at the time of checking, using not-before ('nbf' claim in JWT) and expires ('exp' claim in JWT) values, if those are provided in the token.
  • Verify that if the stateless token has information about the time of being valid, such as 'nbf' and 'exp' claims in JWT, the consumer validates if the token is allowed to be used at the time of checking.
  • Verify that the stateless token is allowed to be used at the time of checking if the stateless token has information about the time of being valid, such as 'nbf' and 'exp' claims in JWT.

@randomstuff
Copy link
Contributor

randomstuff commented Oct 28, 2024

I'd like your second version better. The two other looks somewhat ambiguous to me.

Analysis of the third proposition

For example,

Verify that the stateless token is allowed to be used at the time of checking if the stateless token has information about the time of being valid, such as 'nbf' and 'exp' claims in JWT.

I think this is ambiguous about the scope of the condition. This might be understood as:

Verify that the (stateless token is allowed to be used at the time of checking if the stateless token has information about the time of being valid), such as 'nbf' and 'exp' claims in JWT.

whereas we mean:

(Verify that the stateless token is allowed to be used at the time of checking) if the stateless token has information about the time of being valid, such as 'nbf' and 'exp' claims in JWT.

This would be clearer:

Verify, if the stateless token has information about the time of being valid (such as 'nbf' and 'exp' claims in JWT), the stateless token is allowed to be used at the time of checking.

But actually, something seems to be missing to me and we mean:

Verify, if the stateless token has information about the time of being valid (such as 'nbf' and 'exp' claims in JWT), the application verifies the token is currently valid according to this information before taking any actions based on this token.

What about:

Verify that application accepts an stateless token only if the verification time is within this validity time span in the token, if such a validity time span is present. For JWTs and OAuth Token Introspection, this is currently represented by the 'nbf' and 'exp' claims and properties respectively.

or

Verify, if a stateless token is associated with some validity time span, the application verifies the token is currently valid according to this information before taking any action based on this token. For JWTs and OAuth Token Introspection, this is currently represented by the 'nbf' and 'exp' claims and properties respectively.

I removed "stateless" here because this can apply to stateful tokens as well (i.e. when using OAuth token introspection), right?

@ryarmst
Copy link
Collaborator

ryarmst commented Oct 29, 2024

May I suggest wording that favours rejection over acceptance? For example, rather than "accepts a token only if.." what about "rejects the token if..."?

@elarlang
Copy link
Collaborator Author

I'm a bit lost now what is the latest proposal here :)

@randomstuff - just in case, it is a V3 issue. If we want to have OAuth mentioned, it sounds like a specific requirement for V51. By content at the moment I see it as general requirement.

Is OAuth Introspection defines nbf and exp or it uses the definitions from JWT?

@elarlang elarlang removed the 4) proposal for review Issue contains clear proposal for add/change something label Oct 30, 2024
@randomstuff
Copy link
Contributor

@elarlang, the token introspection part can be skipped if needed.

The definitions of nbf and exp from token introspection reference the definition from JWT (but use them in a separate context):

exp OPTIONAL. Integer timestamp, measured in the number of seconds since January 1 1970 UTC, indicating when this token will expire, as defined in JWT [RFC7519].

[...]

nbf OPTIONAL. Integer timestamp, measured in the number of seconds since January 1 1970 UTC, indicating when this token is not to be used before, as defined in JWT [RFC7519].

@elarlang
Copy link
Collaborator Author

elarlang commented Nov 3, 2024

Those definitions I referenced in the issue description.

My point here is that we should make "in general" valid requirements for (JWT) tokens. If there is a more specific case to cover with some specific, then there is a need to make a separate requirement for the related paragraph.

@TobiasAhnoff
Copy link

A suggestion, as part of This is part of "cleaning up 3.5" see #1917 (comment), is to have:

Verify that the token is valid based on current time and, if present, the token identifier. For JWTs the claims 'iat', 'nbf' and 'exp' should be verified for time based validation. The claim 'jti' should be validated to identify a specific token, in example to assert that the token is only used once.

@randomstuff
Copy link
Contributor

The claim 'jti' should be validated to identify a specific token, in example to assert that the token is only used once.

I would not include this. It's usually OK to use your access token many times while it's still valid.

Some tokens are supposed to be used only once (ID token, DPoP proofs) but this is not the case for all tokens (such as access tokens).

@elarlang
Copy link
Collaborator Author

The claim 'jti' should be validated to identify a specific token, in example to assert that the token is only used once.

This is a separate test and problem to solve. Let this requirement only focus on the time window.

I would like the second part / example as it is:

For JWTs the claims 'iat', 'nbf' and 'exp' should be verified for time based validation.

But I did not find any solution for first part that I'm happy with. For a starter:

Verify that the token and it's content are accepted only if the verification time is within this validity time span in the token if such a validity time span is present in the token data.

@TobiasAhnoff
Copy link

This is a separate test and problem to solve. Let this requirement only focus on the time window.

I agree, good to split this.

But I did not find any solution for first part that I'm happy with.

Is this better?

Verify that, if validity time span is present in the token data, the token and it's content are accepted only if the verification time is within this validity time span. For JWTs the claims 'iat', 'nbf' and 'exp' should be verified.

@elarlang
Copy link
Collaborator Author

elarlang commented Nov 13, 2024

Some changes, including removed 'iat' claim, as it is not meant for time-window validation by JWT own spec. It can be used if the application logic works that way and the requirement is still valid for "validity must be checked" and for example, for JWT those claims must (I changed should to must) be used:

Verify that, if a validity time span is present in the token data, the token and it's content are accepted only if the verification time is within this validity time span. For example, for JWTs the claims 'nbf' and 'exp' must be verified.

@elarlang elarlang added 4) proposal for review Issue contains clear proposal for add/change something 5) awaiting PR A proposal hs been accepted and reviewed and we are now waiting for a PR and removed 4) proposal for review Issue contains clear proposal for add/change something labels Nov 13, 2024
elarlang pushed a commit to elarlang/ASVS that referenced this issue Nov 13, 2024
@elarlang elarlang mentioned this issue Nov 13, 2024
@elarlang elarlang added 6) PR awaiting review and removed 5) awaiting PR A proposal hs been accepted and reviewed and we are now waiting for a PR labels Nov 13, 2024
@elarlang elarlang linked a pull request Nov 13, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1) Discussion ongoing Issue is opened and assigned but no clear proposal yet 6) PR awaiting review V3 _5.0 - prep This needs to be addressed to prepare 5.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants