Applied Arcjet Protection for rate limiting, spoofed bot detection , … - #3
Merged
Conversation
…SQL injection , etc to all auth routes
There was a problem hiding this comment.
Pull request overview
This pull request introduces Arcjet-based security protections for the backend auth endpoints to add automated shielding, bot detection (including spoofing inspection), and rate limiting.
Changes:
- Adds a shared
arcjetProtectionExpress middleware and applies it to all/api/authroutes. - Introduces Arcjet configuration (
shield,detectBot,slidingWindow) and wires in new environment variables. - Adds Arcjet dependencies to the backend package manifests.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/src/routes/auth.routes.js | Applies Arcjet protection middleware to all auth routes. |
| backend/src/middleware/arcjet.middleware.js | Implements the Arcjet protection middleware and denial responses. |
| backend/src/lib/env.js | Adds Arcjet-related environment variable wiring. |
| backend/src/lib/arcjet.js | Adds Arcjet client/rules configuration for shielding, bot detection, and rate limiting. |
| backend/package.json | Adds Arcjet dependencies for runtime usage. |
| backend/package-lock.json | Locks Arcjet dependency tree (includes Node engine requirements). |
Files not reviewed (1)
- backend/package-lock.json: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
13
to
14
| "type": "module", | ||
| "dependencies": { |
Comment on lines
+5
to
+29
| const aj = arcjet({ | ||
| key: ENV.ARCJET_KEY, | ||
| rules: [ | ||
| // Shield protects your app from common attacks e.g. SQL injection | ||
| shield({ mode: "LIVE" }), | ||
| // Create a bot detection rule | ||
| detectBot({ | ||
| mode: "LIVE", // Blocks requests. Use "DRY_RUN" to log only | ||
| // Block all bots except the following | ||
| allow: [ | ||
| "CATEGORY:SEARCH_ENGINE", // Google, Bing, etc | ||
| // Uncomment to allow these other common bot categories | ||
| // See the full list at https://arcjet.com/bot-list | ||
| //"CATEGORY:MONITOR", // Uptime monitoring services | ||
| //"CATEGORY:PREVIEW", // Link previews e.g. Slack, Discord | ||
| ], | ||
| }), | ||
| // Create a token bucket rate limit. Other algorithms are supported. | ||
| slidingWindow({ | ||
| mode: "LIVE", // Blocks requests. Use "DRY_RUN" to log only | ||
| max: 100, // Max 100 requests | ||
| interval: 60, | ||
| }), | ||
| ], | ||
| }); |
Comment on lines
+22
to
+25
| return res.status(403).json({ | ||
| error: "Spoofed bot detected", | ||
| message: "Malicious bot activity detected.", | ||
| }); |
Comment on lines
+29
to
+32
| } catch (error) { | ||
| console.log("Arcjet Protection Error:", error); | ||
| next(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…SQL injection , etc to all auth routes