Skip to content

Commit b9a7bb5

Browse files
committed
Set secure attribute on cookies if possible
Signed-off-by: Michal Kolodziejski <[email protected]>
1 parent 4fed5af commit b9a7bb5

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

public/js/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,8 @@ function toggleNightMode () {
16331633
} else {
16341634
Cookies.set('nightMode', !isActive, {
16351635
expires: 365,
1636-
sameSite: 'Lax'
1636+
sameSite: 'Lax',
1637+
secure: window.location.protocol === 'https:'
16371638
})
16381639
}
16391640
}

public/js/lib/common/login.js

+4-2
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

+20-10
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,15 @@ export default class Editor {
415415
if (this.editor.getOption('indentWithTabs')) {
416416
Cookies.set('indent_type', 'tab', {
417417
expires: 365,
418-
sameSite: 'Lax'
418+
sameSite: 'Lax',
419+
secure: window.location.protocol === 'https:'
419420
})
420421
type.text('Tab Size:')
421422
} else {
422423
Cookies.set('indent_type', 'space', {
423424
expires: 365,
424-
sameSite: 'Lax'
425+
sameSite: 'Lax',
426+
secure: window.location.protocol === 'https:'
425427
})
426428
type.text('Spaces:')
427429
}
@@ -433,12 +435,14 @@ export default class Editor {
433435
if (this.editor.getOption('indentWithTabs')) {
434436
Cookies.set('tab_size', unit, {
435437
expires: 365,
436-
sameSite: 'Lax'
438+
sameSite: 'Lax',
439+
secure: window.location.protocol === 'https:'
437440
})
438441
} else {
439442
Cookies.set('space_units', unit, {
440443
expires: 365,
441-
sameSite: 'Lax'
444+
sameSite: 'Lax',
445+
secure: window.location.protocol === 'https:'
442446
})
443447
}
444448
widthLabel.text(unit)
@@ -507,7 +511,8 @@ export default class Editor {
507511
var keymap = this.editor.getOption('keyMap')
508512
Cookies.set('keymap', keymap, {
509513
expires: 365,
510-
sameSite: 'Lax'
514+
sameSite: 'Lax',
515+
secure: window.location.protocol === 'https:'
511516
})
512517
label.text(keymap)
513518
this.restoreOverrideEditorKeymap()
@@ -543,7 +548,8 @@ export default class Editor {
543548
this.editor.setOption('theme', theme)
544549
Cookies.set('theme', theme, {
545550
expires: 365,
546-
sameSite: 'Lax'
551+
sameSite: 'Lax',
552+
secure: window.location.protocol === 'https:'
547553
})
548554
this.statusIndicators.find('.status-theme li').removeClass('active')
549555
this.statusIndicators.find(`.status-theme li[value="${theme}"]`).addClass('active')
@@ -646,7 +652,8 @@ export default class Editor {
646652

647653
Cookies.set('spellcheck', false, {
648654
expires: 365,
649-
sameSite: 'Lax'
655+
sameSite: 'Lax',
656+
secure: window.location.protocol === 'https:'
650657
})
651658

652659
self.editor.setOption('mode', defaultEditorMode)
@@ -655,7 +662,8 @@ export default class Editor {
655662

656663
Cookies.set('spellcheck', lang, {
657664
expires: 365,
658-
sameSite: 'Lax'
665+
sameSite: 'Lax',
666+
secure: window.location.protocol === 'https:'
659667
})
660668

661669
self.editor.setOption('mode', 'spell-checker')
@@ -677,7 +685,8 @@ export default class Editor {
677685
}
678686
Cookies.set('linter', true, {
679687
expires: 365,
680-
sameSite: 'Lax'
688+
sameSite: 'Lax',
689+
secure: window.location.protocol === 'https:'
681690
})
682691
} else {
683692
this.editor.setOption('gutters', gutters.filter(g => g !== lintGutter))
@@ -727,7 +736,8 @@ export default class Editor {
727736
if (overrideBrowserKeymap.is(':checked')) {
728737
Cookies.set('preferences-override-browser-keymap', true, {
729738
expires: 365,
730-
sameSite: 'Lax'
739+
sameSite: 'Lax',
740+
secure: window.location.protocol === 'https:'
731741
})
732742
this.restoreOverrideEditorKeymap()
733743
} else {

public/js/locale.js

+2-1
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)