Skip to content

Commit 53c02d6

Browse files
committed
fix(Http): Only allow valid HTTP status code values via template
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 384f3c0 commit 53c02d6

20 files changed

+43
-41
lines changed

lib/private/AppFramework/OCS/BaseResponse.php

+2-2
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

+3-3
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

+3-3
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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 */

lib/public/AppFramework/Http/JSONResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
/**
3434
* A renderer for JSON calls
3535
* @since 6.0.0
36-
* @template S of int
36+
* @template S of Http::STATUS_*
3737
* @template-covariant T of null|string|int|float|bool|array|\stdClass|\JsonSerializable
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
class JSONResponse extends Response {
4242
/**

lib/public/AppFramework/Http/NotFoundResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
/**
3131
* A generic 404 response showing an 404 error page as well to the end-user
3232
* @since 8.1.0
33-
* @template S of int
33+
* @template S of Http::STATUS_*
3434
* @template H of array<string, mixed>
35-
* @template-extends TemplateResponse<int, array<string, mixed>>
35+
* @template-extends TemplateResponse<Http::STATUS_*, array<string, mixed>>
3636
*/
3737
class NotFoundResponse extends TemplateResponse {
3838
/**

lib/public/AppFramework/Http/RedirectResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
/**
3232
* Redirects to a different URL
3333
* @since 7.0.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 RedirectResponse extends Response {
3939
private $redirectURL;

lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
*
3636
* @since 16.0.0
3737
* @deprecated 23.0.0 Use RedirectResponse() with IURLGenerator::linkToDefaultPageUrl() instead
38-
* @template S of int
38+
* @template S of Http::STATUS_*
3939
* @template H of array<string, mixed>
40-
* @template-extends RedirectResponse<int, array<string, mixed>>
40+
* @template-extends RedirectResponse<Http::STATUS_*, array<string, mixed>>
4141
*/
4242
class RedirectToDefaultAppResponse extends RedirectResponse {
4343
/**

lib/public/AppFramework/Http/Response.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
* It handles headers, HTTP status code, last modified and ETag.
4444
* @since 6.0.0
45-
* @template S of int
45+
* @template S of Http::STATUS_*
4646
* @template H of array<string, mixed>
4747
*/
4848
class Response {

lib/public/AppFramework/Http/StandaloneTemplateResponse.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@
2626
*/
2727
namespace OCP\AppFramework\Http;
2828

29+
use OCP\AppFramework\Http;
30+
2931
/**
3032
* A template response that does not emit the loadAdditionalScripts events.
3133
*
3234
* This is useful for pages that are authenticated but do not yet show the
3335
* full nextcloud UI. Like the 2FA page, or the grant page in the login flow.
3436
*
3537
* @since 16.0.0
36-
* @template S of int
38+
* @template S of Http::STATUS_*
3739
* @template H of array<string, mixed>
38-
* @template-extends TemplateResponse<int, array<string, mixed>>
40+
* @template-extends TemplateResponse<Http::STATUS_*, array<string, mixed>>
3941
*/
4042
class StandaloneTemplateResponse extends TemplateResponse {
4143
}

lib/public/AppFramework/Http/StreamResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
* Class StreamResponse
3434
*
3535
* @since 8.1.0
36-
* @template S of int
36+
* @template S of Http::STATUS_*
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 StreamResponse extends Response implements ICallbackResponse {
4141
/** @var string */

lib/public/AppFramework/Http/Template/PublicTemplateResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
*
3535
* @since 14.0.0
3636
* @template H of array<string, mixed>
37-
* @template S of int
38-
* @template-extends TemplateResponse<int, array<string, mixed>>
37+
* @template S of Http::STATUS_*
38+
* @template-extends TemplateResponse<Http::STATUS_*, array<string, mixed>>
3939
*/
4040
class PublicTemplateResponse extends TemplateResponse {
4141
private $headerTitle = '';

lib/public/AppFramework/Http/TemplateResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
* Response for a normal template
3636
* @since 6.0.0
3737
*
38-
* @template S of int
38+
* @template S of Http::STATUS_*
3939
* @template H of array<string, mixed>
40-
* @template-extends Response<int, array<string, mixed>>
40+
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
4141
*/
4242
class TemplateResponse extends Response {
4343
/**

lib/public/AppFramework/Http/TextPlainResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
/**
3232
* A renderer for text responses
3333
* @since 22.0.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 TextPlainResponse extends Response {
3939
/** @var string */

lib/public/AppFramework/Http/TooManyRequestsResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
/**
3333
* A generic 429 response showing an 404 error page as well to the end-user
3434
* @since 19.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 TooManyRequestsResponse extends Response {
4040
/**

lib/public/AppFramework/Http/ZipResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
* Public library to send several files in one zip archive.
3838
*
3939
* @since 15.0.0
40-
* @template S of int
40+
* @template S of Http::STATUS_*
4141
* @template H of array<string, mixed>
42-
* @template-extends Response<int, array<string, mixed>>
42+
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
4343
*/
4444
class ZipResponse extends Response implements ICallbackResponse {
4545
/** @var array{internalName: string, resource: resource, size: int, time: int}[] Files to be added to the zip response */

0 commit comments

Comments
 (0)