Skip to content

fix: change logout from GET to POST with session destruction#578

Open
anshul23102 wants to merge 1 commit into
GitMetricsLab:mainfrom
anshul23102:fix/logout-get-to-post-556
Open

fix: change logout from GET to POST with session destruction#578
anshul23102 wants to merge 1 commit into
GitMetricsLab:mainfrom
anshul23102:fix/logout-get-to-post-556

Conversation

@anshul23102
Copy link
Copy Markdown
Contributor

Summary

Closes #556

The /api/auth/logout route was registered as GET, making it vulnerable to CSRF via image tags, link prefetching, or simple <a> clicks. This change:

  • Changes the route method from GET to POST
  • Adds req.session.destroy() to fully invalidate the server-side session after req.logout()
  • Calls res.clearCookie('connect.sid') to remove the session cookie from the browser

Changes

  • backend/routes/auth.js: Route method changed from GET to POST; added session destruction and cookie clearing

Test plan

  • POST /api/auth/logout returns 200 and { message: 'Logged out successfully' }
  • After logout, the connect.sid cookie is absent from the response
  • A subsequent authenticated request using the old session ID is rejected (session destroyed server-side)
  • GET /api/auth/logout now returns 404

Could you please add the appropriate GSSoC labels (gssoc26, type:security, level:intermediate) when you get a chance? Thank you!

The logout route used GET which allows CSRF attacks via image tags or
link prefetching. Changed to POST and added req.session.destroy() plus
res.clearCookie() to ensure the session is fully invalidated server-side
and the cookie is cleared from the browser on logout.

Fixes GitMetricsLab#556
@netlify
Copy link
Copy Markdown

netlify Bot commented May 27, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit e5fd808
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a1710ada8d3ca0008c2e1f7
😎 Deploy Preview https://deploy-preview-578--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Warning

Review limit reached

@anshul23102, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 15 minutes and 19 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a833474d-8513-4bdd-8ad4-a799a26a0cf1

📥 Commits

Reviewing files that changed from the base of the PR and between 4ae0ef6 and e5fd808.

📒 Files selected for processing (1)
  • backend/routes/auth.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@anshul23102
Copy link
Copy Markdown
Contributor Author

Hey @GitMetricsLab, pinging this as part of NSoC'26. Let me know if you have any review feedback. Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [GSSoC'26] GET /api/auth/logout is CSRF-vulnerable: any third-party page can force-logout authenticated users via a passive request

1 participant