Skip to content

Commit a4f6f6e

Browse files
authored
N°4368 Fix CORB blocking regression (#598)
Don't send X-Content-Type-Options HTTP header for certain WebPage impl to workaround CORB blocking To disable globally this new behavior introduced in 9865bf0, set the `security.enable_header_xcontent_type_options` config parameter to false Thanks @Molkobain for the review !
1 parent 94c604a commit a4f6f6e

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

application/ajaxwebpage.class.inc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ function __construct($s_title) {
5151
utils::InitArchiveMode();
5252
}
5353

54+
/**
55+
* Disabling sending the header so that resource won't be blocked by CORB. See parent method documentation.
56+
* @return void
57+
* @since 2.7.10 3.0.4 3.1.2 3.2.0 N°4368 method creation
58+
*/
59+
public function add_xcontent_type_options()
60+
{
61+
// Nothing to do !
62+
}
63+
5464
/**
5565
* @inheritDoc
5666
* @throws \Exception

application/webpage.class.inc.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,12 @@ public function add_http_headers($sXFrameOptionsHeaderValue = null)
495495
}
496496

497497
/**
498-
* @param string|null $sHeaderValue for example `SAMESITE`. If null will set the header using the config parameter value.
498+
* @param string|null $sHeaderValue for example `SAMESITE`. If null will set the header using the `security_header_xframe` config parameter value.
499499
*
500500
* @since 2.7.3 3.0.0 N°3416
501-
* @uses security_header_xframe config parameter
502501
* @uses \utils::GetConfig()
503502
*
504-
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
503+
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options HTTP header MDN documentation
505504
*/
506505
public function add_xframe_options($sHeaderValue = null)
507506
{
@@ -513,13 +512,34 @@ public function add_xframe_options($sHeaderValue = null)
513512
}
514513

515514
/**
515+
* Warning : this header will trigger the Cross-Origin Read Blocking (CORB) protection for some mime types (HTML, XML except SVG, JSON, text/plain)
516+
* In consequence some children pages will override this method.
517+
*
518+
* Sending header can be disabled globally using the `security.enable_header_xcontent_type_options` optional config parameter.
519+
*
516520
* @return void
517521
* @since 2.7.10 3.0.4 3.1.2 3.2.0 N°4368 method creation
518522
*
519-
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
523+
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options HTTP header MDN documentation
524+
* @link https://chromium.googlesource.com/chromium/src/+/master/services/network/cross_origin_read_blocking_explainer.md#determining-whether-a-response-is-corb_protected "Determining whether a response is CORB-protected"
520525
*/
521526
public function add_xcontent_type_options()
522527
{
528+
try {
529+
$oConfig = utils::GetConfig();
530+
} catch (ConfigException|CoreException $e) {
531+
$oConfig = null;
532+
}
533+
if (is_null($oConfig)) {
534+
$bSendXContentTypeOptionsHttpHeader = true;
535+
} else {
536+
$bSendXContentTypeOptionsHttpHeader = $oConfig->Get('security.enable_header_xcontent_type_options');
537+
}
538+
539+
if ($bSendXContentTypeOptionsHttpHeader === false) {
540+
return;
541+
}
542+
523543
$this->add_header('X-Content-Type-Options: nosniff');
524544
}
525545

application/xmlpage.class.inc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ function __construct($s_title, $bPassThrough = false)
4848
$this->add_header("Content-location: export.xml");
4949
}
5050

51+
/**
52+
* Disabling sending the header so that resource won't be blocked by CORB. See parent method documentation.
53+
* @return void
54+
* @since 2.7.10 3.0.4 3.1.2 3.2.0 N°4368 method creation
55+
*/
56+
public function add_xcontent_type_options()
57+
{
58+
// Nothing to do !
59+
}
60+
5161
public function output()
5262
{
5363
if (!$this->m_bPassThrough)

core/config.class.inc.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,14 @@ class Config
13201320
'source_of_value' => '',
13211321
'show_in_conf_sample' => false,
13221322
],
1323+
'security.enable_header_xcontent_type_options' => [
1324+
'type' => 'bool',
1325+
'description' => 'If set to false, iTop will stop sending the X-Content-Type-Options HTTP header. This header could trigger CORB protection on certain resources (JSON, XML, HTML, text) therefore blocking them.',
1326+
'default' => true,
1327+
'value' => '',
1328+
'source_of_value' => '',
1329+
'show_in_conf_sample' => false,
1330+
],
13231331
'behind_reverse_proxy' => [
13241332
'type' => 'bool',
13251333
'description' => 'If true, then proxies custom header (X-Forwarded-*) are taken into account. Use only if the webserver is not publicly accessible (reachable only by the reverse proxy)',

0 commit comments

Comments
 (0)