Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e0a86b

Browse files
committed
Remove XDEBUG_SESSION cookie while performing XHRs
1 parent c4e97eb commit 8e0a86b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md

+5
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

+32
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,34 @@
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) {
104+
if (xdebugCookieValue !== null) {
105+
setCookie('XDEBUG_SESSION', xdebugCookieValue, 365);
106+
}
107+
81108
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
82109
options = options || {};
83110
options.retry = options.retry || false;
@@ -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)