Skip to content

Conversation

@provokateurin
Copy link
Member

The OCSMiddleware handles the ?format=json query parameter and Accept: application/json request header, but ocs/v1.php uses ApiHelper::respond which only handles ?format=json so far.

@nickvergessen
Copy link
Member

While a good and nice fix, I fear this could break current clients working around the problem since years. So I'd suggest to delay it until after the branch off?

@provokateurin
Copy link
Member Author

this could break current clients working around the problem since years

So the issue is known and was manually handled by some clients? 🙈

I'm fine with waiting, I just found this while fuzzing the API and it has been broken this way since forever, so fixing it is not that urgent.

@come-nc
Copy link
Contributor

come-nc commented Aug 26, 2025

It would make sense to add a method to IRequest to get requested format, maybe?

…ype the same way everywhere

Signed-off-by: provokateurin <[email protected]>
@provokateurin provokateurin force-pushed the fix/ocs/accept-header branch from 714a976 to aab11d3 Compare August 26, 2025 07:53
@provokateurin provokateurin changed the title fix(OCS): Honor Accept header in ApiHelper fix(OCS): Add IRequest::getFormat to determine the response Content-Type the same way everywhere Aug 26, 2025
@provokateurin
Copy link
Member Author

I have too many questions about the code I saw 🙈

@provokateurin provokateurin requested a review from susnux August 26, 2025 07:54
@provokateurin provokateurin added the pending documentation This pull request needs an associated documentation update label Aug 26, 2025
return \is_array($trustedProxies) && $this->isTrustedProxy($trustedProxies, $remoteAddress);
}

public function getFormat(): ?string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@provokateurin provokateurin merged commit a1709f5 into master Aug 28, 2025
198 checks passed
@provokateurin provokateurin deleted the fix/ocs/accept-header branch August 28, 2025 12:03
@nextcloud-bot nextcloud-bot mentioned this pull request Aug 28, 2025
@skjnldsv skjnldsv modified the milestones: Nextcloud 33, Nextcloud 32 Oct 2, 2025
$header = strtolower(trim($header));

if (str_starts_with($header, $prefix)) {
return substr($header, strlen($prefix));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opposed to Controller::getResponderByHTTPHeader() which was used before, this here no longer checks if there is a responder registered and does not fall back to the default type correctly.
E.g. When you create a share for a file that can not have a preview (e.g. PDF without PDF being enabled), instead of having a proper 404, the response now is:

Technische Details

    Entfernte Adresse: ::1
    Anfragekennung: 3RuRvo3TEr52XxYi3pq6
    Typ: DomainException
    Code: 0
    Nachricht: No responder registered for format xhtml+xml!
    Datei: /home/nickv/Nextcloud/33/server/lib/public/AppFramework/Controller.php
    Zeile: 139


Trace

#0 /home/nickv/Nextcloud/33/server/lib/private/AppFramework/Http/Dispatcher.php(227): OCP\AppFramework\Controller->buildResponse(Object(OCP\AppFramework\Http\DataResponse), '...')
#1 /home/nickv/Nextcloud/33/server/lib/private/AppFramework/Http/Dispatcher.php(118): OC\AppFramework\Http\Dispatcher->executeController(Object(OCA\Files_Sharing\Controller\PublicPreviewController), '...')
#2 /home/nickv/Nextcloud/33/server/lib/private/AppFramework/App.php(153): OC\AppFramework\Http\Dispatcher->dispatch(Object(OCA\Files_Sharing\Controller\PublicPreviewController), '...')
#3 /home/nickv/Nextcloud/33/server/lib/private/Route/Router.php(321): OC\AppFramework\App::main('...', '...', Object(OC\AppFramework\DependencyInjection\DIContainer), Array)
#4 /home/nickv/Nextcloud/33/server/lib/base.php(1096): OC\Route\Router->match('...')
#5 /home/nickv/Nextcloud/33/server/index.php(25): OC::handleRequest()
#6 {main}

This works properly until Nextcloud 31.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews bug pending documentation This pull request needs an associated documentation update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants