Skip to content

fix: Incomplete JSON key escaping in PostgreSQL Increment on nested Object fields#10261

Merged
mtrezza merged 2 commits intoparse-community:alphafrom
mtrezza:fix/postgres-increment-json-key-escaping
Mar 20, 2026
Merged

fix: Incomplete JSON key escaping in PostgreSQL Increment on nested Object fields#10261
mtrezza merged 2 commits intoparse-community:alphafrom
mtrezza:fix/postgres-increment-json-key-escaping

Conversation

@mtrezza
Copy link
Member

@mtrezza mtrezza commented Mar 20, 2026

Issue

Incomplete JSON key escaping in PostgreSQL Increment on nested Object fields (GHSA-33gq-87fg-pf98)

@parse-github-assistant
Copy link

parse-github-assistant bot commented Mar 20, 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

parseplatformorg commented Mar 20, 2026

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 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7958e747-9e58-4fd4-9a17-905e19d8d0ac

📥 Commits

Reviewing files that changed from the base of the PR and between 0e5649e and 0c8c13c.

📒 Files selected for processing (1)
  • src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

📝 Walkthrough

Walkthrough

Adds JSON-string escaping for nested-object Increment keys in the Postgres storage adapter and updates PostgreSQL tests to assert that crafted sub-keys cannot create or modify unintended JSONB keys or bypass ACL/CLP protections.

Changes

Cohort / File(s) Summary
Postgres storage adapter change
src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Added escapeJsonString and applied two escaping variants (jsonSafeName, sqlSafeName) in Increment logic for nested JSONB keys to prevent JSON/SQL injection when building JSON literals vs. extracting values.
New injection tests
spec/PostgresStorageAdapter.spec.js
Added PostgreSQL-only test suite (~+210 lines) covering crafted sub-key names for Increment: verifies no unintended JSONB keys, respects CLP/ACL and protectedFields, and checks resulting stored values.
Vulnerability test updates
spec/vulnerabilities.spec.js
Adjusted two PostgreSQL tests to assert safe escaping behavior (no extra JSONB keys, no pg_sleep(3)-named key) rather than focusing on JSONB invalidation or execution timing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is empty and does not follow the required template structure with Issue, Approach, and Tasks sections. Provide a description including the Issue being fixed, the Approach taken, and Task checkboxes (especially for tests and security checks).
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: fixing incomplete JSON key escaping in PostgreSQL Increment operations on nested Object fields.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Adapters/Storage/Postgres/PostgresStorageAdapter.js`:
- Line 212: The escapeJsonString function currently only escapes backslashes and
quotes, leaving control characters like newline, carriage return and tabs
unescaped which can break the CONCAT-built JSON literal; update escapeJsonString
to also replace control characters (at minimum \n, \r, \t — and ideally \b and
\f) with their escaped sequences (e.g. \\n, \\r, \\t, \\b, \\f) using global
replacements so the produced string is a valid JSON string when inserted into
CONCAT('{"...":', ...)::jsonb; keep the existing backslash and quote escaping
and ensure the replacements run on the same input value in escapeJsonString.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 48172d9e-852e-47fa-9e29-e5f14b0645ac

📥 Commits

Reviewing files that changed from the base of the PR and between 12fdbd6 and 0e5649e.

📒 Files selected for processing (3)
  • spec/PostgresStorageAdapter.spec.js
  • spec/vulnerabilities.spec.js
  • src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.55%. Comparing base (2126fe4) to head (0c8c13c).
⚠️ Report is 5 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha   #10261      +/-   ##
==========================================
+ Coverage   84.38%   92.55%   +8.16%     
==========================================
  Files         192      192              
  Lines       16431    16433       +2     
  Branches      226      226              
==========================================
+ Hits        13866    15210    +1344     
+ Misses       2545     1203    -1342     
  Partials       20       20              

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

@mtrezza mtrezza merged commit a692873 into parse-community:alpha Mar 20, 2026
21 of 24 checks passed
parseplatformorg pushed a commit that referenced this pull request Mar 20, 2026
# [9.6.0-alpha.46](9.6.0-alpha.45...9.6.0-alpha.46) (2026-03-20)

### Bug Fixes

* Incomplete JSON key escaping in PostgreSQL Increment on nested Object fields ([#10261](#10261)) ([a692873](a692873))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 9.6.0-alpha.46

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

Labels

state:released-alpha Released as alpha version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants