Copilot commented on code in PR #11359:
URL: https://github.com/apache/cloudstack/pull/11359#discussion_r2245077818
##########
ui/src/store/modules/user.js:
##########
@@ -496,9 +496,17 @@ const user = {
}).catch(() => {
resolve()
}).finally(() => {
+ const paths = ['/', '/client']
+ const hostname = window.location.hostname
+ const domains = [undefined, hostname, `.${hostname}`]
Review Comment:
The domain `.${hostname}` may create an invalid domain format. For example,
if hostname is 'localhost' or an IP address like '127.0.0.1', the resulting
domain '.localhost' or '.127.0.0.1' would be invalid. Consider validating the
hostname format before adding the dot prefix, or handle cases where the
hostname might not be a valid domain.
```suggestion
const isValidDomain = (name) => /^[a-zA-Z0-9.-]+$/.test(name) &&
!/^(\d{1,3}\.){3}\d{1,3}$/.test(name) && name !== 'localhost'
const domains = [undefined, hostname]
if (isValidDomain(hostname)) {
domains.push(`.${hostname}`)
}
```
##########
ui/src/store/modules/user.js:
##########
@@ -496,9 +496,17 @@ const user = {
}).catch(() => {
resolve()
}).finally(() => {
+ const paths = ['/', '/client']
+ const hostname = window.location.hostname
+ const domains = [undefined, hostname, `.${hostname}`]
Object.keys(Cookies.get()).forEach(cookieName => {
- Cookies.remove(cookieName)
- Cookies.remove(cookieName, { path: '/client' })
+ paths.forEach(path => {
+ domains.forEach(domain => {
+ const options = { path }
+ if (domain) options.domain = domain
+ Cookies.remove(cookieName, options)
+ })
Review Comment:
Using nested forEach loops results in O(n*m*k) complexity where n is the
number of cookies, m is the number of paths, and k is the number of domains.
This could be inefficient if there are many cookies. Consider batching the
operations or using a more efficient approach for cookie removal.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]