Skip to content

Commit a89e6f1

Browse files
authored
Merge pull request #50087 from nextcloud/backport/49882/stable28
[stable28] fix(Http): Only allow valid HTTP status code values via template
2 parents f47653b + 9dc6af6 commit a89e6f1

22 files changed

+56
-51
lines changed

apps/settings/lib/Controller/LogSettingsController.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ public function __construct(string $appName, IRequest $request, Log $logger) {
4848
*
4949
* @NoCSRFRequired
5050
*
51-
* @psalm-suppress MoreSpecificReturnType The value of Content-Disposition is not relevant
52-
* @psalm-suppress LessSpecificReturnStatement The value of Content-Disposition is not relevant
53-
* @return StreamResponse<Http::STATUS_OK, array{Content-Type: 'application/octet-stream', 'Content-Disposition': string}>
51+
* @return StreamResponse<Http::STATUS_OK, array{Content-Type: 'application/octet-stream', 'Content-Disposition': 'attachment; filename="nextcloud.log"'}>
5452
*
5553
* 200: Logfile returned
5654
*/
5755
public function download() {
5856
if (!$this->log instanceof Log) {
5957
throw new \UnexpectedValueException('Log file not available');
6058
}
61-
$resp = new StreamResponse($this->log->getLogPath());
62-
$resp->setHeaders([
63-
'Content-Type' => 'application/octet-stream',
64-
'Content-Disposition' => 'attachment; filename="nextcloud.log"',
65-
]);
66-
return $resp;
59+
return new StreamResponse(
60+
$this->log->getLogPath(),
61+
Http::STATUS_OK,
62+
[
63+
'Content-Type' => 'application/octet-stream',
64+
'Content-Disposition' => 'attachment; filename="nextcloud.log"',
65+
],
66+
);
6767
}
6868
}

apps/settings/openapi.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
"headers": {
4545
"Content-Disposition": {
4646
"schema": {
47-
"type": "string"
47+
"type": "string",
48+
"enum": [
49+
"attachment; filename=\"nextcloud.log\""
50+
]
4851
}
4952
}
5053
},

lib/private/AppFramework/OCS/BaseResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333

3434
/**
3535
* @psalm-import-type DataResponseType from DataResponse
36-
* @template S of int
36+
* @template S of Http::STATUS_*
3737
* @template-covariant T of DataResponseType
3838
* @template H of array<string, mixed>
39-
* @template-extends Response<int, array<string, mixed>>
39+
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
4040
*/
4141
abstract class BaseResponse extends Response {
4242
/** @var array */

lib/private/AppFramework/OCS/V1Response.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131

3232
/**
3333
* @psalm-import-type DataResponseType from DataResponse
34-
* @template S of int
34+
* @template S of Http::STATUS_*
3535
* @template-covariant T of DataResponseType
3636
* @template H of array<string, mixed>
37-
* @template-extends BaseResponse<int, DataResponseType, array<string, mixed>>
37+
* @template-extends BaseResponse<Http::STATUS_*, DataResponseType, array<string, mixed>>
3838
*/
3939
class V1Response extends BaseResponse {
4040
/**
4141
* The V1 endpoint has very limited http status codes basically everything
4242
* is status 200 except 401
4343
*
44-
* @return int
44+
* @return Http::STATUS_*
4545
*/
4646
public function getStatus() {
4747
$status = parent::getStatus();

lib/private/AppFramework/OCS/V2Response.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030

3131
/**
3232
* @psalm-import-type DataResponseType from DataResponse
33-
* @template S of int
33+
* @template S of Http::STATUS_*
3434
* @template-covariant T of DataResponseType
3535
* @template H of array<string, mixed>
36-
* @template-extends BaseResponse<int, DataResponseType, array<string, mixed>>
36+
* @template-extends BaseResponse<Http::STATUS_*, DataResponseType, array<string, mixed>>
3737
*/
3838
class V2Response extends BaseResponse {
3939
/**
4040
* The V2 endpoint just passes on status codes.
4141
* Of course we have to map the OCS specific codes to proper HTTP status codes
4242
*
43-
* @return int
43+
* @return Http::STATUS_*
4444
*/
4545
public function getStatus() {
4646
$status = parent::getStatus();

lib/public/AppFramework/Http/DataDisplayResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
* Class DataDisplayResponse
3232
*
3333
* @since 8.1.0
34-
* @template S of int
34+
* @template S of Http::STATUS_*
3535
* @template H of array<string, mixed>
36-
* @template-extends Response<int, array<string, mixed>>
36+
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
3737
*/
3838
class DataDisplayResponse extends Response {
3939
/**

lib/public/AppFramework/Http/DataDownloadResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
* Class DataDownloadResponse
3131
*
3232
* @since 8.0.0
33-
* @template S of int
33+
* @template S of Http::STATUS_*
3434
* @template C of string
3535
* @template H of array<string, mixed>
36-
* @template-extends DownloadResponse<int, string, array<string, mixed>>
36+
* @template-extends DownloadResponse<Http::STATUS_*, string, array<string, mixed>>
3737
*/
3838
class DataDownloadResponse extends DownloadResponse {
3939
/**

lib/public/AppFramework/Http/DataResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
* for responders to transform
3333
* @since 8.0.0
3434
* @psalm-type DataResponseType = array|int|float|string|bool|object|null|\stdClass|\JsonSerializable
35-
* @template S of int
35+
* @template S of Http::STATUS_*
3636
* @template-covariant T of DataResponseType
3737
* @template H of array<string, mixed>
38-
* @template-extends Response<int, array<string, mixed>>
38+
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
3939
*/
4040
class DataResponse extends Response {
4141
/**

lib/public/AppFramework/Http/DownloadResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
/**
3232
* Prompts the user to download the a file
3333
* @since 7.0.0
34-
* @template S of int
34+
* @template S of Http::STATUS_*
3535
* @template C of string
3636
* @template H of array<string, mixed>
37-
* @template-extends Response<int, array<string, mixed>>
37+
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
3838
*/
3939
class DownloadResponse extends Response {
4040
/**

lib/public/AppFramework/Http/FileDisplayResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
* Class FileDisplayResponse
3333
*
3434
* @since 11.0.0
35-
* @template S of int
35+
* @template S of Http::STATUS_*
3636
* @template H of array<string, mixed>
37-
* @template-extends Response<int, array<string, mixed>>
37+
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
3838
*/
3939
class FileDisplayResponse extends Response implements ICallbackResponse {
4040
/** @var File|ISimpleFile */

0 commit comments

Comments
 (0)