Skip to content

Commit 20d694e

Browse files
committed
bug symfony#18413 [2.7][WebProfilerBundle] Fix CORS ajax security issues (romainneutron)
This PR was merged into the 2.7 branch. Discussion ---------- [2.7][WebProfilerBundle] Fix CORS ajax security issues | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A The WebProfiler toolbar monitors ajax requests. However, when using cross domain ajax requests, it triggers a security issues `Refused to get unsafe header "X-Debug-Token"` `Refused to get unsafe header "X-Debug-Token-Link"` because if the other app is not a Symfony App configured to expose these headers in CORS. ![image](https://cloud.githubusercontent.com/assets/137574/14225799/f462c09c-f8cf-11e5-925d-88be99945a92.png) This fixes the issue. It adds a new configuration node to explicitly activate it on purpose. Commits ------- f8dd87d [WebProfilerBundle] Fix CORS ajax security issues
2 parents 66da91d + f8dd87d commit 20d694e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Symfony/Bundle/WebProfilerBundle/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)