Skip to content
Permalink
Browse files
[FIXED JENKINS-32074] When rootURL is empty, store cookies at '/'
When Jenkins is running from the top-level URL, the rootURL variable is an empty
string. In this case, store the cookies at '/' instead of rootURL.

Prior to this change, the cookies were created with an empty path, and the
browser defaults to storing them at the build URL. These cookies will now be
deleted because they would override the cookies stored at the Jenkins URL.

Bug introduced by JENKINS-29899.
  • Loading branch information
StevenGBrown committed Jan 13, 2016
1 parent 409ae92 commit 26f6fdb2d47f88e1fe8afd454407fc5283eaeb6b
Showing with 11 additions and 1 deletion.
  1. +11 −1 src/main/resources/hudson/plugins/timestamper/annotator/TimestampAnnotatorFactory/script.js
@@ -42,6 +42,12 @@ function init() {
'local': document.getElementById('timestamper-localTime')
};

// Delete cookies added with the wrong path by Timestamper 1.7.2. See JENKINS-32074.
var attributes = '; path=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
document.cookie = 'jenkins-timestamper=' + attributes;
document.cookie = 'jenkins-timestamper-local=' + attributes;
document.cookie = 'jenkins-timestamper-offset=' + attributes;

// Set the mode from a cookie or initialize it (also handle migrating old cookie values to new ones).
var mode = getCookie() || 'system';
if (mode == 'local') {
@@ -106,9 +112,13 @@ function setCookie(value, suffix) {
name += '-' + suffix;
}

var path = '/';
if (rootURL) {
path = rootURL;
}
var currentDate = new Date();
currentDate.setTime(currentDate.getTime() + 1000 * 60 * 60 * 24 * 365 * 2); // 2 years
var attributes = '; path=' + rootURL + '; expires=' + currentDate.toGMTString();
var attributes = '; path=' + path + '; expires=' + currentDate.toGMTString();
document.cookie = name + '=' + value + attributes;
}

0 comments on commit 26f6fdb

Please sign in to comment.