Skip to content

refactor: remove short-circuit middleware from Discord invite route#2582

Open
AnujChhikara wants to merge 2 commits intodevelopfrom
anuj/enable-get-invite-link-route
Open

refactor: remove short-circuit middleware from Discord invite route#2582
AnujChhikara wants to merge 2 commits intodevelopfrom
anuj/enable-get-invite-link-route

Conversation

@AnujChhikara
Copy link
Contributor

@AnujChhikara AnujChhikara commented Feb 24, 2026

Date: 25 Feb 2026

Developer Name: @AnujChhikara


Issue Ticket Number

Tech Doc Link

  • NA

Business Doc Link

  • NA

Description

  • removed short-circuit middleware from Discord invite route

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screenshot 1
Screen.Recording.2026-02-25.at.1.33.57.AM.mov

@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

Walkthrough

The disableRoute middleware import and its usage were removed from the GET /invite route in the Discord actions router. The endpoint now executes only the authenticate and getUserDiscordInvite middlewares in sequence.

Changes

Cohort / File(s) Summary
Middleware removal
routes/discordactions.js
Removed disableRoute middleware import and eliminated its usage from the GET /invite route handler.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • RealDevSquad/website-backend#2570: Removes the disableRoute short-circuit middleware from the POST /invite endpoint, following a similar pattern of middleware simplification.

Suggested reviewers

  • MayankBansal12
  • iamitprakash

Poem

🐰 A middleware falls away, streamlining the path,
The invite route breathes lighter now, no gatekeeping wrath!
Simpler flows, cleaner routes—
The Discord door swings wide with just a pair of boots! 🚪✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: removing the disableRoute middleware from the Discord invite route endpoint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description accurately describes the changeset - it removes the short-circuit middleware from the Discord invite route, which matches the code changes shown in the raw summary.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch anuj/enable-get-invite-link-route

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AnujChhikara AnujChhikara self-assigned this Feb 24, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
routes/discordactions.js (1)

40-44: ⚠️ Potential issue | 🟡 Minor

Remove the now-stale "Short-circuit" comment block.

The comment at Lines 40–43 explicitly states "Short-circuit the GET method for this endpoint", which directly contradicts the intent of this PR (removing that short-circuit). Leaving it in place will mislead future readers into thinking the route is still disabled.

🧹 Proposed fix
-/**
- * Short-circuit the GET method for this endpoint
- * Refer https://github.com/Real-Dev-Squad/todo-action-items/issues/269 for more details.
- */
 router.get("/invite", authenticate, getUserDiscordInvite);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@routes/discordactions.js` around lines 40 - 44, Remove the stale comment
block above the router.get("/invite", authenticate, getUserDiscordInvite) route
in routes/discordactions.js: delete the lines that say "Short-circuit the GET
method for this endpoint" and the referential URL so the comment no longer
contradicts the current behavior of the route; leave the route registration
(router.get(...)) and middleware/handler (authenticate, getUserDiscordInvite)
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@routes/discordactions.js`:
- Line 44: The /invite GET route currently calls authenticate and
getUserDiscordInvite without rate limiting; import the rate limiter (exported
function n) from middlewares/rateLimiting.js and apply it to this route so the
handler becomes router.get("/invite", authenticate, n(), getUserDiscordInvite)
(or the appropriate middleware invocation signature) to protect
getUserDiscordInvite from enumeration and Firestore exhaustion.

---

Outside diff comments:
In `@routes/discordactions.js`:
- Around line 40-44: Remove the stale comment block above the
router.get("/invite", authenticate, getUserDiscordInvite) route in
routes/discordactions.js: delete the lines that say "Short-circuit the GET
method for this endpoint" and the referential URL so the comment no longer
contradicts the current behavior of the route; leave the route registration
(router.get(...)) and middleware/handler (authenticate, getUserDiscordInvite)
unchanged.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b705b0 and b69eaea.

📒 Files selected for processing (1)
  • routes/discordactions.js

MayankBansal12
MayankBansal12 previously approved these changes Feb 24, 2026
@AnujChhikara
Copy link
Contributor Author

@coderabbitai can you please create an ticket for these changes where i removed the disable route middleware from the get discord invite route as new application are opening and user should be able to get their invite links

@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@AnujChhikara: I'll create a GitHub issue to document these changes.


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue for enabling the Discord invite route

gh issue create \
  --title "Enable Discord invite route for new applications" \
  --body "## Context

This issue tracks the changes made in PR `#2582` to enable the Discord invite route for users.

## Change Summary

The \`disableRoute\` middleware has been removed from the GET \`/invite\` route in the Discord actions router. This allows users to retrieve their Discord invite links.

## Rationale

New applications are opening and users should be able to get their invite links through this endpoint.

## Reference

- PR: https://github.com/RealDevSquad/website-backend/pull/2582
- Requested by: `@AnujChhikara`" \
  --assignee AnujChhikara

Length of output: 59


@AnujChhikara: I've successfully created issue #2583 to track these changes. The issue documents the removal of the disableRoute middleware from the Discord invite route and explains that it's being enabled because new applications are opening and users need to access their invite links.

You can view the issue here: #2583

* Short-circuit this POST method for this endpoint
* Refer https://github.com/Real-Dev-Squad/todo-action-items/issues/269 for more details.
*/
router.get("/invite", authenticate, getUserDiscordInvite);

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.

Copilot Autofix

AI 1 day ago

In general, this should be fixed by adding a rate‑limiting middleware to the affected route so that each client (e.g., IP) can only hit /invite a bounded number of times within a time window. In Express, a common solution is to use the well‑known express-rate-limit package, configure a limiter, and insert it into the middleware chain for the vulnerable route(s).

For this code, the least intrusive, best fix is:

  • Import express-rate-limit at the top of routes/discordactions.js.
  • Define a limiter specifically for the Discord invite endpoint, e.g., getUserInviteLimiter, configured with a reasonable windowMs and max appropriate for invite lookups (for example, a small number per minute or per 15 minutes).
  • Apply this limiter only to the GET /invite route by placing it between authenticate and getUserDiscordInvite in the middleware chain.
  • Leave all other routes unchanged, since CodeQL only complained about this one, and we don’t want to alter behavior elsewhere without need.

Concretely:

  • In routes/discordactions.js, add const rateLimit = require("express-rate-limit"); alongside the other require statements.
  • Below the router initialization (const router = express.Router();), define const getUserInviteLimiter = rateLimit({...}).
  • Update line 40 from router.get("/invite", authenticate, getUserDiscordInvite); to router.get("/invite", authenticate, getUserInviteLimiter, getUserDiscordInvite);.

This introduces rate limiting for the sensitive route without modifying existing authentication/authorization logic or controllers.

Suggested changeset 2
routes/discordactions.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/routes/discordactions.js b/routes/discordactions.js
--- a/routes/discordactions.js
+++ b/routes/discordactions.js
@@ -31,13 +31,21 @@
 const { Services } = require("../constants/bot");
 const { verifyCronJob } = require("../middlewares/authorizeBot");
 const { authorizeAndAuthenticate } = require("../middlewares/authorizeUsersAndService");
+const rateLimit = require("express-rate-limit");
 const router = express.Router();
 
+const getUserInviteLimiter = rateLimit({
+  windowMs: 15 * 60 * 1000, // 15 minutes
+  max: 50, // limit each IP to 50 requests per windowMs for GET /invite
+  standardHeaders: true,
+  legacyHeaders: false,
+});
+
 router.post("/groups", authenticate, checkIsVerifiedDiscord, validateGroupRoleBody, createGroupRole);
 router.get("/groups", authenticate, checkIsVerifiedDiscord, validateLazyLoadingParams, getPaginatedAllGroupRoles);
 router.delete("/groups/:groupId", authenticate, checkIsVerifiedDiscord, authorizeRoles([SUPERUSER]), deleteGroupRole);
 router.post("/roles", authenticate, checkIsVerifiedDiscord, validateMemberRoleBody, addGroupRoleToMember);
-router.get("/invite", authenticate, getUserDiscordInvite);
+router.get("/invite", authenticate, getUserInviteLimiter, getUserDiscordInvite);
 router.post("/invite", authenticate, checkCanGenerateDiscordLink, generateInviteForUser);
 
 router.delete("/roles", authenticate, checkIsVerifiedDiscord, deleteRole);
EOF
@@ -31,13 +31,21 @@
const { Services } = require("../constants/bot");
const { verifyCronJob } = require("../middlewares/authorizeBot");
const { authorizeAndAuthenticate } = require("../middlewares/authorizeUsersAndService");
const rateLimit = require("express-rate-limit");
const router = express.Router();

const getUserInviteLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 50, // limit each IP to 50 requests per windowMs for GET /invite
standardHeaders: true,
legacyHeaders: false,
});

router.post("/groups", authenticate, checkIsVerifiedDiscord, validateGroupRoleBody, createGroupRole);
router.get("/groups", authenticate, checkIsVerifiedDiscord, validateLazyLoadingParams, getPaginatedAllGroupRoles);
router.delete("/groups/:groupId", authenticate, checkIsVerifiedDiscord, authorizeRoles([SUPERUSER]), deleteGroupRole);
router.post("/roles", authenticate, checkIsVerifiedDiscord, validateMemberRoleBody, addGroupRoleToMember);
router.get("/invite", authenticate, getUserDiscordInvite);
router.get("/invite", authenticate, getUserInviteLimiter, getUserDiscordInvite);
router.post("/invite", authenticate, checkCanGenerateDiscordLink, generateInviteForUser);

router.delete("/roles", authenticate, checkIsVerifiedDiscord, deleteRole);
package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -42,7 +42,8 @@
     "passport-github2": "0.1.12",
     "passport-google-oauth20": "^2.0.0",
     "rate-limiter-flexible": "5.0.3",
-    "winston": "3.13.0"
+    "winston": "3.13.0",
+    "express-rate-limit": "^8.2.1"
   },
   "devDependencies": {
     "@types/chai": "4.3.16",
EOF
@@ -42,7 +42,8 @@
"passport-github2": "0.1.12",
"passport-google-oauth20": "^2.0.0",
"rate-limiter-flexible": "5.0.3",
"winston": "3.13.0"
"winston": "3.13.0",
"express-rate-limit": "^8.2.1"
},
"devDependencies": {
"@types/chai": "4.3.16",
This fix introduces these dependencies
Package Version Security advisories
express-rate-limit (npm) 8.2.1 None
Copilot is powered by AI and may make mistakes. Always verify output.
@prakashchoudhary07
Copy link
Contributor

prakashchoudhary07 commented Feb 25, 2026

Comment on lines -47 to -49
* Short-circuit this POST method for this endpoint
* Refer https://github.com/Real-Dev-Squad/todo-action-items/issues/269 for more details.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug needs to be fixed before enabling this route, is it solved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No one can generate invite link until they have approved application in this new application cycle that we will start. So we are maintaining a Boolean value isNew:true for new application and all the previous application irrespective of status have isNew: false and before generating the link we verify isNew should be true otherwise you can not generate invite link

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnujChhikara So when does isNew become false?

Also, if that issue is fixed, please add the description, link the PR which fixes it, and update the status of it please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ran a migration script where in all of the old application we added isNew: false field. So if anyone have a approved application they can not generate invite code. They will be able to generate invite link if their application got approved this time as in this new application cycle we are using isNew:true field.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, are we not storing the invite link generation status? Is that not being used?

Copy link
Contributor Author

@AnujChhikara AnujChhikara Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When user created the invite link we store that in the discord invite collection and they can get that using this get api from where I am removing the disable route middleware. When someone try to generate invite again we check if invite exists in that collection if found then we throw error that's way they cannot generate more than one invite link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants