Skip to content

Commit

Permalink
A dep update (#2021)
Browse files Browse the repository at this point in the history
* Retested list with rate-limiting ... returned 429 as expected
* Minimal used end-user changes since 5.x verified in CHANGELOGs... changes needed applied.

Auto-merge
  • Loading branch information
Martii authored Nov 20, 2023
1 parent bdd5cb1 commit 73bbb39
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"express": "4.18.2",
"express-hcaptcha": "git+https://github.com/OpenUserJS/express-hcaptcha.git#forkUpdate",
"express-minify": "1.0.0",
"express-rate-limit": "5.5.1",
"express-rate-limit": "7.1.4",
"express-session": "1.17.3",
"express-svg-captcha": "1.0.1",
"font-awesome": "4.7.0",
Expand Down
30 changes: 15 additions & 15 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ var installCapLimiter = rateLimit({
handler: function (aReq, aRes, aNext, aOptions) {
var cmd = null;

if (aReq.rateLimit.current < aReq.rateLimit.limit + 4) {
if (aReq.rateLimit.used < aReq.rateLimit.limit + 4) {
// Midddlware options
if (!aRes.oujsOptions) {
aRes.oujsOptions = {};
}

aRes.oujsOptions.showReminderInstallLimit = 4 - (aReq.rateLimit.current - aReq.rateLimit.limit);
aRes.oujsOptions.showReminderInstallLimit = 4 - (aReq.rateLimit.used - aReq.rateLimit.limit);

aNext();
} else if (aReq.rateLimit.current < aReq.rateLimit.limit + 10) {
} else if (aReq.rateLimit.used < aReq.rateLimit.limit + 10) {
aRes.header('Retry-After', waitInstallCapMin * 60 + (isDev ? fudgeSec : fudgeMin));
statusCodePage(aReq, aRes, aNext, {
statusCode: 429,
Expand All @@ -84,10 +84,10 @@ var installCapLimiter = rateLimit({
retryAfter: waitInstallCapMin * 60 + (isDev ? fudgeSec : fudgeMin)
}
});
} else if (aReq.rateLimit.current < aReq.rateLimit.limit + 15) {
} else if (aReq.rateLimit.used < aReq.rateLimit.limit + 15) {
aRes.header('Retry-After', waitInstallCapMin * 60 + (isDev ? fudgeSec : fudgeMin));
aRes.status(429).send('Too many requests. Please try again later');
} else if (aReq.rateLimit.current < aReq.rateLimit.limit + 25) {
} else if (aReq.rateLimit.used < aReq.rateLimit.limit + 25) {
aRes.header('Retry-After', waitInstallCapMin * 60 + (isDev ? fudgeSec : fudgeMin));
aRes.status(429).send();
} else {
Expand Down Expand Up @@ -129,7 +129,7 @@ var installRateLimiter = rateLimit({
handler: function (aReq, aRes, aNext, aOptions) {
aRes.header('Retry-After', waitRateInstallSec + (isDev ? fudgeSec : fudgeMin));
if (isSameOrigin(aReq.get('Referer')).result) {
if (aReq.rateLimit.current <= aReq.rateLimit.limit + 2) {
if (aReq.rateLimit.used <= aReq.rateLimit.limit + 2) {
statusCodePage(aReq, aRes, aNext, {
statusCode: 429,
statusMessage: 'Too many requests.',
Expand Down Expand Up @@ -177,7 +177,7 @@ var metaRateLimiter = rateLimit({
handler: function (aReq, aRes, aNext, aOptions) {
aRes.header('Retry-After', waitRateMetaSec + (isDev ? fudgeSec : fudgeMin));
if (isSameOrigin(aReq.get('Referer')).result) {
if (aReq.rateLimit.current <= aReq.rateLimit.limit + 2) {
if (aReq.rateLimit.used <= aReq.rateLimit.limit + 2) {
statusCodePage(aReq, aRes, aNext, {
statusCode: 429,
statusMessage: 'Too many requests.',
Expand Down Expand Up @@ -303,16 +303,16 @@ var listCapLimiter = rateLimit({
handler: function (aReq, aRes, aNext, aOptions) {
var cmd = null;

if (aReq.rateLimit.current < aReq.rateLimit.limit + 4) {
if (aReq.rateLimit.used < aReq.rateLimit.limit + 4) {
// Midddlware options
if (!aRes.oujsOptions) {
aRes.oujsOptions = {};
}

aRes.oujsOptions.showReminderListLimit = 4 - (aReq.rateLimit.current - aReq.rateLimit.limit);
aRes.oujsOptions.showReminderListLimit = 4 - (aReq.rateLimit.used - aReq.rateLimit.limit);

aNext();
} else if (aReq.rateLimit.current < aReq.rateLimit.limit + 10) {
} else if (aReq.rateLimit.used < aReq.rateLimit.limit + 10) {
aRes.header('Retry-After', waitListCapMin * 60 + (isDev ? fudgeSec : fudgeMin));
statusCodePage(aReq, aRes, aNext, {
statusCode: 429,
Expand All @@ -324,10 +324,10 @@ var listCapLimiter = rateLimit({
retryAfter: waitListCapMin * 60 + (isDev ? fudgeSec : fudgeMin)
}
});
} else if (aReq.rateLimit.current < aReq.rateLimit.limit + 15) {
} else if (aReq.rateLimit.used < aReq.rateLimit.limit + 15) {
aRes.header('Retry-After', waitListCapMin * 60 + (isDev ? fudgeSec : fudgeMin));
aRes.status(429).send('Too many requests. Please try again later');
} else if (aReq.rateLimit.current < aReq.rateLimit.limit + 25) {
} else if (aReq.rateLimit.used < aReq.rateLimit.limit + 25) {
aRes.header('Retry-After', waitListCapMin * 60 + (isDev ? fudgeSec : fudgeMin));
aRes.status(429).send();
} else {
Expand Down Expand Up @@ -364,7 +364,7 @@ var listRateLimiter = rateLimit({
max: 1, // limit each IP to n requests per windowMs for memory store or expireTimeMs for mongo store
handler: function (aReq, aRes, aNext, aOptions) {
aRes.header('Retry-After', waitListRateSec + fudgeSec);
if (aReq.rateLimit.current <= aReq.rateLimit.limit + 1) {
if (aReq.rateLimit.used <= aReq.rateLimit.limit + 1) {
statusCodePage(aReq, aRes, aNext, {
statusCode: 429,
statusMessage: 'Too many requests.',
Expand Down Expand Up @@ -408,7 +408,7 @@ var listAnyQRateLimiter = rateLimit({
max: 1, // limit each IP to n requests per windowMs for memory store or expireTimeMs for mongo store
handler: function (aReq, aRes, aNext, aOptions) {
aRes.header('Retry-After', waitListAnyQRateSec + fudgeSec);
if (aReq.rateLimit.current <= aReq.rateLimit.limit + 2) {
if (aReq.rateLimit.used <= aReq.rateLimit.limit + 2) {
statusCodePage(aReq, aRes, aNext, {
statusCode: 429,
statusMessage: 'Too many requests.',
Expand Down Expand Up @@ -448,7 +448,7 @@ var listSameQRateLimiter = rateLimit({
max: 1, // limit each IP to n requests per windowMs for memory store or expireTimeMs for mongo store
handler: function (aReq, aRes, aNext, aOptions) {
aRes.header('Retry-After', waitListSameQCapMin * 60 + (isDev ? fudgeSec : fudgeMin));
if (aReq.rateLimit.current <= aReq.rateLimit.limit + 2) {
if (aReq.rateLimit.used <= aReq.rateLimit.limit + 2) {
statusCodePage(aReq, aRes, aNext, {
statusCode: 429,
statusMessage: 'Too many requests.',
Expand Down

0 comments on commit 73bbb39

Please sign in to comment.