From 8de5608976dc8a73a400267601acb4c8e127de5a Mon Sep 17 00:00:00 2001 From: winter Date: Thu, 16 Jan 2025 18:33:18 +0000 Subject: note privacy and summary stuff --- routes/note.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'routes/note.php') diff --git a/routes/note.php b/routes/note.php index 8a6c9da..f1d6650 100644 --- a/routes/note.php +++ b/routes/note.php @@ -1,8 +1,12 @@ mount('/note/:id', function (array $args) { @@ -16,6 +20,14 @@ Router::getInstance()->mount('/note/:id', function (array $args) { if (isset($_SERVER['HTTP_ACCEPT']) && str_contains($_SERVER['HTTP_ACCEPT'], 'text/html')) { throw new TemporaryRedirect('/@/' . $note->author->handle . "/note/$note->id"); } + // if it's not public we need to check whether the requesting instance is allowed to see it + if ($note->privacy->scope != NotePrivacyScope::PUBLIC ) { + $instance = Instance::requireByRequestHeaders(); + $allowed = $note->getRelevantServers(); + if (!in_array($instance, $allowed)) { + throw new Forbidden(); + } + } json_response($note); }); @@ -28,5 +40,12 @@ Router::getInstance()->mount('/@/:handle/note/:id', function (array $args) { if ($args['handle'] != $note->author->getFullHandle()) { throw new TemporaryRedirect('/@/' . $note->author->getFullHandle() . "/note/$note->id"); } + // check the current user is allowed to see it + if ($note->privacy->scope != NotePrivacyScope::PUBLIC ) { + $user = UserAccount::requireByCurrentSession(); + if (!in_array($user->actor, $note->getRelevantActors())) { + throw new Forbidden(); + } + } render_template('thread_page', ['note' => $note]); }); -- cgit v1.3