8000 Remove XDEBUG_SESSION cookie while performing XHRs · symfony/symfony@76241d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 76241d9

Browse files
committed
Remove XDEBUG_SESSION cookie while performing XHRs
1 parent c4e97eb commit 76241d9

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Disable the XDEBUG_SESSION cookie while sending toolbar requests
8+
49
6.4
510
---
611

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,29 @@
7777
});
7878
}
7979
80+
const setCookie = function (name, value, days) {
81+
var exp = new Date();
82+
exp.setTime(exp.getTime() + (days * 24 * 60 * 60 * 1000));
83+
document.cookie = name + '=' + value + '; expires=' + exp.toGMTString() + '; path=/; SameSite=Lax';
84+
};
85+
86+
const getCookie = function (name) {
87+
var prefix = name + '=';
88+
var cookieStartIndex = document.cookie.indexOf(prefix);
89+
var cookieEndIndex;
90+
91+
if (cookieStartIndex == -1) {
92+
return null;
93+
}
94+
95+
cookieEndIndex = document.cookie.indexOf(';', cookieStartIndex + prefix.length);
96+
if (cookieEndIndex == -1) {
97+
cookieEndIndex = document.cookie.length;
98+
}
99+
100+
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
101+
};
102+
80103
var request = function(url, onSuccess, onError, payload, options, tries) {
81104
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
82105
options = options || {};
@@ -88,6 +111,10 @@
88111
xhr.open(options.method || 'GET', url, true);
89112
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
90113
xhr.onreadystatechange = function(state) {
114+
if (xdebugCookieValue !== null) {
115+
setCookie('XDEBUG_SESSION', xdebugCookieValue, 365);
116+
}
117+
91118
if (4 !== xhr.readyState) {
92119
return null;
93120
}
@@ -114,6 +141,11 @@
114141
options.onSend(tries);
115142
}
116143
144+
var xdebugCookieValue = getCookie('XDEBUG_SESSION');
145+
if (xdebugCookieValue !== null) {
146+
setCookie('XDEBUG_SESSION', null, -1);
147+
}
148+
117149
xhr.send(payload || '');
118150
};
119151

0 commit comments

Comments
 (0)
0