Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden user_status API #49797

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

provokateurin
Copy link
Member

Summary

Issues found with #47825

Checklist

@provokateurin provokateurin added this to the Nextcloud 31 milestone Dec 11, 2024
@provokateurin provokateurin requested review from nickvergessen, a team, ArtificialOwl, skjnldsv and come-nc and removed request for a team December 11, 2024 09:26
@@ -46,7 +46,7 @@ public function __construct(
* Find statuses of users
*
* @param int|null $limit Maximum number of statuses to find
* @param int|null $offset Offset for finding statuses
* @param non-negative-int|null $offset Offset for finding statuses
Copy link
Contributor

Choose a reason for hiding this comment

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

I’m curious, I guess a lot of places in the API expects a positive int and type it as int, why change this one in particular?

Copy link
Member Author

Choose a reason for hiding this comment

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

I found this one because the fuzzer used -1 which triggered an unexpected error.
I didn't search for these problems, but the underlying typing could be improved to find more of them.

@@ -36,7 +36,7 @@ class UserStatusController extends OCSController {
public function __construct(
string $appName,
IRequest $request,
private string $userId,
private ?string $userId,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any chance to explain psalm and friends that such a property cannot be null when calling an authenticated method?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that is possible and even then we'd still have a problem because the DI will fail when you don't send the authentication (regardless if the method needs it or not).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah we have this error regularly in our logs from various apps.
I'm just always drawn apart how to handle it as allowing null in the constructor basically means you have to handle it manually in each method or have psalm complaining there

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we could be handling it more gracefully and letting controllers specify it as non-null if they know it has to be there for every method. Currently if the DI fails weird things happen, for example for a DELETE request it just returns 200 (which is how I found this with the fuzzer).

@@ -22,7 +22,7 @@
* icon: string,
* message: string,
* clearAt: ?UserStatusClearAt,
* visible: ?bool,
* visible?: bool,
Copy link
Member

Choose a reason for hiding this comment

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

I want to check this on Monday, so please don't merge before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants