fix: toJSONwithObjects leaks ParseACL instances when afterFind hooks modify objects with directAccess - #10244
Conversation
…oks modify objects When `directAccess` is enabled, `toJSONwithObjects` iterates pending ops and calls `object.get(key)` for each dirty field. For ACL, this returns a live `ParseACL` instance. Since `ParseACL` lacks `_toFullJSON`, the instance was assigned directly to the response JSON. With `directAccess`, the response bypasses HTTP serialization, so the raw `ParseACL` leaks to the client SDK. The client's `ParseObject._finishFetch` then calls `new ParseACL(aclData)` expecting plain JSON but receiving a `ParseACL` instance, throwing: "TypeError: Tried to create an ACL with an invalid permission type." The fix calls `val.toJSON()` on values that support it before assigning, ensuring SDK types like `ParseACL` and `ParseGeoPoint` are serialized to plain JSON — consistent with what `object.toJSON()` already does. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🚀 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
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. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
ChangesACL serialization
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change serializes SDK values such as ParseACL before direct-access responses, addressing client errors caused by leaked live instances. No actionable merge-blocking risk remains at the current head, so the PR is merge-ready after normal checks and review. Suggested reviewers: Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error)
✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #10244 +/- ##
=======================================
Coverage 93.78% 93.78%
=======================================
Files 192 192
Lines 16832 16832
Branches 248 248
=======================================
Hits 15786 15786
Misses 1025 1025
Partials 21 21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@mtrezza can you re-run the "MongoDB 8, ReplicaSet" looks like a flaky test case. Also "Docker Build" action failing on this PR only? |
|
@yog27ray Is this a security vulnerability? |
|
@mtrezza is there any change required in this PR? |
|
@mtrezza can someone review this? |
|
@mtrezza any concern with this PR ? |
|
@yog27ray it's in review |
|
The ACL fix is correct, but calling The client SDK's if (value === null || typeof value !== 'object' || value instanceof Date) {
return value;
}
Unlike ACL (which is already a hard A fix could be to narrow the conditional to ACL: if (val instanceof Parse.ACL) {
toJSON[key] = val.toJSON();
} else {
toJSON[key] = val;
}The root cause is that the pending-ops loop overrides the properly-encoded output of The broader issue is that if directAccess currently returns a date string, and we cannot even switch to a Parse-style date object, because even though Parse SDKs would be able to parse it correctly, it would be a breaking change for direct REST consumers.
|
… Date instances Calling val.toJSON() on all objects with a toJSON method converts Date instances to ISO strings, breaking directAccess consumers. Narrowing to Parse.ACL fixes the original bug without regressing Date fields.
|
@mtrezza requested changes done |
|
@mtrezza any further changes required. |
|
@mtrezza any update on this |
|
@mtrezza is there any changes required? |
|
@mtrezza any thing that i can help with to make this PR merge. |
Issue
Closes #8473
When
directAccessis enabled,toJSONwithObjectsinsrc/triggers.jsleaks liveParseACLinstances into the response instead of plain JSON objects. This causes the client-side Parse SDK to throw:The bug occurs when an
afterFindhook modifies objects via.setACL()or.set(). SinceParseACLlacks_toFullJSON, the raw instance is assigned directly to the response JSON. WithdirectAccess, the response bypasses HTTP serialization (JSON.stringify), so theParseACLinstance leaks through toParseObject._finishFetch, which expects plain JSON.Approach
In
toJSONwithObjects, when a pending op value lacks_toFullJSON, check if it has atoJSONmethod and call it before assigning. This serializes SDK types likeParseACLandParseGeoPointto plain JSON — consistent with whatobject.toJSON()already does in the same function.Change in
src/triggers.js:198:Tasks
Summary by CodeRabbit
Bug Fixes
Tests