From f4071d657cddd2a82bb47b1ef94a952909188d6e Mon Sep 17 00:00:00 2001 From: Stefan Dirsch Date: Tue, 19 Nov 2019 20:14:55 +0100 Subject: [PATCH] Add support for 'sessionid' cookie as alternative to "SACSID" cookie SACSID already expires after 24 hours, whereas 'sessionid' cookie expires after 2 weeks. So using 'sessionid' instead of SACSID improves the situation. Using SACSID is still supported though to remain compatibility. This resolves github issue #3. --- ice/ingress-ice.conf.sample | 8 ++++++-- ice/modules/ice-30-config.js | 3 +++ ice/modules/ice-60-core.js | 14 +++++++++++--- ice/modules/ice-70-login-cookies.js | 15 +++++++++++++-- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/ice/ingress-ice.conf.sample b/ice/ingress-ice.conf.sample index bf03110..5ce9ac8 100644 --- a/ice/ingress-ice.conf.sample +++ b/ice/ingress-ice.conf.sample @@ -5,7 +5,7 @@ [ice] #> Your Google login and password -# Authentication via login/password currently not working at all; use cookies, i.e. SACSID/CSRF options below (issue #1) +# Authentication via login/password currently not working at all; use cookies, i.e. SACSID/sessionid and CSRF options below (issue #1) #login= #password= #> Your area link. To get it, visit https://intel.ingress.com/intel, scroll the map to your location and press [LINK] at the top right corner. Copy that link and paste it here. @@ -53,8 +53,12 @@ consoleLog= [cookies] #> If set, will use cookies for authentication instead of login/password -# Firefox: use Webdeveloper/Storage Inspector on https://intel.ingress.com/intel (csrftoken/SACSID) +# Firefox: use Webdeveloper/Storage Inspector on https://intel.ingress.com/intel (csrftoken/SACSID/sessionid) +# Either specify 'SACSID' or 'sessionid' cookie (or both) +# SACSID already expires after 24 hours! SACSID= +# 'sessionid' expires after two weeks, so this is preferred +sessionid= CSRF= [Amazon-S3] diff --git a/ice/modules/ice-30-config.js b/ice/modules/ice-30-config.js index 553ba64..3c9ede8 100644 --- a/ice/modules/ice-30-config.js +++ b/ice/modules/ice-30-config.js @@ -19,6 +19,9 @@ if ( ) && ( typeof config.SACSID == 'undefined' || config.SACSID === '' || typeof config.CSRF == 'undefined' || config.CSRF === '' + ) && ( + typeof config.sessionid == 'undefined' || config.sessionid === '' || + typeof config.CSRF == 'undefined' || config.CSRF === '' ) ) || ( typeof config.area == 'undefined' || config.area === '' diff --git a/ice/modules/ice-60-core.js b/ice/modules/ice-60-core.js index b3dfd16..3f9628c 100644 --- a/ice/modules/ice-60-core.js +++ b/ice/modules/ice-60-core.js @@ -205,13 +205,21 @@ function main() { */ function ice() { greet(); - if (config.SACSID == undefined || config.SACSID == '') { + if ((config.SACSID == undefined || config.SACSID == '') && + (config.sessionid == undefined || config.sessionid == '')) { loadCookies(); } - if (config.SACSID == undefined || config.SACSID == '') { + if ((config.SACSID == undefined || config.SACSID == '') && + (config.sessionid == undefined || config.sessionid == '')) { firePlainLogin(); } else { - addCookies(config.SACSID, config.CSRF); + if (config.SACSID == undefined) { + config.SACSID='' + } + if (config.sessionid == undefined) { + config.sessionid='' + } + addCookies(config.SACSID, config.CSRF, config.sessionid); announce('Using cookies to log in'); afterCookieLogin(); } diff --git a/ice/modules/ice-70-login-cookies.js b/ice/modules/ice-70-login-cookies.js index ce8e045..996adde 100644 --- a/ice/modules/ice-70-login-cookies.js +++ b/ice/modules/ice-70-login-cookies.js @@ -19,7 +19,7 @@ /*global cookiespath */ /** - * Checks if cookies file exists. If so, it sets SACSID and CSRF vars + * Checks if cookies file exists. If so, it sets SACSID/sessionid and CSRF vars * @returns {boolean} * @author mfcanovas (github.com/mfcanovas) * @since 3.2.0 @@ -34,6 +34,8 @@ function loadCookies() { config.SACSID = line[1]; } else if(line[0] === 'csrftoken') { config.CSRF = line[1]; + } else if(line[0] === 'sessionid') { + config.sessionid = line[1]; } } stream.close(); @@ -46,7 +48,7 @@ function loadCookies() { * @param {String} csrf * @since 3.1.0 */ -function addCookies(sacsid, csrf) { +function addCookies(sacsid, csrf, sessionid) { phantom.addCookie({ name: 'SACSID', value: sacsid, @@ -61,6 +63,14 @@ function addCookies(sacsid, csrf) { domain: 'intel.ingress.com', path: '/' }); + phantom.addCookie({ + name: 'sessionid', + value: sessionid, + domain: 'intel.ingress.com', + path: '/', + httponly: true, + secure: true + }); } @@ -79,6 +89,7 @@ function afterCookieLogin() { if(config.login && config.password) { page.deleteCookie('SACSID'); page.deleteCookie('csrftoken'); + page.deleteCookie('sessionid'); firePlainLogin(); return; } else {