Skip to content

Conversation

@nc-fkl
Copy link
Contributor

@nc-fkl nc-fkl commented Mar 12, 2024

  • Resolves: #

Summary

When doing a request via app_api the rate limiting prevents more than 5 requests per 2 minutes, with checking if the app_api session exsists we bypass the rate limiting for app_api requests.

Checklist

  • Resolves: #

@nc-fkl
Copy link
Contributor Author

nc-fkl commented Mar 12, 2024

/backport to stable28

@nc-fkl nc-fkl requested a review from bigcat88 March 12, 2024 10:24
@bigcat88 bigcat88 requested a review from nickvergessen March 12, 2024 10:25
Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

It's not okay to generally disable ratelimit like this.

Can you maybe point out which endpoint is a problem?

Copy link
Contributor

@bigcat88 bigcat88 left a comment

Choose a reason for hiding this comment

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

Please, make squash commit with force push with correct message for "Block unconventional commits" check.

Added logic in this PR for me looks good, requests from ExApps should always bypass any rate limits.

@nickvergessen
Copy link
Member

requests from ExApps should always bypass any rate limits.

Why is that? We have several API endpoints which have a rate limit also for logged in users.

@nc-fkl
Copy link
Contributor Author

nc-fkl commented Mar 12, 2024

requests from ExApps should always bypass any rate limits.

Why is that? We have several API endpoints which have a rate limit also for logged in users.

Hi,

we need to utilize:
/ocs/v2.php/textprocessing/schedule
multiple times in a short period of time, but every >= 6th request is failing because of
429 too many requests
which is coming from the rate-limiting.

As a example we want to utilize some AI features for summarizing a long chatlog. We need to split the chatlog into multiple chunks (lets say 10 chunks) and for each we need to do a request to the /ocs/v2.php/textprocessing/schedule endpoint.
For the first 5 its going well but then the rate limiting is blocking us to process the other requests also, therefore and also for other app_api requests in the future, we need to bypass the rate limiting for app_api requests.

@bigcat88
Copy link
Contributor

bigcat88 commented Mar 12, 2024

Why is that? We have several API endpoints which have a rate limit also for logged in users.

We need this for the Summurize bot (which was supposed to be released a week(?) ago..) calling text-processing endpoints to schedule a summarization task.
The bot does not have a user context; it is called from the background task.
As a result, it falls into the Anonymous rate limit (5 requests).
But the user rate limit is not enough for us too(20 requests), if the number of chats is more than 20, then the user rate limit will also block..

@nickvergessen
Copy link
Member

Then let's either bump or remove the user limit from that endpoint for now.
But removing rate limit completely is not an option!

@nickvergessen
Copy link
Member

Or additionally we add a AppAPIRateLimit attribute additionally which is checked in case the session flag is there and we fall back to the UserRateLimit if it's not set.

@bigcat88
Copy link
Contributor

Then let's either bump or remove the user limit from that endpoint for now.

value of rate limit will depend on size of the Nextcloud instance, we can not know the value.

removing rate limit form that endpoint completely will allow to easy ddos cloud without even an account, as that endpoint allows anonymous access already..

Or additionally we add a AppAPIRateLimit attribute additionally which is checked in case the session flag is there and we fall back to the UserRateLimit if it's not set.

Good proposal

@nickvergessen
Copy link
Member

removing rate limit form that endpoint completely will allow to easy ddos cloud without even an account, as that endpoint allows anonymous access already.

Well AppAPI is not anonymous, right? So it should be using the UserRateLimit, and you could simply adjust that to 100 per second.
You will need to do something alike also with an AppAPIRateLimit anyway.

@bigcat88
Copy link
Contributor

bigcat88 commented Mar 12, 2024

Well AppAPI is not anonymous, right

Summarise bot is anonymous, it is not triggered by user, it is triggered by background job once a day, so we can't not know what "userId" to use in OCS requests.

@bigcat88
Copy link
Contributor

bigcat88 commented Mar 12, 2024

My proposal: we have such a concept in ExApp as a “system application” - it is indicated by a separate flag.
These applications are able to impersonate the user and they do not interact directly with users, and Summarize Chat Bot is the first system application, afaik.

We can make sure that this flag is added to the session and add a check for this flag, and remove the rate limit only for such system applications.

Will this be ok?

Ordinary ExApps really don’t need a separate RateLimit, as they always have a UserId.

This is draft for adding that session variable: https://github.com/cloud-py-api/app_api/pull/248/files

@nickvergessen
Copy link
Member

I guess so, but we are running out of time (behind API and feature freeze)

@skjnldsv skjnldsv added bug 2. developing Work in progress 3. to review Waiting for reviews labels Mar 15, 2024
@skjnldsv skjnldsv added this to the Nextcloud 30 milestone Mar 15, 2024
@skjnldsv skjnldsv added security and removed 3. to review Waiting for reviews labels Mar 15, 2024
@nc-fkl
Copy link
Contributor Author

nc-fkl commented Mar 15, 2024

I guess so, but we are running out of time (behind API and feature freeze)

As @bigcat88 mentioned, we are now checking in the session for app_api_system - it shouldn't break anything. Are you fine with that @nickvergessen ?

@bigcat88
Copy link
Contributor

I guess so, but we are running out of time (behind API and feature freeze)

From my humble point of view, this is not a new feature, but rather a bug fix that we missed when implementing AppAPI authentication.
Bypassing two-factor authentication and CORS was treated like a bugfix..

@nickvergessen
Copy link
Member

I guess so, but we are running out of time (behind API and feature freeze)

From my humble point of view, this is not a new feature, but rather a bug fix that we missed when implementing AppAPI authentication.

My point was less to block merging, but more to point out that this should be speeded up, so we also run the final result of crucial points before the release

@andrey18106 andrey18106 force-pushed the enh/appapi-rate-limit-bypass branch 2 times, most recently from 08d6340 to 9e3888f Compare March 18, 2024 17:38
@andrey18106 andrey18106 force-pushed the enh/appapi-rate-limit-bypass branch from 9e3888f to f3a4abd Compare March 18, 2024 18:09
@bigcat88
Copy link
Contributor

cypress errors look unrelated

@bigcat88 bigcat88 modified the milestones: Nextcloud 30, Nextcloud 29 Mar 18, 2024
@Altahrim Altahrim mentioned this pull request Mar 19, 2024
@nickvergessen nickvergessen merged commit 6101abb into master Mar 19, 2024
@nickvergessen nickvergessen deleted the enh/appapi-rate-limit-bypass branch March 19, 2024 08:32
@welcome
Copy link

welcome bot commented Mar 19, 2024

Thanks for your first pull request and welcome to the community! Feel free to keep them coming! If you are looking for issues to tackle then have a look at this selection: https://github.com/nextcloud/server/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22

@bigcat88
Copy link
Contributor

/backport to stable28

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