Skip to content

Commit b8ee819

Browse files
committed
fix: Maintenance key IP mismatch silently downgrades to regular auth instead of rejecting
1 parent 5323b08 commit b8ee819

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

spec/Middlewares.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,31 @@ describe('middlewares', () => {
186186
);
187187
});
188188

189+
it_id('5b8b9280-53ec-445a-b868-6992931d2236')(it)('should reject maintenance key from non-allowed IP instead of downgrading to anonymous auth', async () => {
190+
await reconfigureServer({
191+
maintenanceKeyIps: ['10.0.0.1'],
192+
});
193+
const logger = require('../lib/logger').logger;
194+
spyOn(logger, 'error').and.callFake(() => {});
195+
AppCachePut(fakeReq.body._ApplicationId, {
196+
maintenanceKey: 'maintenanceKey',
197+
maintenanceKeyIps: ['10.0.0.1'],
198+
masterKey: 'masterKey',
199+
masterKeyIps: ['0.0.0.0/0', '::0'],
200+
});
201+
fakeReq.ip = '127.0.0.1';
202+
fakeReq.headers['x-parse-maintenance-key'] = 'maintenanceKey';
203+
204+
const error = await middlewares.handleParseHeaders(fakeReq, fakeRes, () => {}).catch(e => e);
205+
206+
expect(error).toBeDefined();
207+
expect(error.status).toBe(403);
208+
expect(error.message).toEqual('unauthorized');
209+
expect(logger.error).toHaveBeenCalledWith(
210+
`Request using maintenance key rejected as the request IP address '127.0.0.1' is not set in Parse Server option 'maintenanceKeyIps'.`
211+
);
212+
});
213+
189214
it_id('2f7fadec-a87c-4626-90d1-65c75653aea9')(it)('should succeed if the ip does belong to masterKeyIps list', async () => {
190215
AppCachePut(fakeReq.body._ApplicationId, {
191216
masterKey: 'masterKey',

src/middlewares.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ async function resolveKeyAuth({ config, keyValue, maintenanceKeyValue, installat
454454
log.error(
455455
`Request using maintenance key rejected as the request IP address '${clientIp}' is not set in Parse Server option 'maintenanceKeyIps'.`
456456
);
457+
const error = new Error();
458+
error.status = 403;
459+
error.message = 'unauthorized';
460+
throw error;
457461
}
458462
const masterKey = await config.loadMasterKey();
459463
if (keyValue === masterKey) {

0 commit comments

Comments
 (0)