Skip to content

fix: Original object missing in afterSave trigger and LiveQuery event on login with authData - #10920

Open
Albert1603 wants to merge 1 commit into
parse-community:alphafrom
Albert1603:fix/authdata-login-original
Open

Albert1603 wants to merge 1 commit into
parse-community:alphafrom
Albert1603:fix/authdata-login-original

Conversation

@Albert1603

@Albert1603 Albert1603 commented Dec 3, 2026 •

Copy link
Copy Markdown

Pull Request

Issue

Closes: #7737

Related: #7742, which adds a failing test for this issue.

Approach

A POST /users request with authData that matches an existing user is a login. It has no update query, so RestWrite built no original object: request.original was undefined in the _User afterSave trigger, and the login looked like a sign-up to Cloud Code and to LiveQuery.

The matched user is now copied before the auth validation and the authData update change the response, and the copy is used as the original object. File fields of the copy get their URLs like the response.

The fix adds no database read or write. RestWrite.originalData is not set, because it is also used to build the response and the trigger object of an update.

Sign-up, update and linking of authData are not changed. afterSave still runs on login, also for providers that update authData or use doNotSave.

Notes for review:

  • LiveQuery event changes from create to update. A login with authData now sends an update event with an original object to LiveQuery subscribers, as the user already exists. For this reason I changed one expectation in the test for GHSA-f92h-3w9f-hg55 in spec/vulnerabilities.spec.js from create to update, and added a check that the original object in the event has no authData. The other checks of that test pass unchanged.
  • The original object has the same fields as the original object of a regular update by the user itself. I compared both with protectedFieldsTriggerExempt set to true and to false.
  • The original object is the user as stored before the login, so it has the authData from before the update by the provider.
  • I ran the specs for auth adapters, users, vulnerabilities, LiveQuery and Cloud Code on MongoDB. I did not run them on Postgres.

Tasks

  • Add tests

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Authentication events now consistently reflect changes to existing accounts, including the account’s stored state before an update. LiveQuery reports matching authentication changes as updates rather than creations.
    • Account creation remains distinct from linking an existing account, and invalid authentication data does not trigger post-save processing.

…nt on login with authData

Login with authData matches an existing user without an update query, so `afterSave`
and LiveQuery received no original object and the login looked like a sign-up.

Keep a copy of the matched user before the auth validation and the authData update
change the response, and use it as the original object. File fields of the copy get
their URLs like the response. LiveQuery now sends the login as an update event.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@parse-github-assistant

Copy link
Copy Markdown

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

Tip

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

Note

Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect.

Caution

Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

AuthData login processing now preserves the matched user as the original object for after-save and LiveQuery processing. Tests cover login, signup, linking, file attributes, and failed authData validation.

Changes: AuthData Login Originals

Layer / File(s) Summary
Preserve matched user as original
src/RestWrite.js, spec/AuthenticationAdaptersV2.spec.js, spec/vulnerabilities.spec.js
The login path clones the matched user, expands its file pointers, and uses it as the original object when no query object exists. Tests check original data during login and linking, signup and failed-login behavior, and LiveQuery events. The vulnerability test now expects an update event whose original object has no authData.

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Possibly related PRs

Suggested reviewers: mtrezza

Merge Risk: Minimal · up to 88fc0

This change makes authData logins of existing users report the stored user as the original object in afterSave and LiveQuery events, so they are no longer treated as new. No concrete merge-blocking risk was found, and the new tests cover the main flows.

Pre-merge checks: Passed 6

Check name Status Explanation
Title check Passed The title begins with the allowed prefix "fix:" and the first letter after the prefix is capitalized ("Original"). It states the main change: the original object is now supplied in the afterSave trigg…
Description check Passed The description follows the repository template. It includes the Pull Request notes, an Issue section that links #7737 and related #7742, a detailed Approach section explaining the login path and the …
Linked Issues check Passed [#7737] requires that an existing user who logs in through Facebook, Twitter, or Google is not detected as new in afterSave. The expected outcome is that an existing user is not detected as new. At …
Out of Scope Changes check Passed All changed files relate to the #7737 fix. src/RestWrite.js adds the login-user preservation, the file expansion for the preserved copy, and the original object construction in buildParseObjects. sp…
Security Check Passed Summary: the PR does not add a client-reachable security weakness in the changed code. I found one server-side deviation from a documented protectedFields setting, and I did not treat it as a FAIL. Ch…
Engage In Review Feedback Passed The check passes because no review feedback exists for the author to ignore or resolve. Evidence: - The review context states: "No CodeRabbit review threads were returned." - The current review report…
Full details: Title check

Explanation

The title begins with the allowed prefix "fix:" and the first letter after the prefix is capitalized ("Original"). It states the main change: the original object is now supplied in the afterSave trigger and LiveQuery event on login with authData, which matches the RestWrite change and the tests.

Full details: Description check

Explanation

The description follows the repository template. It includes the Pull Request notes, an Issue section that links #7737 and related #7742, a detailed Approach section explaining the login path and the fix, review notes on the LiveQuery event change from create to update, and a Tasks section with the tests box checked. The template items for documentation, security check, and Parse JS SDK error codes are not addressed. These are non-critical for this change, so the check passes.

Full details: Linked Issues check

Explanation

[#7737] requires that an existing user who logs in through Facebook, Twitter, or Google is not detected as new in afterSave. The expected outcome is that an existing user is not detected as new. At the reviewed head, RestWrite.handleAuthData stores a clone of the matched user in this.storage.authDataLoginUser when the request has no query (src/RestWrite.js, +3 lines). buildParseObjects then uses that user as originalObject through triggers.inflate when no query exists (+7 lines). The afterSave trigger and LiveQuery therefore receive a non-empty request.original for a login. expandFilesForExistingObjects also expands file fields of the preserved copy, so the original has the same file URLs as the response. The test changes in spec/AuthenticationAdaptersV2.spec.js and spec/vulnerabilities.spec.js cover this behavior. The issue also lists authData being erased intermittently. That item appears as an observation, not as an expected outcome. The PR description states that authData update and linking behavior is unchanged and does not claim to fix it. This gap does not block the stated expected outcome. Caveat: I checked only the RestWrite diff and the test summaries. I did not run the specs.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the #7737 fix. src/RestWrite.js adds the login-user preservation, the file expansion for the preserved copy, and the original object construction in buildParseObjects. spec/AuthenticationAdaptersV2.spec.js adds tests for afterSave original objects on login, linking, signup, and failed validation. spec/vulnerabilities.spec.js changes the GHSA-f92h-3w9f-hg55 LiveQuery expectation from create to update. The PR description explains this change as a direct result of the fix. No unrelated refactoring or unrelated feature appears in the reviewed summary or in the RestWrite diff. The PR description says the fix adds no database read or write and does not change RestWrite.originalData. The diff is consistent with that statement.

Full details: Security Check

Explanation

Summary: the PR does not add a client-reachable security weakness in the changed code. I found one server-side deviation from a documented protectedFields setting, and I did not treat it as a FAIL. Changed files (base...head): src/RestWrite.js, spec/vulnerabilities.spec.js, spec/AuthenticationAdaptersV2.spec.js. What the source change does: - In handleAuthData (login branch, no query objectId), storage.authDataLoginUser = structuredClone(userResult) runs after delete results[0].password. The clone is taken before the authData update and the response mutation. - expandFilesForExistingObjects expands file pointers on that clone, as it already does for the response. - buildParseObjects uses the clone as originalObject when there is no query. Checks performed: - Password hash: delete results[0].password runs before the clone. filterSensitiveData also removes _-prefixed keys such as _hashed_password, _password_history and sessionToken. The original therefore does not carry the password hash or session token. - LiveQuery: ParseLiveQueryServer.ts _filterSensitiveData and _filterAuthData filter res.original per subscriber. They delete original.authData and apply protectedFields and ACL checks. The changed test GHSA-f92h-3w9f-hg55 keeps expectNoSecrets and adds expect(event.original.authData).toBeUndefined(). This keeps the advisory protection in place. - Cross-user data: userResult comes from results[0] after filteredObjectsByACL. A login with a mismatched user throws earlier, so the clone holds only the matched user. Residual observation (not a FAIL): - handleAuthData calls config.database.find without an acl argument. That makes the lookup master-scoped, so protectedFields are not stripped. An update trigger's original is fetched with the caller's auth, and protectedFields are stripped there unless protectedFieldsTriggerExempt is true. The new login original therefore can include protected fields, even when protectedFieldsTriggerExempt is false. - With default options, protectedFieldsOwnerExempt is true, so the logging-in user, as the owner, already sees these fields on a self-update. The exposure is limited to server-side afterSave code. No client-reachable path was found. It is limited to protectedFieldsOwnerExempt: false or role-scoped protected fields. Maintainers may want to confirm this against the documented protectedFieldsTriggerExempt contract. No injection, authorization bypass, secret leakage to clients, or changed authentication decision was found in the diff.

Full details: Engage In Review Feedback

Explanation

The check passes because no review feedback exists for the author to ignore or resolve. Evidence: - The review context states: "No CodeRabbit review threads were returned." - The current review reports zero actionable findings. - No posted review comment is open, closed, or resolved in the supplied context. So no thread was resolved without engagement. - The primary PR is parse-community/parse-server #10920, head branch fix/authdata-login-original, base alpha. The provider-reported author is Albert1603. The check forbids ignoring or resolving feedback without discussion and a commit or a retraction. Without feedback, no violation can occur. The check is therefore not triggered. Limit: this verdict depends on the supplied review context. If review threads exist outside that context, a new assessment would be needed. Tone note: this verdict stands firm on the evidence. A PASS here does not depend on any assumption about the author's intent.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.3)

spec/vulnerabilities.spec.js

ast-grep timed out on this file

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cc7bcb48-b4c0-47a7-a358-39d01b299e44
Commits

Reviewing files that changed from the base of the PR and between 4e4d1a1 and 88fc03e.

Files selected for processing: 3

  • spec/AuthenticationAdaptersV2.spec.js
  • spec/vulnerabilities.spec.js
  • src/RestWrite.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

This branch has not been deployed

No deployments
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.

User is always being detected as new when logged in through Facebook, Twitter, or Google

1 participant