Skip to content

Commit

Permalink
Merge pull request #24706 from nextcloud/bugfix/noid/log-error-on-set…
Browse files Browse the repository at this point in the history
…ting-custom-headers-on-no-content-responses

Log an error when setting a custom header on "Not Modified" responses
  • Loading branch information
rullzer committed Dec 16, 2020
2 parents 4c133f2 + 329ffa2 commit 7a77493
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/public/AppFramework/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

use OCP\AppFramework\Http;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use Psr\Log\LoggerInterface;

/**
* Base class for responses. Also used to just send headers.
Expand Down Expand Up @@ -203,6 +205,18 @@ public function addHeader($name, $value) {
// to be able to reliably check for security
// headers

if ($this->status === Http::STATUS_NOT_MODIFIED
&& stripos($name, 'x-') === 0) {
/** @var IConfig $config */
$config = \OC::$server->get(IConfig::class);

if ($config->getSystemValueBool('debug', false)) {
\OC::$server->get(LoggerInterface::class)->error(
'Setting a custom header on a 204 or 304 is not supported'
);
}
}

if (is_null($value)) {
unset($this->headers[$name]);
} else {
Expand Down

0 comments on commit 7a77493

Please sign in to comment.