Skip to content

Commit c8eab94

Browse files
committed
Set secure attribute on cookies if possible
Signed-off-by: Michal Kolodziejski <michal.kolodziejski@cern.ch>
1 parent e608f57 commit c8eab94

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

public/js/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,8 @@ function toggleNightMode () {
16011601
} else {
16021602
Cookies.set('nightMode', !isActive, {
16031603
expires: 365,
1604-
sameSite: 'Lax'
1604+
sameSite: 'Lax',
1605+
secure: window.location.protocol === 'https:'
16051606
})
16061607
}
16071608
}

public/js/lib/common/login.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ export function resetCheckAuth () {
2020
export function setLoginState (bool, id) {
2121
Cookies.set('loginstate', bool, {
2222
expires: 365,
23-
sameSite: 'Lax'
23+
sameSite: 'Lax',
24+
secure: window.location.protocol === 'https:'
2425
})
2526
if (id) {
2627
Cookies.set('userid', id, {
2728
expires: 365,
28-
sameSite: 'Lax'
29+
sameSite: 'Lax',
30+
secure: window.location.protocol === 'https:'
2931
})
3032
} else {
3133
Cookies.remove('userid')

public/js/lib/editor/index.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,15 @@ export default class Editor {
451451
if (this.editor.getOption('indentWithTabs')) {
452452
Cookies.set('indent_type', 'tab', {
453453
expires: 365,
454-
sameSite: 'Lax'
454+
sameSite: 'Lax',
455+
secure: window.location.protocol === 'https:'
455456
})
456457
type.text('Tab Size:')
457458
} else {
458459
Cookies.set('indent_type', 'space', {
459460
expires: 365,
460-
sameSite: 'Lax'
461+
sameSite: 'Lax',
462+
secure: window.location.protocol === 'https:'
461463
})
462464
type.text('Spaces:')
463465
}
@@ -469,12 +471,14 @@ export default class Editor {
469471
if (this.editor.getOption('indentWithTabs')) {
470472
Cookies.set('tab_size', unit, {
471473
expires: 365,
472-
sameSite: 'Lax'
474+
sameSite: 'Lax',
475+
secure: window.location.protocol === 'https:'
473476
})
474477
} else {
475478
Cookies.set('space_units', unit, {
476479
expires: 365,
477-
sameSite: 'Lax'
480+
sameSite: 'Lax',
481+
secure: window.location.protocol === 'https:'
478482
})
479483
}
480484
widthLabel.text(unit)
@@ -543,7 +547,8 @@ export default class Editor {
543547
var keymap = this.editor.getOption('keyMap')
544548
Cookies.set('keymap', keymap, {
545549
expires: 365,
546-
sameSite: 'Lax'
550+
sameSite: 'Lax',
551+
secure: window.location.protocol === 'https:'
547552
})
548553
label.text(keymap)
549554
this.restoreOverrideEditorKeymap()
@@ -579,7 +584,8 @@ export default class Editor {
579584
this.editor.setOption('theme', theme)
580585
Cookies.set('theme', theme, {
581586
expires: 365,
582-
sameSite: 'Lax'
587+
sameSite: 'Lax',
588+
secure: window.location.protocol === 'https:'
583589
})
584590
this.statusIndicators.find('.status-theme li').removeClass('active')
585591
this.statusIndicators.find(`.status-theme li[value="${theme}"]`).addClass('active')
@@ -682,7 +688,8 @@ export default class Editor {
682688

683689
Cookies.set('spellcheck', false, {
684690
expires: 365,
685-
sameSite: 'Lax'
691+
sameSite: 'Lax',
692+
secure: window.location.protocol === 'https:'
686693
})
687694

688695
self.editor.setOption('mode', defaultEditorMode)
@@ -691,7 +698,8 @@ export default class Editor {
691698

692699
Cookies.set('spellcheck', lang, {
693700
expires: 365,
694-
sameSite: 'Lax'
701+
sameSite: 'Lax',
702+
secure: window.location.protocol === 'https:'
695703
})
696704

697705
self.editor.setOption('mode', 'spell-checker')
@@ -713,7 +721,8 @@ export default class Editor {
713721
}
714722
Cookies.set('linter', true, {
715723
expires: 365,
716-
sameSite: 'Lax'
724+
sameSite: 'Lax',
725+
secure: window.location.protocol === 'https:'
717726
})
718727
} else {
719728
this.editor.setOption('gutters', gutters.filter(g => g !== lintGutter))
@@ -763,7 +772,8 @@ export default class Editor {
763772
if (overrideBrowserKeymap.is(':checked')) {
764773
Cookies.set('preferences-override-browser-keymap', true, {
765774
expires: 365,
766-
sameSite: 'Lax'
775+
sameSite: 'Lax',
776+
secure: window.location.protocol === 'https:'
767777
})
768778
this.restoreOverrideEditorKeymap()
769779
} else {

public/js/locale.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ $('select.ui-locale option[value="' + lang + '"]').attr('selected', 'selected')
2626
locale.change(function () {
2727
Cookies.set('locale', $(this).val(), {
2828
expires: 365,
29-
sameSite: 'Lax'
29+
sameSite: 'Lax',
30+
secure: window.location.protocol === 'https:'
3031
})
3132
window.location.reload()
3233
})

0 commit comments

Comments
 (0)