Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Rate limit the /auth/login route of ETAPI
DynamoFoxb965f77f4a3f
diff --git a/src/etapi/auth.js b/src/etapi/auth.jsindex ad2cf12740..921c91d944 100644--- a/src/etapi/auth.js+++ b/src/etapi/auth.js@@ -3,8 +3,8 @@ const eu = require("./etapi_utils");const passwordEncryptionService = require("../services/password_encryption");const etapiTokenService = require("../services/etapi_tokens");-function register(router) {- eu.NOT_AUTHENTICATED_ROUTE(router, 'post', '/etapi/auth/login', (req, res, next) => {+function register(router, loginMiddleware) {+ eu.NOT_AUTHENTICATED_ROUTE(router, 'post', '/etapi/auth/login', loginMiddleware, (req, res, next) => {const {password, tokenName} = req.body;if (!passwordEncryptionService.verifyPassword(password)) {diff --git a/src/etapi/etapi.openapi.yaml b/src/etapi/etapi.openapi.yamlindex 1644e90bb3..47e8d22a8d 100644--- a/src/etapi/etapi.openapi.yaml+++ b/src/etapi/etapi.openapi.yaml@@ -602,6 +602,8 @@ paths:authToken:type: stringexample: Bc4bFn0Ffiok_4NpbVCDnFz7B2WU+pdhW8B5Ne3DiR5wXrEyqdjgRIsk=+ '429':+ description: Client IP has been blacklisted because too many requests (possibly failed authentications) were made within a short time frame, try again laterdefault:description: unexpected errorcontent:diff --git a/src/etapi/etapi_utils.js b/src/etapi/etapi_utils.jsindex e07fbb4da2..43bd0eee03 100644--- a/src/etapi/etapi_utils.js+++ b/src/etapi/etapi_utils.js@@ -66,8 +66,8 @@ function route(router, method, path, routeHandler) {router[method](path, checkEtapiAuth, (req, res, next) => processRequest(req, res, routeHandler, next, method, path));}-function NOT_AUTHENTICATED_ROUTE(router, method, path, routeHandler) {- router[method](path, (req, res, next) => processRequest(req, res, routeHandler, next, method, path));+function NOT_AUTHENTICATED_ROUTE(router, method, path, middleware, routeHandler) {+ router[method](path, ...middleware, (req, res, next) => processRequest(req, res, routeHandler, next, method, path));}function getAndCheckNote(noteId) {diff --git a/src/routes/routes.js b/src/routes/routes.jsindex b957139fee..f4cf9bdebe 100644--- a/src/routes/routes.js+++ b/src/routes/routes.js@@ -416,7 +416,7 @@ function register(app) {shareRoutes.register(router);- etapiAuthRoutes.register(router);+ etapiAuthRoutes.register(router, [loginRateLimiter]);etapiAppInfoRoutes.register(router);etapiAttributeRoutes.register(router);etapiBranchRoutes.register(router);