Skip to content

fix: Nested batch sub-requests cause unclear error#10371

Open
mtrezza wants to merge 2 commits intoparse-community:alphafrom
mtrezza:fix/nested-batch-request-rejection
Open

fix: Nested batch sub-requests cause unclear error#10371
mtrezza wants to merge 2 commits intoparse-community:alphafrom
mtrezza:fix/nested-batch-request-rejection

Conversation

@mtrezza
Copy link
Copy Markdown
Member

@mtrezza mtrezza commented Mar 31, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Prevent nested batch requests where any sub-request targets the batch endpoint; such requests now fail with HTTP 400 and return an error stating "nested batch requests are not allowed".
  • Tests

    • Added tests to verify rejection of nested batch requests both when they are the sole sub-request and when mixed with valid sub-requests.

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 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: d00f0aa8-0c71-459c-b2aa-2773b84f6d32

📥 Commits

Reviewing files that changed from the base of the PR and between e2595cf and dcdca3c.

📒 Files selected for processing (1)
  • src/batch.js
✅ Files skipped from review due to trivial changes (1)
  • src/batch.js

📝 Walkthrough

Walkthrough

Added validation to forbid nested batch sub-requests that target the /batch endpoint; tests added to assert the batch endpoint rejects such nested submissions with HTTP 400 and an explicit error message.

Changes

Cohort / File(s) Summary
Tests — nested batch requests
spec/batch.spec.js
Added a test suite with two cases asserting that batch requests containing sub-requests targeting /1/batch are rejected with HTTP 400 and error 'nested batch requests are not allowed'.
Batch handler validation
src/batch.js
Added a check during sub-request iteration to detect sub-requests whose resolved method is POST and routable path equals the batch endpoint, throwing a Parse.Error (INVALID_JSON) to reject nested batch requests before further processing.

Sequence Diagram(s)

(Skipped — change is a focused validation within the batch handler and does not introduce a multi-component sequential flow requiring visualization.)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author. The description template requires Issue, Approach, and Tasks sections. Add a comprehensive PR description following the template, including: an Issue section (describe or link the related issue), an Approach section (explain the changes made), and check off completed Tasks.
Engage In Review Feedback ❓ Inconclusive Assessment cannot be completed definitively without direct access to the GitHub PR page to verify review comments and user responses. Visit #10371 to review the Conversation and Files changed tabs for feedback engagement.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title begins with 'fix:' prefix as required and clearly describes the main change: preventing nested batch sub-requests with a clear error message.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Security Check ✅ Passed PR implements a legitimate security fix preventing nested batch requests with proper validation and comprehensive test coverage.

✏️ 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
Copy Markdown

@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

🧹 Nitpick comments (1)
spec/batch.spec.js (1)

856-911: Add one non-regression test for valid paths ending with batch.

This suite covers reject cases well, but it should also assert that a valid endpoint like POST /1/classes/batch is accepted, so the nested-batch guard stays scoped to /1/batch only.

✅ Suggested test addition
   describe('nested batch requests', () => {
+    it('does not reject valid non-batch endpoints that end with "batch"', async () => {
+      const result = await request({
+        method: 'POST',
+        url: 'http://localhost:8378/1/batch',
+        headers,
+        body: JSON.stringify({
+          requests: [
+            {
+              method: 'POST',
+              path: '/1/classes/batch',
+              body: { key: 'value' },
+            },
+          ],
+        }),
+      });
+      expect(result.data[0].success.objectId).toBeDefined();
+    });
+
     it('rejects sub-request that targets the batch endpoint', async () => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@spec/batch.spec.js` around lines 856 - 911, Add a non-regression test to the
existing "nested batch requests" suite that verifies a valid endpoint like POST
/1/classes/batch is accepted; update spec/batch.spec.js by adding an it(...)
that sends a POST to http://localhost:8378/1/classes/batch with headers and a
normal body (e.g., class object or query) and asserts the request resolves (not
rejected) and returns a 200/expected success response. Place this test alongside
the existing tests in the describe('nested batch requests') block so the
nested-batch guard (logic that checks requests to '/1/batch') is confirmed to
not block paths that simply end with "batch" such as '/1/classes/batch'.
🤖 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/batch.js`:
- Around line 81-83: The current guard rejects any POST sub-request whose path
endsWith(batchPath), which incorrectly blocks routes like /1/classes/batch;
change the condition to only reject when the path is exactly the batch route.
Replace the endsWith check with an equality check (e.g., restRequest.path ===
batchPath) in the same block where restRequest and batchPath are used so only
true /batch requests are treated as nested-batch and throw the Parse.Error.

---

Nitpick comments:
In `@spec/batch.spec.js`:
- Around line 856-911: Add a non-regression test to the existing "nested batch
requests" suite that verifies a valid endpoint like POST /1/classes/batch is
accepted; update spec/batch.spec.js by adding an it(...) that sends a POST to
http://localhost:8378/1/classes/batch with headers and a normal body (e.g.,
class object or query) and asserts the request resolves (not rejected) and
returns a 200/expected success response. Place this test alongside the existing
tests in the describe('nested batch requests') block so the nested-batch guard
(logic that checks requests to '/1/batch') is confirmed to not block paths that
simply end with "batch" such as '/1/classes/batch'.
🪄 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: 63054783-7667-4566-afba-bb855f432252

📥 Commits

Reviewing files that changed from the base of the PR and between 82edbd7 and e2595cf.

📒 Files selected for processing (2)
  • spec/batch.spec.js
  • src/batch.js

@mtrezza
Copy link
Copy Markdown
Member Author

mtrezza commented Mar 31, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.52%. Comparing base (82edbd7) to head (dcdca3c).

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha   #10371   +/-   ##
=======================================
  Coverage   92.52%   92.52%           
=======================================
  Files         192      192           
  Lines       16566    16568    +2     
  Branches      231      231           
=======================================
+ Hits        15327    15329    +2     
  Misses       1217     1217           
  Partials       22       22           

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

1 participant