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 Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded two afterFind hook tests covering ACL serialization and directAccess behavior; updated toJSONwithObjects to serialize pending Parse.ACL instances to plain JSON instead of leaving them as Parse.ACL objects. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 92.50% 92.50%
=======================================
Files 192 192
Lines 16792 16792
Branches 234 234
=======================================
Hits 15533 15533
Misses 1236 1236
Partials 23 23 ☔ View full report in Codecov by Sentry. 🚀 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 |
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
Tests
Bug Fixes