-
Notifications
You must be signed in to change notification settings - Fork 7
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
Set tokenTimeToLive in seconds from now #18
Conversation
`getTokenTimeToLive` uses a default value 15 days from current date in milliseconds: ``` System.currentTimeMillis() + 3600 * 24 * 15 * 1000 ``` However, the value is then used to configure the [Max-Age cookie property](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#max-agenumber]): https://github.com/kinde-oss/kinde-java-sdk/blob/main/src/main/java/org/openapitools/sdk/storage/Storage.java#L65 According to MDN web docs, the max-age of a cookie "_Indicates the number of seconds until the cookie expires_", so it should be specified in seconds from now. For this reason, I'm changing the default value used here to reflect 15 days in seconds
WalkthroughThe Changes
Sequence Diagram(s)The changes are straightforward and do not introduce new features or significantly alter the control flow, hence sequence diagrams are not necessary. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
src/main/java/org/openapitools/sdk/storage/Storage.java (1)
90-90
: The change correctly sets the token TTL to 15 days in seconds, aligning with the PR objectives.Consider adding a comment explaining why the value is in seconds, to aid future maintainability.
This has been open now for more than a month. Would someone be able to have a look? |
Hi - you missed two other methods in that same class that need a similar fix. setState Regards, |
See previous commit for more detail
Fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/main/java/org/openapitools/sdk/storage/Storage.java (4 hunks)
Additional comments not posted (3)
src/main/java/org/openapitools/sdk/storage/Storage.java (3)
90-90
: LGTM!The method correctly returns a fixed value representing 15 days in seconds.
102-102
: LGTM!The method correctly sets the expiration time for the state to 2 hours in seconds.
111-111
: LGTM!The method correctly sets the expiration time for the code verifier to 2 hours in seconds.
@@ -87,7 +87,7 @@ public static Long getExpiredAt(HttpServletRequest request) { | |||
} | |||
|
|||
public static Long getTokenTimeToLive() { | |||
return tokenTimeToLive != null ? tokenTimeToLive : System.currentTimeMillis() + 3600 * 24 * 15 * 1000; // Live in 15 days | |||
return tokenTimeToLive != null ? tokenTimeToLive : 3600 * 24 * 15; // Live in 15 days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can define as a static final int FIFTEEN_DAYS = 3600 * 24 * 15
and use in getTokenTImeToLeave. And the function can also simplify:
public static Long getTokenTimeToLive() {
return tokenTimeToLive == null ? FIFTEEN_DAYS : tokenTimeToLive;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe correct implementation would be:
public static Long getTokenTimeToLive() {
return tokenTimeToLive != null ? tokenTimeToLive : 3600 * 24 * 15 * 1000; // Live in 15 days
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@7171mayanktyagi that was removed in f87edcb My comments was related to current PR, if calculation will be changed, could properly change the above my comments as well, where I already specify the constants. Which was my only notes + simplify nullify check, and not negate null checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As, value of getTokenTimeToLive() is being passed in setMaxAge() of Cookie. And it accept value in ms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hhovhann, I also came across this #PR on Upwork. The question is, who is the author of this post?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#18 (comment) - @7171mayanktyagi my comment wasn't realated to cookies maxage, my comments was suggestion to use constants define in class level the value of the constant what would be used for the calculatation.
Based on Java Documentation suggesting to use the Constants in code instead of numbers, which i suggested, as well as the better practise. Upto you will you use it or no, this is just the suggestion and again I am not the code owner to restrict your commit. I hope I am clear in my explanations
#18 (comment) - @7171mayanktyagi the upwork job post not visible the company name, because that is job post which you can apply and if the Job poster will respond you then you can see the company/person. I just see on comments the people when adding the feedback the name Andre, not sure if Andre is part of the Kinde.
Hope my clarifications is enough for you.
@@ -99,7 +99,7 @@ public static String getState(HttpServletRequest request) { | |||
} | |||
|
|||
public static void setState( HttpServletResponse response,String newState) { | |||
setItem(response,StorageEnums.STATE.getValue(), newState,(int) ((long) (System.currentTimeMillis() + 3600 *2 ))); | |||
setItem(response,StorageEnums.STATE.getValue(), newState, 3600 * 2); // 2 hours |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same is here
int static final TWO_DAYS = 3600 * 2;
public static void setState( HttpServletResponse response,String newState) {
setItem(response,StorageEnums.STATE.getValue(), newState, TWO_HOURS); // 2 hours
// set expiration time for state
}
@@ -108,7 +108,7 @@ public static String getCodeVerifier(HttpServletRequest request) { | |||
} | |||
|
|||
public static void setCodeVerifier(HttpServletResponse response,String newCodeVerifier) { | |||
setItem(response,StorageEnums.CODE_VERIFIER.getValue(), newCodeVerifier,(int) ((long) (System.currentTimeMillis() + 3600 *2 ))); | |||
setItem(response,StorageEnums.CODE_VERIFIER.getValue(), newCodeVerifier, 3600 * 2); // 2 hours |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same is here
int static final TWO_DAYS = 3600 * 2;
public static void setCodeVerifier(HttpServletResponse response,String newCodeVerifier) {
setItem(response,StorageEnums.CODE_VERIFIER.getValue(), newCodeVerifier, TWO_DAYS); // 2 hours
// set expiration time for code verifier
}
Added couple of comments please take alook, otherwise LGTM |
Listen, there's clearly a bug in your code. I've put up a PR with a fix. It's been ignored for two months and I have had to escalate to your security team to even had it looked at. And now you're asking me to tidy up your commercial codebase while I'm at it. I suggest you apply any cosmetic changes you're interested in in your own paid time and merge the PR when you think it's ready. |
Dear @arnfred if this message #18 (comment) to me, unfortunately I am not the owner of the code and I just added my comments as a free contribution based on the open upwork job post. If that wasn't to me, then you can ignore this comment. Thanks |
My comment was to you. I assumed you were working for Kinde. To any Kinde employee seeing this PR:Browser cookies with the wrong expiry date in your official SDK is BAD. You want this fixed. All of your customers who use this SDK will be affected. Their users will not see updated permissions because their tokens aren't updating. They will stay logged in after their user has been revoked and disabled for practically forever. The current value of |
Well said! It's Immortal cookie . |
Have you seen this issue #12 ? |
Why use magic numbers and constants? There's already a built in JDK method for this: |
This is no longer required with the reworked SDK. Please close |
Since this PR was originally created, the SDK has undergone a significant refactor. The changes made during that process have rendered this PR redundant. Therefore, we are closing it. Thank you for your contribution! |
getTokenTimeToLive
uses a default value 15 days from current date in milliseconds:However, the value is then used to configure the Max-Age cookie property: https://github.com/kinde-oss/kinde-java-sdk/blob/main/src/main/java/org/openapitools/sdk/storage/Storage.java#L65
According to MDN web docs, the max-age of a cookie "Indicates the number of seconds until the cookie expires", so it should be specified in seconds from now.
For this reason, I'm changing the default value used here to reflect 15 days in seconds
Explain your changes
Suppose there is a related issue with enough detail for a reviewer to understand your changes fully. In that case, you can omit an explanation and instead include either “Fixes #XX” or “Updates #XX” where “XX” is the issue number.
Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.