Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions spec/batch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,4 +852,61 @@ describe('batch', () => {
expect(result.data).toEqual(jasmine.any(Array));
});
});

describe('nested batch requests', () => {
it('rejects sub-request that targets the batch endpoint', async () => {
await expectAsync(
request({
method: 'POST',
url: 'http://localhost:8378/1/batch',
headers,
body: JSON.stringify({
requests: [
{
method: 'POST',
path: '/1/batch',
body: {
requests: [{ method: 'GET', path: '/1/classes/TestClass' }],
},
},
],
}),
})
).toBeRejectedWith(
jasmine.objectContaining({
status: 400,
data: jasmine.objectContaining({
error: 'nested batch requests are not allowed',
}),
})
);
});

it('rejects when any sub-request among valid ones targets the batch endpoint', async () => {
await expectAsync(
request({
method: 'POST',
url: 'http://localhost:8378/1/batch',
headers,
body: JSON.stringify({
requests: [
{ method: 'GET', path: '/1/classes/TestClass' },
{
method: 'POST',
path: '/1/batch',
body: { requests: [{ method: 'GET', path: '/1/classes/TestClass' }] },
},
],
}),
})
).toBeRejectedWith(
jasmine.objectContaining({
status: 400,
data: jasmine.objectContaining({
error: 'nested batch requests are not allowed',
}),
})
);
});
});
});
3 changes: 3 additions & 0 deletions src/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ async function handleBatch(router, req) {
if (!restRequest || typeof restRequest !== 'object' || typeof restRequest.path !== 'string') {
throw new Parse.Error(Parse.Error.INVALID_JSON, 'batch request path must be a string');
}
if (restRequest.method === 'POST' && restRequest.path.endsWith(batchPath)) {
throw new Parse.Error(Parse.Error.INVALID_JSON, 'nested batch requests are not allowed');
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

// The batch paths are all from the root of our domain.
Expand Down
Loading