Arcjet helps developers protect their apps in just a few lines of code. Bot detection. Rate limiting. Email validation. Attack protection. Data redaction. A developer-first approach to security.
This is an example Firebase functions application demonstrating how to protect a website from abuse.
- Bot protection shows how the site can be protected from automated clients.
- Rate limiting shows a rate limit configuration that limits the number of requests from a single IP.
- Attack protection demonstrates Arcjet Shield, which detects suspicious behavior, such as SQL injection and cross-site scripting attacks.
-
Install dependencies:
npm ci-
Rename
example.secret.localto.secret.localand add your Arcjet key. -
Start the dev server
npm run devFirebase may prompt you to login; follow the instructions in the terminal.
Firebase will print the local URL of both the emulator UI and the function
iteself. The function URL should end with /arcjetExample.
-
Install dependencies:
npm ci- Login to Firebase:
npx firebase login- Configure
ARCJET_KEYsecret in Firebase:
npx firebase functions:secrets:set ARCJET_KEY- Deploy to Firebase:
npm run deployFirebase will provide the URL of your deployed function which should end with
/arcjetExample.
- Open the deployed function URL in your browser and you'll see a "Hello world" response.
- Reload the page 6 or so times within a minute and you should see "Rate limit exceeded."
- Add a
userquery parameter to the URL (for examplehttps://<your functionurl>?user=david), and reload the page multiple times. You should see "Hello david" responses until you exceed the higher rate limit for authenticated users. - Make a
curlrequest to the function and you should see a "Bots denied" message. - Try running following
curlcommand a couple times to simulate a spoofed bot
curl -H "User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" <your function url>Check out the docs, contact support, or join our Discord server.
All development for Arcjet examples is done in the
arcjet/examples repository.
You are welcome to open an issue here or in
arcjet/examples directly.
However, please direct all pull requests to
arcjet/examples. Take a look at
our
contributing guide
for more information.