Skip to content

Commit af88731

Browse files
committed
fix: Normalize HTTP method case in allowMethodOverride middleware
1 parent f05aca6 commit af88731

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

spec/RateLimit.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,36 @@ describe('rate limit', () => {
967967
});
968968
});
969969

970+
it('should enforce rate limit when _method override uses non-standard casing', async () => {
971+
Parse.Cloud.beforeLogin(() => {}, {
972+
rateLimit: {
973+
requestTimeWindow: 10000,
974+
requestCount: 1,
975+
errorResponseMessage: 'Too many requests',
976+
includeInternalRequests: true,
977+
},
978+
});
979+
await Parse.User.signUp('testuser', 'password');
980+
const res1 = await request({
981+
method: 'POST',
982+
headers,
983+
url: 'http://localhost:8378/1/login',
984+
body: JSON.stringify({ username: 'testuser', password: 'password' }),
985+
});
986+
expect(res1.data.username).toBe('testuser');
987+
// Second login via POST with _method:'get' (lowercase) — should still be rate limited
988+
const res2 = await request({
989+
method: 'POST',
990+
headers,
991+
url: 'http://localhost:8378/1/login',
992+
body: JSON.stringify({ _method: 'get', username: 'testuser', password: 'password' }),
993+
}).catch(e => e);
994+
expect(res2.data).toEqual({
995+
code: Parse.Error.CONNECTION_FAILED,
996+
error: 'Too many requests',
997+
});
998+
});
999+
9701000
it('should ignore _method override with non-string type', async () => {
9711001
await reconfigureServer({
9721002
rateLimit: [

src/middlewares.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export function allowMethodOverride(req, res, next) {
484484
if (req.method === 'POST' && req.body?._method) {
485485
if (typeof req.body._method === 'string') {
486486
req.originalMethod = req.method;
487-
req.method = req.body._method;
487+
req.method = req.body._method.toUpperCase();
488488
}
489489
delete req.body._method;
490490
}

0 commit comments

Comments
 (0)