From 7901a00bd7b2edfd02c906ba5070a170d9a1d3fd Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 18 Jun 2023 15:13:54 -0400 Subject: [PATCH] Fix handling of `path` in `set-cookie` scriptlet As per feedback from filter list volunteers. --- assets/resources/scriptlets.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 874ced88d..e30e26c67 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -739,7 +739,11 @@ function setCookieHelper( if ( expires !== '' ) { cookieParts.push('; expires=', expires); } - if ( path !== '' ) { + + if ( path === '' ) { path = '/'; } + else if ( path === 'none' ) { path = ''; } + if ( path !== '' && path !== '/' ) { return; } + if ( path === '/' ) { cookieParts.push('; path=/'); } document.cookie = cookieParts.join(''); @@ -2752,10 +2756,6 @@ function setCookie( } value = encodeURIComponent(value); - const validPaths = [ '', '/', 'none' ]; - if ( validPaths.includes(path) === false ) { return; } - if ( path === 'none' ) { path = ''; } - setCookieHelper( name, value, @@ -2894,10 +2894,6 @@ function trustedSetCookie( expires = time.toUTCString(); } - const validPaths = [ '', '/', 'none' ]; - if ( validPaths.includes(path) === false ) { return; } - if ( path === 'none' ) { path = ''; } - setCookieHelper( name, value,