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

[Enhancement] A collection of pre-included plugins #12

Open
conorvenus opened this issue Sep 18, 2024 · 2 comments
Open

[Enhancement] A collection of pre-included plugins #12

conorvenus opened this issue Sep 18, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@conorvenus
Copy link

conorvenus commented Sep 18, 2024

What do you think about the potential of having some premade plugins included in the library? For example, if people are serving their website via CF or another reverse proxy, the clients' IP addresses are obscured and so you have to use the CF-Connecting-IP header, otherwise then you just end up ratelimiting CF's IP (e.g., every single user who wants to access that endpoint is now ratelimited).

export class CloudflareRateLimiter implements RateLimiterPlugin {
    readonly rate: Rate;

    constructor(rate: { limit: number, duration: RateUnit }) {
        this.rate = [rate.limit, rate.duration];
    }

    async hash(event: RequestEvent) {
        return event.request.headers.get('cf-connecting-ip') || event.getClientAddress();
    }
}
@ciscoheat
Copy link
Owner

Good idea, I'll add this one to a limiters directory in the next release, then you can make a PR there if you want to add more.

@ciscoheat
Copy link
Owner

Added now in 0.6.1. Can you make a PR for the Readme to include them?

CloudflareIPRateLimiter and CloudflareIPUARateLimiter that can be imported from sveltekit-rate-limiter/limiters.

@ciscoheat ciscoheat added the documentation Improvements or additions to documentation label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants