Skip to content

feat: Add zones for rate limiting by ip, user, session, global #8508

New issue

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

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

Already on GitHub? # to your account

Merged
merged 9 commits into from
Jun 9, 2023

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Apr 14, 2023

Pull Request

Issue

Closes: #8507

Approach

Adds zone to rateLimit to allow rate limits:

  • per user: rate limits per user ID
  • per session: rate limits per session token
  • per ip: rate limit per ip (current default)
  • global: rate limit across all users (useful for DDOS protection for example)

Tasks

  • Add tests

@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title feat: create rateLimit zone to rate limit depending on global, ip, userId, sessionToken feat: Create rateLimit zone to rate limit depending on global, ip, userId, sessionToken Apr 14, 2023
@parse-github-assistant
Copy link

Thanks for opening this pull request!

@codecov
Copy link

codecov bot commented Apr 14, 2023

Codecov Report

Patch coverage: 95.23% and project coverage change: -0.02 ⚠️

Comparison is base (967700b) 94.44% compared to head (5410c0b) 94.42%.

❗ Current head 5410c0b differs from pull request most recent head 4f4b747. Consider uploading reports for the commit 4f4b747 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha    #8508      +/-   ##
==========================================
- Coverage   94.44%   94.42%   -0.02%     
==========================================
  Files         183      184       +1     
  Lines       14594    14613      +19     
==========================================
+ Hits        13783    13799      +16     
- Misses        811      814       +3     
Impacted Files Coverage Δ
src/Options/Definitions.js 100.00% <ø> (ø)
src/Options/index.js 100.00% <ø> (ø)
src/middlewares.js 96.81% <90.00%> (-0.23%) ⬇️
src/Config.js 91.27% <100.00%> (+0.10%) ⬆️
src/ParseServer.js 97.46% <100.00%> (+0.02%) ⬆️
src/cloud-code/Parse.Server.js 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dblythy dblythy requested a review from a team April 14, 2023 05:31
@dblythy
Copy link
Member Author

dblythy commented May 16, 2023

Added the ability to define namespaces via Parse.Server, so we can use Parse.Server.RateLimitOptions

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

Looks good, is this ready for merge?

@mtrezza mtrezza changed the title feat: Create rateLimit zone to rate limit depending on global, ip, userId, sessionToken feat: Create rate limit zone for rate limiting based on global, ip, userId, sessionToken May 17, 2023
@mtrezza mtrezza changed the title feat: Create rate limit zone for rate limiting based on global, ip, userId, sessionToken feat: Create rate limit zone for rate limiting by global, ip, userId, sessionToken May 17, 2023
@dblythy
Copy link
Member Author

dblythy commented May 22, 2023

I have been trying to get enum working with flow / JS Docs (so we can use ParseServerOptions.RateLimitZone.Global) but I haven't been successful - do you have any ideas? I'm thinking it makes more sense than using Parse.Server but I can't get it working

@mtrezza
Copy link
Member

mtrezza commented May 22, 2023

Hm, what are our options?

@dblythy
Copy link
Member Author

dblythy commented Jun 9, 2023

I think the current solution is fine. Ready for merge!

@mtrezza mtrezza changed the title feat: Create rate limit zone for rate limiting by global, ip, userId, sessionToken feat: Add zones for rate limiting by ip, user, session, global Jun 9, 2023
@mtrezza mtrezza merged commit 03fba97 into parse-community:alpha Jun 9, 2023
parseplatformorg pushed a commit that referenced this pull request Jun 9, 2023
# [6.1.0-alpha.20](6.1.0-alpha.19...6.1.0-alpha.20) (2023-06-09)

### Features

* Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.1.0-alpha.20

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Jun 9, 2023
parseplatformorg pushed a commit that referenced this pull request Jun 10, 2023
# [6.3.0-beta.1](6.2.0...6.3.0-beta.1) (2023-06-10)

### Bug Fixes

* Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515))
* GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b))
* Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02))
* LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b))
* Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c))
* Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007))

### Features

* `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3))
* Add new Parse Server option `prevent#WithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308))
* Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31))
* Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673))
* Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97))
* Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3))

### Reverts

* fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.3.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Jun 10, 2023
parseplatformorg pushed a commit that referenced this pull request Jun 18, 2023
# [6.3.0-alpha.1](6.2.0...6.3.0-alpha.1) (2023-06-18)

### Bug Fixes

* Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515))
* GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b))
* Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02))
* LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b))
* Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c))
* Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007))

### Features

* `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3))
* Add new Parse Server option `prevent#WithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308))
* Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31))
* Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673))
* Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97))
* Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3))

### Reverts

* fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.3.0-alpha.1

parseplatformorg pushed a commit that referenced this pull request Sep 16, 2023
# [6.3.0](6.2.2...6.3.0) (2023-09-16)

### Bug Fixes

* Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515))
* GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b))
* Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02))
* LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b))
* Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c))
* Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007))

### Features

* `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3))
* Add new Parse Server option `prevent#WithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308))
* Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31))
* Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673))
* Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97))
* Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3))

### Reverts

* fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.3.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Sep 16, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create rateLimit zone to support global rate limiting
3 participants