Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sveltekit-rate-limiter

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sveltekit-rate-limiter - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

10

dist/server/index.js

@@ -80,9 +80,2 @@ import { nanoid } from 'nanoid';

}
else {
import('crypto').then((crypto) => {
defaultHashFunction = (input) => {
return Promise.resolve(crypto.createHash('sha256').update(input).digest('hex'));
};
});
}
async function _subtleSha256(str) {

@@ -192,4 +185,5 @@ const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(str));

this.hashFunction = options.hashFunction ?? defaultHashFunction;
if (!this.hashFunction)
if (!this.hashFunction) {
throw new Error('No RateLimiter hash function found. Please set one with the hashFunction option.');
}
if (options.rates?.IP)

@@ -196,0 +190,0 @@ this.plugins.push(new IPRateLimiter(options.rates.IP));

3

package.json
{
"name": "sveltekit-rate-limiter",
"version": "0.4.0",
"version": "0.4.1",
"author": "Andreas Söderlund <ciscoheat@gmail.com> (https://blog.encodeart.dev)",

@@ -46,2 +46,3 @@ "description": "A modular rate limiter for SvelteKit. Use in password resets, account registration, etc.",

"@sveltejs/adapter-auto": "^2.1.0",
"@sveltejs/adapter-cloudflare": "^2.3.2",
"@sveltejs/kit": "^1.22.5",

@@ -48,0 +49,0 @@ "@sveltejs/package": "^2.2.1",

@@ -104,3 +104,3 @@ # sveltekit-rate-limiter

rates: {
IP: [10, 'h']
IP: [10, 'h'],
IPUA: [5, 'm']

@@ -114,3 +114,3 @@ }

if(status.limited) {
if (status.limited) {
event.setHeaders({

@@ -131,2 +131,14 @@ 'Retry-After': status.retryAfter.toString()

## Custom hash function
The default hash function is using `crypto.subtle` to generate a SHA-256 digest, but if isn't available in your environment, you can supply your own with the `hashFunction` option. Here's an example with the NodeJS `crypto` package:
```ts
import crypto from 'crypto';
// (input: string) => Promise<string>
const hashFunction = (input: string) =>
Promise.resolve(crypto.createHash('sha256').update(input).digest('hex'));
```
## Creating a custom limiter

@@ -133,0 +145,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc