mirror of
https://github.com/strapi/strapi.git
synced 2025-09-01 04:42:58 +00:00
update path normalize to a cleaner implementation
This commit is contained in:
parent
4013ae7345
commit
9f1600ab5d
@ -1,7 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const utils = require('@strapi/utils');
|
const utils = require('@strapi/utils');
|
||||||
const { has, toLower } = require('lodash/fp');
|
const { isString, has, toLower } = require('lodash/fp');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const { RateLimitError } = utils.errors;
|
const { RateLimitError } = utils.errors;
|
||||||
|
|
||||||
@ -24,13 +25,9 @@ module.exports =
|
|||||||
const rateLimit = require('koa2-ratelimit').RateLimit;
|
const rateLimit = require('koa2-ratelimit').RateLimit;
|
||||||
|
|
||||||
const userEmail = toLower(ctx.request.body.email) || 'unknownEmail';
|
const userEmail = toLower(ctx.request.body.email) || 'unknownEmail';
|
||||||
let requestPath = toLower(ctx.request.path) || 'unknownPath';
|
const requestPath = isString(ctx.request.path)
|
||||||
|
? toLower(path.normalize(ctx.request.path))
|
||||||
if (requestPath.endsWith('/')) {
|
: 'invalidPath';
|
||||||
if (requestPath !== '/') {
|
|
||||||
requestPath = requestPath.slice(0, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadConfig = {
|
const loadConfig = {
|
||||||
interval: { min: 5 },
|
interval: { min: 5 },
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const utils = require('@strapi/utils');
|
const utils = require('@strapi/utils');
|
||||||
const { has, toLower } = require('lodash/fp');
|
const { isString, has, toLower } = require('lodash/fp');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const { RateLimitError } = utils.errors;
|
const { RateLimitError } = utils.errors;
|
||||||
|
|
||||||
@ -24,13 +25,9 @@ module.exports =
|
|||||||
const rateLimit = require('koa2-ratelimit').RateLimit;
|
const rateLimit = require('koa2-ratelimit').RateLimit;
|
||||||
|
|
||||||
const userIdentifier = toLower(ctx.request.body.email) || 'unknownIdentifier';
|
const userIdentifier = toLower(ctx.request.body.email) || 'unknownIdentifier';
|
||||||
let requestPath = toLower(ctx.request.path) || 'unknownPath';
|
const requestPath = isString(ctx.request.path)
|
||||||
|
? toLower(path.normalize(ctx.request.path))
|
||||||
if (requestPath.endsWith('/')) {
|
: 'invalidPath';
|
||||||
if (requestPath !== '/') {
|
|
||||||
requestPath = requestPath.slice(0, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadConfig = {
|
const loadConfig = {
|
||||||
interval: { min: 5 },
|
interval: { min: 5 },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user