arcjet / arcjet-js

Arcjet JS SDKs. Rate limiting, bot protection, email verification & attack defense for Node.js, Next.js, Bun & SvelteKit.
https://arcjet.com
Apache License 2.0
182 stars 3 forks source link

Missing `refillRate` on TokenBucket configuration causes error #992

Open bendechrai opened 1 month ago

bendechrai commented 1 month ago

Might be the lack of the required refillRate or the inclusion of an unknown fillRate, but the following config:

    tokenBucket({
      mode: "LIVE",
      capacity: 40,
      fillRate: 10,
      interval: 60,
    }),

Caused the following in DataDog:

Key: 'TokenBucketOptions.RefillRate' Error:Field validation for 'RefillRate' failed on the 'required' tag

Should probably return an error to the app, not the server.

davidmytton commented 1 month ago

Here's the error detail.

{
        "attributes": {
            "availability_zone": "aws-us-west-2a",
            "reason": {
                "Error": {
                    "message": "Could not construct RateLimit rule"
                }
            },
            "level": "INFO",
            "rules": [
                {
                    "Rule": {
                        "Shield": {
                            "mode": 2,
                            "auto_added": true
                        }
                    }
                },
                {
                    "Rule": {
                        "RateLimit": {
                            "mode": 2,
                            "interval": 60,
                            "algorithm": 1,
                            "capacity": 40
                        }
                    }
                },
                {
                    "Rule": {
                        "Bots": {
                            "mode": 2,
                            "block": [
                                2
                            ]
                        }
                    }
                }
            ],
            "ttl": 0,
            "conclusion": "CONCLUSION_ERROR",
            "results": [
                {
                    "conclusion": 1,
                    "state": 1
                },
                {
                    "conclusion": 4,
                    "reason": {
                        "Reason": {
                            "Error": {
                                "message": "Could not construct RateLimit rule"
                            }
                        }
                    },
                    "state": 2
                },
                {
                    "conclusion": 1,
                    "reason": {
                        "Reason": {
                            "Bot": {
                                "bot_type": 4
                            }
                        }
                    },
                    "state": 1
                }
            ],
            "key": ""
        }
    }
}