Skip to content

Commit e390954

Browse files
committed
fix: Add 403 response for admin pages
Signed-off-by: provokateurin <[email protected]>
1 parent 65eab06 commit e390954

File tree

7 files changed

+3865
-150
lines changed

7 files changed

+3865
-150
lines changed

generate-spec.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@
573573
$isCORS,
574574
$isNoCSRFRequired,
575575
$isPublic,
576+
$isAdmin,
576577
);
577578
}
578579

@@ -757,26 +758,35 @@
757758
// Add empty authentication, meaning that it's optional. We can't know if there is a difference in behaviour for authenticated vs. unauthenticated access on public pages (e.g. capabilities)
758759
$security[] = new stdClass();
759760
} else {
760-
$mergedResponses[401] ??= [
761-
'description' => 'Current user is not logged in',
762-
'content' => [
763-
'application/json' => [
764-
'schema' => $route->isOCS
765-
? Helpers::wrapOCSResponse(new stdClass())
766-
: [
767-
'type' => 'object',
768-
'required' => [
769-
'message',
770-
],
771-
'properties' => [
772-
'message' => [
773-
'type' => 'string',
774-
],
761+
$content = [
762+
'application/json' => [
763+
'schema' => $route->isOCS
764+
? Helpers::wrapOCSResponse(new stdClass())
765+
: [
766+
'type' => 'object',
767+
'required' => [
768+
'message',
769+
],
770+
'properties' => [
771+
'message' => [
772+
'type' => 'string',
775773
],
776774
],
777-
],
775+
],
778776
],
779777
];
778+
779+
$mergedResponses[401] ??= [
780+
'description' => 'Current user is not logged in',
781+
'content' => $content,
782+
];
783+
784+
if ($route->isAdmin) {
785+
$mergedResponses[403] ??= [
786+
'description' => 'Logged in account must be an admin',
787+
'content' => $content,
788+
];
789+
}
780790
}
781791
if (!$route->isCORS) {
782792
// Bearer auth is not allowed on CORS routes

src/Route.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function __construct(
2121
public bool $isCORS,
2222
public bool $isNoCSRFRequired,
2323
public bool $isPublic,
24+
public bool $isAdmin,
2425
) {
2526
}
2627

0 commit comments

Comments
 (0)