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

fix clock skew to right direction #1237

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/injectables/OAuthService.html
Original file line number Diff line number Diff line change
Expand Up @@ -11305,8 +11305,8 @@ <h3 id="inputs">
const clockSkewInMSec &#x3D; this.getClockSkewInMsec(); // (this.getClockSkewInMsec() || 600) * 1000;

if (
issuedAtMSec - clockSkewInMSec &gt;&#x3D; now ||
expiresAtMSec + clockSkewInMSec &lt;&#x3D; now
issuedAtMSec &gt;&#x3D; now - clockSkewInMSec ||
expiresAtMSec &lt;&#x3D; now + clockSkewInMSec
) {
const err &#x3D; &#x27;Token has expired&#x27;;
console.error(err);
Expand Down Expand Up @@ -11462,7 +11462,7 @@ <h3 id="inputs">
const now &#x3D; this.dateTimeService.new();
if (
expiresAt &amp;&amp;
parseInt(expiresAt, 10) &lt; now.getTime() - this.getClockSkewInMsec()
parseInt(expiresAt, 10) &lt; now.getTime() + this.getClockSkewInMsec()
) {
return false;
}
Expand All @@ -11482,7 +11482,7 @@ <h3 id="inputs">
const now &#x3D; this.dateTimeService.new();
if (
expiresAt &amp;&amp;
parseInt(expiresAt, 10) &lt; now.getTime() - this.getClockSkewInMsec()
parseInt(expiresAt, 10) &lt; now.getTime() + this.getClockSkewInMsec()
) {
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions projects/lib/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2263,8 +2263,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
const clockSkewInMSec = this.getClockSkewInMsec(); // (this.getClockSkewInMsec() || 600) * 1000;

if (
issuedAtMSec - clockSkewInMSec >= now ||
expiresAtMSec + clockSkewInMSec <= now
issuedAtMSec >= now - clockSkewInMSec ||
Copy link

@vincent-petit vincent-petit Sep 26, 2022

Choose a reason for hiding this comment

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

I think the sign of the clockSkew is wrong when comparing with the issuedAt.
In the case when the Identity Provider server clock is the same as the the browser clock, the issuedAt of a new/refreshed access_token/id_token will be very close to the server time.
Reducing the browser time with the clock skew, it will lead to the "token has expired" error each time, no?

Suggested change
issuedAtMSec >= now - clockSkewInMSec ||
issuedAtMSec >= now + clockSkewInMSec ||

Copy link
Author

Choose a reason for hiding this comment

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

I think you are right. The original code is correct here.

Copy link

@vincent-petit vincent-petit Sep 30, 2022

Choose a reason for hiding this comment

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

The original code was correct only for issuedAt attribute.
The updates you suggest on the expiresAt seem correct to me

expiresAtMSec <= now + clockSkewInMSec
) {
const err = 'Token has expired';
console.error(err);
Expand Down Expand Up @@ -2420,7 +2420,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
const now = this.dateTimeService.new();
if (
expiresAt &&
parseInt(expiresAt, 10) < now.getTime() - this.getClockSkewInMsec()
parseInt(expiresAt, 10) < now.getTime() + this.getClockSkewInMsec()
) {
return false;
}
Expand All @@ -2440,7 +2440,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
const now = this.dateTimeService.new();
if (
expiresAt &&
parseInt(expiresAt, 10) < now.getTime() - this.getClockSkewInMsec()
parseInt(expiresAt, 10) < now.getTime() + this.getClockSkewInMsec()
) {
return false;
}
Expand Down