Skip to content

Commit 0d86fd9

Browse files
committed
fix: IRequest::getHeader() can return null which needs to be checked
1 parent fcafbcf commit 0d86fd9

File tree

9 files changed

+17
-15
lines changed

9 files changed

+17
-15
lines changed

apps/dav/lib/Connector/PublicAuth.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function validateUserPass($username, $password) {
103103
} elseif ($this->shareManager->checkPassword($share, $password)) {
104104
return true;
105105
} else {
106-
if (\in_array('XMLHttpRequest', \explode(',', $this->request->getHeader('X-Requested-With')))) {
106+
if (\in_array('XMLHttpRequest', \explode(',', $this->request->getHeader('X-Requested-With') ?? ''), true)) {
107107
// do not re-authenticate over ajax, use dummy auth name to prevent browser popup
108108
\http_response_code(401);
109109
\header('WWW-Authenticate', 'DummyBasic realm="' . $this->realm . '"');

apps/federatedfilesharing/lib/Panels/GeneralPersonalPanel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getSectionID() {
6464

6565
public function getPanel() {
6666
$isIE8 = false;
67-
\preg_match('/MSIE (.*?);/', $this->request->getHeader('User-Agent'), $matches);
67+
\preg_match('/MSIE (.*?);/', $this->request->getHeader('User-Agent') ?? '', $matches);
6868
if (\count($matches) > 0 && $matches[1] <= 9) {
6969
$isIE8 = true;
7070
}

apps/files/ajax/download.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
* Http range requests support
6868
*/
6969
if (isset($_SERVER['HTTP_RANGE'])) {
70-
$server_params['range'] = \OC::$server->getRequest()->getHeader('Range');
70+
$server_params['range'] = \OC::$server->getRequest()->getHeader('Range') ?? '';
7171
}
7272

7373
OC_Files::get($dir, $files_list, $server_params);

apps/files_sharing/lib/Controllers/ShareController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,9 @@ public function downloadShare($token, $files = null, $path = '', $downloadStartS
543543
/**
544544
* Http range requests support
545545
*/
546-
if (isset($_SERVER['HTTP_RANGE'])) {
547-
$server_params['range'] = $this->request->getHeader('Range');
546+
$range_header = $this->request->getHeader('Range');
547+
if ($range_header !== null) {
548+
$server_params['range'] = $range_header;
548549
}
549550

550551
// download selected files

lib/private/AppFramework/Http/Dispatcher.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private function executeController($controller, $methodName) {
153153
(
154154
$this->request->method === 'GET' ||
155155
\strpos(
156-
$this->request->getHeader('Content-Type'),
156+
$this->request->getHeader('Content-Type') ?? '',
157157
'application/x-www-form-urlencoded'
158158
) !== false
159159
)
@@ -175,7 +175,7 @@ private function executeController($controller, $methodName) {
175175

176176
// if none is given try the first Accept header
177177
if ($format === null) {
178-
$headers = $this->request->getHeader('Accept');
178+
$headers = $this->request->getHeader('Accept') ?? '';
179179
$format = $controller->getResponderByHTTPHeader($headers);
180180
}
181181

lib/private/AppFramework/Http/Request.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public function __unset($id) {
292292
* @param string $name
293293
* @return string|null
294294
*/
295-
public function getHeader($name) {
295+
public function getHeader(string $name): ?string {
296296
$name = \strtoupper(\str_replace(['-'], ['_'], $name));
297297
if (isset($this->server['HTTP_' . $name])) {
298298
return $this->server['HTTP_' . $name];
@@ -391,8 +391,8 @@ protected function getContent() {
391391
if ($this->method === 'PUT'
392392
&& $this->getHeader('Content-Length') !== 0
393393
&& $this->getHeader('Content-Length') !== null
394-
&& \strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false
395-
&& \strpos($this->getHeader('Content-Type'), 'application/json') === false
394+
&& \strpos($this->getHeader('Content-Type') ?? '', 'application/x-www-form-urlencoded') === false
395+
&& \strpos($this->getHeader('Content-Type') ?? '', 'application/json') === false
396396
) {
397397
if ($this->content === false) {
398398
throw new \LogicException(
@@ -431,7 +431,7 @@ protected function decodeContent() {
431431
// or post correctly
432432
} elseif ($this->method !== 'GET'
433433
&& $this->method !== 'POST'
434-
&& \strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') !== false) {
434+
&& \strpos($this->getHeader('Content-Type') ?? '', 'application/x-www-form-urlencoded') !== false) {
435435
\parse_str(\file_get_contents($this->inputStream), $params);
436436
if (\is_array($params)) {
437437
$this->items['params'] = $params;

lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ public function afterException($controller, $methodName, \Exception $exception)
209209
}
210210

211211
if ($exception instanceof SecurityException) {
212-
if ($this->request->getHeader('Accept') !== '*/*'
213-
&& \stripos($this->request->getHeader('Accept'), 'html') === false
212+
$accept_header = $this->request->getHeader('Accept') ?? '';
213+
if ($accept_header !== '*/*'
214+
&& \stripos($accept_header, 'html') === false
214215
) {
215216
$response = new JSONResponse(
216217
['message' => $exception->getMessage()],

lib/public/IRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ interface IRequest {
6767
* @return string|null
6868
* @since 6.0.0
6969
*/
70-
public function getHeader($name);
70+
public function getHeader(string $name): ?string;
7171

7272
/**
7373
* Lets you access post and get parameters by the index

remote.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class RemoteException extends Exception {
4646
function handleException($e) {
4747
$request = \OC::$server->getRequest();
4848
// in case the request content type is text/xml - we assume it's a WebDAV request
49-
$isXmlContentType = \strpos($request->getHeader('Content-Type'), 'text/xml');
49+
$isXmlContentType = \strpos($request->getHeader('Content-Type') ?? '', 'text/xml');
5050
if ($isXmlContentType === 0) {
5151
// fire up a simple server to properly process the exception
5252
$server = new Server();

0 commit comments

Comments
 (0)