Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions config/rateLimit/rateLimiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ module.exports = {
return true;
}

// Removing an entrance from a user's exploration list is a low-risk
// self-service action (tokenAuth already ensures ownership). Skip the
// restrictive DELETE rate limit so users can freely manage their list.
if (/^\/api\/v1\/entrances\/\d+\/cavers\/\d+$/.test(req.path)) {
return true;
}

// Third-party origins are always limited (handled by generalRateLimit)
if (req.token && req.headers.origin !== sails.config.custom.baseUrl) {
sails.log.error(
Expand Down
16 changes: 16 additions & 0 deletions test/integration/2_utils/rateLimiter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,22 @@ describe('Rate Limiter', () => {
await agent.delete('/test').expect(200);
}
});

it('should skip rate limiting for explored entrance DELETE route', async () => {
const rateLimiter = freshRateLimiter();
const app = express();
app.use(rateLimiter.deleteRateLimit);
app.delete(
'/api/v1/entrances/:entranceId/cavers/:caverId',
(req, res) => res.status(200).send('ok')
);

const agent = supertest.agent(app);
// Send more than the user delete limit β€” all should pass
for (let i = 0; i < TEST_USER_DELETE_LIMIT + 5; i += 1) {
await agent.delete('/api/v1/entrances/42/cavers/7').expect(200);
}
});
});
});
});