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: Some cookies are misusing the recommended “SameSite“ attribute #3106

Merged
merged 3 commits into from
Aug 8, 2024
Merged
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
9 changes: 2 additions & 7 deletions app/controllers/avo/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,8 @@ def set_force_locale(&action)
end

def set_sidebar_open
value = if cookies["#{Avo::COOKIES_KEY}.sidebar.open"].nil?
cookies["#{Avo::COOKIES_KEY}.sidebar.open"] = "1"
else
cookies["#{Avo::COOKIES_KEY}.sidebar.open"]
end

@sidebar_open = value == "1"
value = cookies["#{Avo::COOKIES_KEY}.sidebar.open"]
@sidebar_open = value.blank? || value == "1"
end

# Set the current host for ActiveStorage
Expand Down
13 changes: 11 additions & 2 deletions app/javascript/js/controllers/sidebar_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export default class extends Controller {
this.sidebarTarget.classList.remove('hidden')
}
this.mainAreaTarget.classList.toggle('sidebar-open')
const value = Cookies.get(this.cookieKey)
Cookies.set(this.cookieKey, value === '1' ? '0' : '1')

Cookies.set(this.cookieKey, this.newValue(Cookies.get(this.cookieKey)))
}

toggleSidebarOnMobile() {
Expand All @@ -104,4 +104,13 @@ export default class extends Controller {
}
this.mainAreaTarget.classList.toggle('sidebar-open')
}

// private
newValue(oldValue) {
if (oldValue === undefined) {
return '0'
}
return oldValue === '1' ? '0' : '1'
}

}
Loading