Repository navigation
Conversation
|
Aligning the session duration with a configurable value rather than the hard-coded 7 days addresses the issue raised. However, there are a couple of things worth reviewing:
It would also help to include a short “Changes Made” or brief testing note instead of just “Not tested”, even if only manual verification steps. |
Updated |
|
LGTM. Thanks for addressing the typing change and path normalisation, and for adding tests around no-expiry and cookie path handling |
|
@steadytao are you able to merge this now? |
| tokens *tokenManager | ||
| } | ||
|
|
||
| const defaultSessionCookieDurationS = 7 * 24 * 60 * 60 |
There was a problem hiding this comment.
Maybe keep this among the other constants?
| c.SessionCookiePath = strings.TrimSpace(c.SessionCookiePath) | ||
| if c.SessionCookiePath == "" { | ||
| c.SessionCookiePath = "/" | ||
| } else if !strings.HasPrefix(c.SessionCookiePath, "/") { |
There was a problem hiding this comment.
This check also covers the condition of the one above, so could be the only one.
| path := strings.TrimSpace(m.guiCfg.SessionCookiePath) | ||
| if path == "" { | ||
| return "/" | ||
| } | ||
| if !strings.HasPrefix(path, "/") { | ||
| return "/" + path | ||
| } |
There was a problem hiding this comment.
Why do we repeat these checks here for every request, isn't it enough that we validated the config?
There was a problem hiding this comment.
Mainly defensive but if you think it's not needed, I have updated it.
| // this cookie is still only as safe as client storage; | ||
| // if stolen it remains valid until explicitly logged out. | ||
| return math.MaxInt32 |
There was a problem hiding this comment.
Can you expand on what you mean with this comment? I'm sure it's true, but not clear on how it relates to the code/maxint32?
There was a problem hiding this comment.
This comment was added as per the request of @steadytao in #10564 (comment)
There was a problem hiding this comment.
Updated comment to make it clearer
calmh
left a comment
There was a problem hiding this comment.
(breaks tests, though frankly not sure why)
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Fixed, please recheck when you can @calmh |
| func (c GUIConfiguration) PreparedCopy() GUIConfiguration { | ||
| c.prepare() | ||
| return c |
There was a problem hiding this comment.
Wait, why is this needed? I'm suspicious that we suddenly need to add another pattern for config handling that we didn't need before... Seems like we're adding a footgun of some kind that we should be handling differently.
There was a problem hiding this comment.
PreparedCopy() is basically a normalization for read/comparison without mutating the original struct, because prepare() is already creating a mutation. Let me know if you have a better approach though.
There was a problem hiding this comment.
But why? Surely we do prepare() on load and unmarshal?
There was a problem hiding this comment.
I was using PreparedCopy() because I understand that GUIConfiguration can also be constructed or copied outside the normal config paths, and I wanted to handle the case where callers want normalized values. However based on your comment I changed it now to use the existing Copy(). Tests are passing. LMK if this is better?
There was a problem hiding this comment.
I feel like this is heading down a strange path. :) We shouldn't need to change anything about how the configs are created, validated, or compared based on this change. The additional validation in prepare() is fine, and it's already called at the points it needs to be. If the problem you're trying to solve is in tests, the proper solution is to make sure the input data in the tests is correct.
There was a problem hiding this comment.
I have removed PreparedCopy() in my previous commit and using the existing prepare() now. Let me know if that's better.
Signed-off-by: Vikram Vaswani <[email protected]>
| // The returned Wrapper is a suture.Service, thus needs to be started (added to | ||
| // a supervisor). | ||
| func Wrap(path string, cfg Configuration, myID protocol.DeviceID, evLogger events.Logger) Wrapper { | ||
| cfg.GUI.prepare() |
| path := strings.TrimSpace(c.SessionCookiePath) | ||
| if !strings.HasPrefix(path, "/") { | ||
| path = "/" + path | ||
| } |
There was a problem hiding this comment.
This belonged better in prepare() where you had it, imho, instead of doing the fixup on every call.
| } | ||
|
|
||
| const ( | ||
| noExpiryNano int64 = math.MaxInt64 |
There was a problem hiding this comment.
Again suggesting this should just be left at zero instead; are there downsides to that approach I'm not seeing?
There was a problem hiding this comment.
TBH this was added in response to the comment by @steadytao which says For noExpiryNano, it may be safer to use math.MaxInt64 or explicitly type the const as an int64 to avoid any potential shift/overflow edge cases with 1<<63.
I have changed it to 0 - however one point to note is that in Check() and saveLocked(), anything that is not noExpiryNano is treated as a Unix timestamp. Since 0 < now, a zero token is immediately expired and gets deleted. I'm not sure if this makes a tangible difference though.
| func (m *tokenCookieManager) sessionCookiePath() string { | ||
| return m.guiCfg.EffectiveSessionCookiePath() | ||
| } |
| fromGUI := from.GUI.Copy() | ||
| toGUI := to.GUI.Copy() | ||
|
|
||
| if toGUI == fromGUI { | ||
| // No GUI changes, we're done here. | ||
| return true | ||
| } | ||
|
|
||
| if to.GUI.Theme != from.GUI.Theme { | ||
| s.statics.setTheme(to.GUI.Theme) | ||
| if toGUI.Theme != fromGUI.Theme { | ||
| s.statics.setTheme(toGUI.Theme) |
There was a problem hiding this comment.
These changes should not be required I think
|
Modified as per your suggestions @calmh - thanks for your patience. Also ran tests, seems OK. |
Signed-off-by: Vikram Vaswani <[email protected]> fix: add feedback Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
|
I messed up the rebase, closing and reopening as new in #10632 |
Purpose
Fixes #10522
Testing
Tested with:
Authorship
Your name and email will be added automatically to the AUTHORS file
based on the commit metadata.