mirror of
https://github.com/parse-community/parse-server
synced 2026-08-09 13:03:18 +00:00
fix: Nested batch sub-requests cause unclear error (#10371)
This commit is contained in:
@@ -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',
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,6 +101,9 @@ async function handleBatch(router, req) {
|
||||
const rateLimits = req.config.rateLimits || [];
|
||||
for (const restRequest of req.body.requests) {
|
||||
const routablePath = makeRoutablePath(restRequest.path);
|
||||
if ((restRequest.method || 'GET').toUpperCase() === 'POST' && routablePath === batchPath) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'nested batch requests are not allowed');
|
||||
}
|
||||
for (const limit of rateLimits) {
|
||||
const pathExp = limit.path.regexp || limit.path;
|
||||
if (!pathExp.test(routablePath)) {
|
||||
|
||||
Reference in New Issue
Block a user