implement rate limit support for mastodon endpoints #23

Open
sugar wants to merge 1 commit from sugar/forkey:implement-rate-limits-for-mastodon-endpoints into main
Owner

What

Implement rate limits for future Mastodon endpoints.

Why

Some endpoints will need stricter rate limits.

Additional info (optional)

Note that rate limits are by default disabled in development, see RateLimiterService.

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests
<!-- ℹ お読みください / README PRありがとうございます! PRを作成する前に、コントリビューションガイドをご確認ください: Thank you for your PR! Before creating a PR, please check the contribution guide: https://github.com/misskey-dev/misskey/blob/develop/CONTRIBUTING.md --> ## What <!-- このPRで何をしたのか? どう変わるのか? --> <!-- What did you do with this PR? How will it change things? --> Implement rate limits for future Mastodon endpoints. ## Why <!-- なぜそうするのか? どういう意図なのか? 何が困っているのか? --> <!-- Why do you do it? What are your intentions? What is the problem? --> Some endpoints will need stricter rate limits. ## Additional info (optional) <!-- テスト観点など --> <!-- Test perspective, etc --> Note that rate limits are by default disabled in development, see `RateLimiterService`. ## Checklist - [ ] Read the [contribution guide](https://github.com/misskey-dev/misskey/blob/develop/CONTRIBUTING.md) - [ ] Test working in a local environment - [ ] (If needed) Add story of storybook - [ ] (If needed) Update CHANGELOG.md - [ ] (If possible) Add tests
sugar force-pushed implement-rate-limits-for-mastodon-endpoints from 689ac72c22 to aaa49f2131 2025-01-17 15:29:21 +00:00 Compare
leah reviewed 2025-01-17 22:40:21 +00:00
@ -456,1 +440,4 @@
async #checkRateLimit(ep: IEndpoint | IMastodonEndpoint, user: MiLocalUser | null | undefined, request: FastifyRequest<{ Body: Record<string, unknown> | undefined, Querystring: Record<string, unknown> }>): Promise<void> {
const bypassRateLimit = this.config.bypassRateLimit?.some(({ header, value }) => request.headers[header] === value) ?? false;
console.log(ep);
Owner

Looks like you forgot to remove this console log

Looks like you forgot to remove this console log
Author
Owner

fixed :3

fixed :3
sugar marked this conversation as resolved
sugar force-pushed implement-rate-limits-for-mastodon-endpoints from aaa49f2131 to d5983dc12e 2025-01-18 10:22:33 +00:00 Compare
Owner

how would i go about testing these endpoints? are there unit tests we can write, perhaps?

how would i go about testing these endpoints? are there unit tests we can write, perhaps?
Author
Owner

fae tested them by removing code that only enforces rate limits in production, adding a limit to an already existing endpoint, and repeatedly visiting it

not sure how would fae go about testing it, but if that helps it's the same system as for regular misskey endpoints

also, it's worth noting that rate limiter only works in production environments (as in upstream), which makes it tough to test

		if (process.env.NODE_ENV !== 'production') {
			this.disabled = true;
		}
fae tested them by removing code that only enforces rate limits in production, adding a limit to an already existing endpoint, and repeatedly visiting it not sure how would fae go about testing it, but if that helps it's the same system as for regular misskey endpoints also, it's worth noting that rate limiter only works in production environments (as in upstream), which makes it tough to test ```typescript if (process.env.NODE_ENV !== 'production') { this.disabled = true; } ```
All checks were successful
Lint / pnpm_install (pull_request) Successful in 2m26s
Test (backend) / unit (22.x) (pull_request) Successful in 7m4s
Test (backend) / e2e (22.x) (pull_request) Successful in 9m3s
Test (frontend) / vitest (22.x) (pull_request) Successful in 3m11s
Test (production install and build) / production (22.x) (pull_request) Successful in 2m58s
Test (backend) / validate-api-json (22.x) (pull_request) Successful in 3m21s
Lint / lint (backend) (pull_request) Successful in 2m40s
Lint / lint (frontend) (pull_request) Successful in 9m27s
Lint / lint (misskey-js) (pull_request) Successful in 2m54s
Lint / lint (sw) (pull_request) Successful in 2m17s
Lint / typecheck (backend) (pull_request) Successful in 3m47s
Lint / typecheck (misskey-js) (pull_request) Successful in 2m16s
This pull request has changes conflicting with the target branch.
  • packages/backend/src/server/api/mastodon-endpoints.ts
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u implement-rate-limits-for-mastodon-endpoints:sugar-implement-rate-limits-for-mastodon-endpoints
git checkout sugar-implement-rate-limits-for-mastodon-endpoints

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout main
git merge --no-ff sugar-implement-rate-limits-for-mastodon-endpoints
git checkout sugar-implement-rate-limits-for-mastodon-endpoints
git rebase main
git checkout main
git merge --ff-only sugar-implement-rate-limits-for-mastodon-endpoints
git checkout sugar-implement-rate-limits-for-mastodon-endpoints
git rebase main
git checkout main
git merge --no-ff sugar-implement-rate-limits-for-mastodon-endpoints
git checkout main
git merge --squash sugar-implement-rate-limits-for-mastodon-endpoints
git checkout main
git merge --ff-only sugar-implement-rate-limits-for-mastodon-endpoints
git checkout main
git merge sugar-implement-rate-limits-for-mastodon-endpoints
git push origin main
Sign in to join this conversation.
No description provided.