Skip to content

fix: toJSONwithObjects leaks ParseACL instances when afterFind hooks modify objects with directAccess#10244

Open
yog27ray wants to merge 1 commit intoparse-community:alphafrom
yog27ray:fix/afterfind-acl-directaccess
Open

fix: toJSONwithObjects leaks ParseACL instances when afterFind hooks modify objects with directAccess#10244
yog27ray wants to merge 1 commit intoparse-community:alphafrom
yog27ray:fix/afterfind-acl-directaccess

Conversation

@yog27ray
Copy link
Contributor

@yog27ray yog27ray commented Mar 19, 2026

Issue

Closes #8473

When directAccess is enabled, toJSONwithObjects in src/triggers.js leaks live ParseACL instances into the response instead of plain JSON objects. This causes the client-side Parse SDK to throw:

TypeError: Tried to create an ACL with an invalid permission type.

The bug occurs when an afterFind hook modifies objects via .setACL() or .set(). Since ParseACL lacks _toFullJSON, the raw instance is assigned directly to the response JSON. With directAccess, the response bypasses HTTP serialization (JSON.stringify), so the ParseACL instance leaks through to ParseObject._finishFetch, which expects plain JSON.

Approach

In toJSONwithObjects, when a pending op value lacks _toFullJSON, check if it has a toJSON method and call it before assigning. This serializes SDK types like ParseACL and ParseGeoPoint to plain JSON — consistent with what object.toJSON() already does in the same function.

Change in src/triggers.js:198:

// Before
toJSON[key] = val;

// After
toJSON[key] = val && typeof val.toJSON === 'function' ? val.toJSON() : val;

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)

…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>
@parse-github-assistant
Copy link

parse-github-assistant bot commented Mar 19, 2026

🚀 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.

@parseplatformorg
Copy link
Contributor

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

Status Scan Engine 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.

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

Added test cases for afterFind hooks validating ACL serialization and preservation behavior. Updated toJSONwithObjects function to safely serialize pending values using toJSON() method when available, improving handling of objects lacking _toFullJSON.

Changes

Cohort / File(s) Summary
Test Coverage
spec/CloudCode.spec.js
Added two afterFind hook test cases: one validating toJSONwithObjects produces plain JSON ACL representation (not a Parse.ACL instance), and another testing ACL preservation with directAccess: true when hooks reapply ACL via setACL(getACL()).
Serialization Utility
src/triggers.js
Modified toJSONwithObjects to handle pending values more safely by preferring val.toJSON() over raw val when the method exists, with fallback to original value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • Moumouls
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main bug fix: toJSONwithObjects leaking ParseACL instances in afterFind hooks with directAccess enabled.
Description check ✅ Passed The pull request description is comprehensive and well-structured, covering all required template sections with clear issue identification, detailed approach explanation, and confirmation of completed tasks.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can customize the tone of the review comments and chat replies.

Configure the tone_instructions setting to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.60%. Comparing base (fbda4cb) to head (6a7755c).
⚠️ Report is 1 commits behind head on alpha.

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha   #10244   +/-   ##
=======================================
  Coverage   92.60%   92.60%           
=======================================
  Files         192      192           
  Lines       16358    16358           
  Branches      201      201           
=======================================
  Hits        15148    15148           
  Misses       1193     1193           
  Partials       17       17           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Error "Tried to create an ACL with an invalid permission type."

3 participants