Skip to content

Commit

Permalink
fix(Http): Only allow valid HTTP status code values via template
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>

[skip ci]
  • Loading branch information
provokateurin authored and backportbot[bot] committed Jan 8, 2025
1 parent cc6cfda commit e960a69
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 41 deletions.
4 changes: 2 additions & 2 deletions lib/private/AppFramework/OCS/BaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@

/**
* @psalm-import-type DataResponseType from DataResponse
* @template S of int
* @template S of Http::STATUS_*
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
abstract class BaseResponse extends Response {
/** @var array */
Expand Down
6 changes: 3 additions & 3 deletions lib/private/AppFramework/OCS/V1Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@

/**
* @psalm-import-type DataResponseType from DataResponse
* @template S of int
* @template S of Http::STATUS_*
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
* @template-extends BaseResponse<int, DataResponseType, array<string, mixed>>
* @template-extends BaseResponse<Http::STATUS_*, DataResponseType, array<string, mixed>>
*/
class V1Response extends BaseResponse {
/**
* The V1 endpoint has very limited http status codes basically everything
* is status 200 except 401
*
* @return int
* @return Http::STATUS_*
*/
public function getStatus() {
$status = parent::getStatus();
Expand Down
6 changes: 3 additions & 3 deletions lib/private/AppFramework/OCS/V2Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@

/**
* @psalm-import-type DataResponseType from DataResponse
* @template S of int
* @template S of Http::STATUS_*
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
* @template-extends BaseResponse<int, DataResponseType, array<string, mixed>>
* @template-extends BaseResponse<Http::STATUS_*, DataResponseType, array<string, mixed>>
*/
class V2Response extends BaseResponse {
/**
* The V2 endpoint just passes on status codes.
* Of course we have to map the OCS specific codes to proper HTTP status codes
*
* @return int
* @return Http::STATUS_*
*/
public function getStatus() {
$status = parent::getStatus();
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/DataDisplayResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
* Class DataDisplayResponse
*
* @since 8.1.0
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class DataDisplayResponse extends Response {
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/DataDownloadResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
* Class DataDownloadResponse
*
* @since 8.0.0
* @template S of int
* @template S of Http::STATUS_*
* @template C of string
* @template H of array<string, mixed>
* @template-extends DownloadResponse<int, string, array<string, mixed>>
* @template-extends DownloadResponse<Http::STATUS_*, string, array<string, mixed>>
*/
class DataDownloadResponse extends DownloadResponse {
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/DataResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
* for responders to transform
* @since 8.0.0
* @psalm-type DataResponseType = array|int|float|string|bool|object|null|\stdClass|\JsonSerializable
* @template S of int
* @template S of Http::STATUS_*
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class DataResponse extends Response {
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/DownloadResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
/**
* Prompts the user to download the a file
* @since 7.0.0
* @template S of int
* @template S of Http::STATUS_*
* @template C of string
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class DownloadResponse extends Response {
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/FileDisplayResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
* Class FileDisplayResponse
*
* @since 11.0.0
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class FileDisplayResponse extends Response implements ICallbackResponse {
/** @var File|ISimpleFile */
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/JSONResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
/**
* A renderer for JSON calls
* @since 6.0.0
* @template S of int
* @template S of Http::STATUS_*
* @template-covariant T of null|string|int|float|bool|array|\stdClass|\JsonSerializable
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class JSONResponse extends Response {
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/NotFoundResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
/**
* A generic 404 response showing an 404 error page as well to the end-user
* @since 8.1.0
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends TemplateResponse<int, array<string, mixed>>
* @template-extends TemplateResponse<Http::STATUS_*, array<string, mixed>>
*/
class NotFoundResponse extends TemplateResponse {
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
/**
* Redirects to a different URL
* @since 7.0.0
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class RedirectResponse extends Response {
private $redirectURL;
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
*
* @since 16.0.0
* @deprecated 23.0.0 Use RedirectResponse() with IURLGenerator::linkToDefaultPageUrl() instead
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends RedirectResponse<int, array<string, mixed>>
* @template-extends RedirectResponse<Http::STATUS_*, array<string, mixed>>
*/
class RedirectToDefaultAppResponse extends RedirectResponse {
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/public/AppFramework/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*
* It handles headers, HTTP status code, last modified and ETag.
* @since 6.0.0
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
*/
class Response {
Expand Down
6 changes: 4 additions & 2 deletions lib/public/AppFramework/Http/StandaloneTemplateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@
*/
namespace OCP\AppFramework\Http;

use OCP\AppFramework\Http;

/**
* A template response that does not emit the loadAdditionalScripts events.
*
* This is useful for pages that are authenticated but do not yet show the
* full nextcloud UI. Like the 2FA page, or the grant page in the login flow.
*
* @since 16.0.0
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends TemplateResponse<int, array<string, mixed>>
* @template-extends TemplateResponse<Http::STATUS_*, array<string, mixed>>
*/
class StandaloneTemplateResponse extends TemplateResponse {
}
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/StreamResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
* Class StreamResponse
*
* @since 8.1.0
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class StreamResponse extends Response implements ICallbackResponse {
/** @var string */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
*
* @since 14.0.0
* @template H of array<string, mixed>
* @template S of int
* @template-extends TemplateResponse<int, array<string, mixed>>
* @template S of Http::STATUS_*
* @template-extends TemplateResponse<Http::STATUS_*, array<string, mixed>>
*/
class PublicTemplateResponse extends TemplateResponse {
private $headerTitle = '';
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/TemplateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
* Response for a normal template
* @since 6.0.0
*
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class TemplateResponse extends Response {
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/TextPlainResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
/**
* A renderer for text responses
* @since 22.0.0
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class TextPlainResponse extends Response {
/** @var string */
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/TooManyRequestsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
/**
* A generic 429 response showing an 404 error page as well to the end-user
* @since 19.0.0
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class TooManyRequestsResponse extends Response {
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/ZipResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
* Public library to send several files in one zip archive.
*
* @since 15.0.0
* @template S of int
* @template S of Http::STATUS_*
* @template H of array<string, mixed>
* @template-extends Response<int, array<string, mixed>>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class ZipResponse extends Response implements ICallbackResponse {
/** @var array{internalName: string, resource: resource, size: int, time: int}[] Files to be added to the zip response */
Expand Down

0 comments on commit e960a69

Please sign in to comment.