Skip to content

fix: Security migration from csurf to csrf-sync#3188

Merged
mtrezza merged 1 commit intoparse-community:alphafrom
mtrezza:fix/csurf
Feb 7, 2026
Merged

fix: Security migration from csurf to csrf-sync#3188
mtrezza merged 1 commit intoparse-community:alphafrom
mtrezza:fix/csurf

Conversation

@mtrezza
Copy link
Member

@mtrezza mtrezza commented Feb 7, 2026

Pull Request

Issue

Security migration from csurf to csrf-sync

Summary by CodeRabbit

  • Security

    • Enhanced CSRF protection on the login route to strengthen defense against cross-site request forgery attacks and improve overall session security.
  • Dependencies

    • Updated security-related dependencies to support the improved protection mechanism.

@parse-github-assistant
Copy link

parse-github-assistant bot commented Feb 7, 2026

🚀 Thanks for opening this pull request!

@parseplatformorg
Copy link
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mtrezza mtrezza changed the title fix: Security migration from csurf to csrf-sync fix: Security migration from csrf to csrf-sync Feb 7, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

The pull request migrates CSRF protection from the csurf library to csrf-sync. A new CSRF protection middleware is created in Authentication.js with a custom token extractor and exposed as a public property, replacing direct csurf usage in the login route.

Changes

Cohort / File(s) Summary
CSRF Middleware Migration
Parse-Dashboard/Authentication.js, Parse-Dashboard/app.js, package.json
Replaces csurf with csrf-sync for CSRF protection. Introduces csrfSynchronisedProtection middleware with custom token extraction (from req.body._csrf or x-csrf-token header) in Authentication class, exposed as a public property. Updates login route to use the new protection mechanism. Dependency replaced in package.json.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete; it omits the Approach section explaining the technical changes and does not include the Tasks checklist. Add an Approach section detailing the migration steps and include the Tasks checklist with appropriate items checked or marked as N/A.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: migrating from csurf to csrf-sync for security purposes.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@mtrezza mtrezza changed the title fix: Security migration from csrf to csrf-sync fix: Security migration from csurf to csrf-sync Feb 7, 2026
@mtrezza mtrezza linked an issue Feb 7, 2026 that may be closed by this pull request
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: 2

Caution

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

⚠️ Outside diff range comments (1)
Parse-Dashboard/app.js (1)

1110-1110: ⚠️ Potential issue | 🔴 Critical

req.csrfToken() is not a function with csrf-sync — this will throw at runtime.

As detailed in the Authentication.js review, csrf-sync does not add csrfToken() to the request object. This line will throw TypeError: req.csrfToken is not a function when any user visits the login page, completely breaking authentication.

🤖 Fix all issues with AI agents
In `@Parse-Dashboard/app.js`:
- Line 1067: The GET /login route uses Authentication.csrfProtection
(csrfSynchronisedProtection) which ignores GET methods and therefore does not
generate req.csrfToken(); update the route handler for app.get('/login',
Authentication.csrfProtection, ...) to explicitly call
Authentication.generateToken(req) (or the equivalent generateToken function
referenced in Authentication.js) to create/retrieve the CSRF token and pass it
into the rendered login page (e.g., add the token to the view locals or template
data) so forms can embed the token; ensure you use the same token API defined in
Authentication.js and keep the middleware in place.

In `@Parse-Dashboard/Authentication.js`:
- Around line 3-10: The code currently only destructures
csrfSynchronisedProtection from csrfSync but not generateToken, so
req.csrfToken() in the login GET handler will break; update the csrfSync call in
Authentication.js to also destructure and export generateToken (alongside
csrfSynchronisedProtection) and then replace the call to req.csrfToken() in the
login GET handler in app.js with generateToken(req) to obtain and embed the CSRF
token.

@mtrezza mtrezza merged commit a95d8a3 into parse-community:alpha Feb 7, 2026
12 checks passed
@mtrezza mtrezza deleted the fix/csurf branch February 7, 2026 02:53
parseplatformorg pushed a commit that referenced this pull request Feb 7, 2026
# [8.5.0-alpha.2](8.5.0-alpha.1...8.5.0-alpha.2) (2026-02-07)

### Bug Fixes

* Security migration from csurf to csrf-sync ([#3188](#3188)) ([a95d8a3](a95d8a3))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 8.5.0-alpha.2

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Feb 7, 2026
parseplatformorg pushed a commit that referenced this pull request Feb 12, 2026
# [8.5.0](8.4.0...8.5.0) (2026-02-12)

### Bug Fixes

* Auto-formatting not applied when Cloud Config parameter value is outdated and re-fetched from server ([#3182](#3182)) ([84eab36](84eab36))
* Clicking reload button in info panel may display fetched data in incorrect panel ([#3189](#3189)) ([b348ef5](b348ef5))
* Role linking in ACL fails with type error ([#3095](#3095)) ([2070d29](2070d29))
* Security migration from csurf to csrf-sync ([#3188](#3188)) ([a95d8a3](a95d8a3))
* View configuration dialog looses focus while typing and lacks syntax highlighting ([#3183](#3183)) ([715fe8d](715fe8d))

### Features

* Add keyboard shortcut to scroll info panels to top ([#3199](#3199)) ([7535626](7535626))
* Add option to reload all or only selected rows after invoking script ([#3200](#3200)) ([173b953](173b953))
* Add reload button to info panel on long loading time ([#3184](#3184)) ([3712d96](3712d96))
* Add support for script execution invoking dashboard form for user input ([#3201](#3201)) ([159f99d](159f99d))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 8.5.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:released Released as stable version state:released-alpha Released as alpha version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace deprecated csurf dependency with maintained alternative

2 participants