Skip to content

Commit 4e28153

Browse files
committed
[WebProfilerBundle] Fix CORS ajax security issues
1 parent a0125b6 commit 4e28153

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Resources/views/Profiler/base_js.html.twig

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@
8080
8181
requestStack = [],
8282
83+
extractHeaders = function(xhr, stackElement) {
84+
// Here we avoid to call xhr.getResponseHeader in order to
85+
// prevent polluting the console with CORS security errors
86+
var allHeaders = xhr.getAllResponseHeaders();
87+
var ret;
88+
89+
if (ret = allHeaders.match(/^x-debug-token:\s+(.*)$/im)) {
90+
stackElement.profile = ret[1];
91+
}
92+
if (ret = allHeaders.match(/^x-debug-token-link:\s+(.*)$/im)) {
93+
stackElement.profilerUrl = ret[1];
94+
}
95+
},
96+
8397
renderAjaxRequests = function() {
8498
var requestCounter = document.querySelectorAll('.sf-toolbar-ajax-requests');
8599
if (!requestCounter.length) {
@@ -239,8 +253,8 @@
239253
stackElement.duration = new Date() - stackElement.start;
240254
stackElement.loading = false;
241255
stackElement.error = self.status < 200 || self.status >= 400;
242-
stackElement.profile = self.getResponseHeader("X-Debug-Token");
243-
stackElement.profilerUrl = self.getResponseHeader("X-Debug-Token-Link");
256+
257+
extractHeaders(self, stackElement);
244258
245259
Sfjs.renderAjaxRequests();
246260
}

0 commit comments

Comments
 (0)