Skip to content

Commit

Permalink
Log an error when setting a custom header on "Not Modified" responses
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Dec 15, 2020
1 parent 8506d08 commit 329ffa2
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 329ffa2

Please sign in to comment.