Giter VIP home page Giter VIP logo

Comments (5)

redevill avatar redevill commented on June 2, 2024 1

Sorry was sick - catching up.
You are right, something not right. The Passport authenticate is set up in the middleware to be called with each request. This set up line is 36 mentioned above. I would not expect any Passport activity before this point. Trace shows otherwise.

from express-rate-limit.

nfriedly avatar nfriedly commented on June 2, 2024

Hum, that's confusing. Can you post the full stack trace it logs with the error?

The way the check works is that it looks for the string "Layer.handle [as handle_request]" in the stack trace. Perhaps that string is appearing for some reason? I'm not sure why it would be intermittent, though..

Also, as a workaround, you can disable that validation check:

    const publicAPIlimiter = rateLimit({
      windowMs: <someValue>,
      limit: <several allowed>,
      validate: {
        creationStack: false
      }
    });

    const authRateLimit = rateLimit({
      windowMs: <someSmallerValue>,
      limit: <SmallerLimit>,
      validate: {
        creationStack: false
      }
    });

from express-rate-limit.

redevill avatar redevill commented on June 2, 2024

Here is the stack.
Not sure why it indicates creation as part of the authentication, as the piece of code above is registered at start up time with the all the routes on the server. Those two are registered 2nd and 3rd respectively.

Thank you for your attention.
Et

ValidationError: express-rate-limit instance should be created at app initialization, not when responding to a request. See https://express-rate-limit.github.io/ERR_ERL_CREATED_IN_REQUEST_HANDLER/ for more information.
    at Object.creationStack (/home/ubuntu/dev/<appName>/node_modules/express-rate-limit/dist/index.cjs:308:13)
    at Object.wrappedValidations.<computed> [as creationStack] (/home/ubuntu/dev/<appName>/node_modules/express-rate-limit/dist/index.cjs:338:22)
    at rateLimit (/home/ubuntu/dev/<appName>/node_modules/express-rate-limit/dist/index.cjs:633:22)
    at new SecurityHandlers (/home/ubuntu/dev/<appName>/server/securityMiddleware/security.handlers.ts:20:39)
    at /home/ubuntu/dev/<appName>/server/routes.ts:36:7
    at Layer.handle [as handle_request] (/home/ubuntu/dev/<appName>/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/ubuntu/dev/<appName>/node_modules/express/lib/router/index.js:328:13)
    at /home/ubuntu/dev/<appName>/node_modules/express/lib/router/index.js:286:9
    at param (/home/ubuntu/dev/<appName>/node_modules/express/lib/router/index.js:365:14)
    at param (/home/ubuntu/dev/<appName>/node_modules/express/lib/router/index.js:376:14)
    at Function.process_params (/home/ubuntu/dev/<appName>/node_modules/express/lib/router/index.js:421:3)
    at next (/home/ubuntu/dev/<appName>/node_modules/express/lib/router/index.js:280:10)
    at SessionStrategy.strategy.pass (/home/ubuntu/dev/<appName>/node_modules/passport/lib/middleware/authenticate.js:346:9)
    at SessionStrategy.authenticate (/home/ubuntu/dev/<appName>/node_modules/passport/lib/strategies/session.js:75:10)
    at attempt (/home/ubuntu/dev/<appName>/node_modules/passport/lib/middleware/authenticate.js:369:16)
    at authenticate (/home/ubuntu/dev/<appName>/node_modules/passport/lib/middleware/authenticate.js:370:7) {
  code: 'ERR_ERL_CREATED_IN_REQUEST_HANDLER',
  help: 'https://express-rate-limit.github.io/ERR_ERL_CREATED_IN_REQUEST_HANDLER/'
}

from express-rate-limit.

nfriedly avatar nfriedly commented on June 2, 2024

What's at and around line 36 in your /home/ubuntu/dev/<appName>/server/routes.ts?

Also, I'm a little perplexed as to how passport's authenticate function is the last item in the stack trace - is it getting called in a setTimeout or process.nextTick or something along those lines?

from express-rate-limit.

nfriedly avatar nfriedly commented on June 2, 2024

Just checking back in, did you make any progress on this? If not, could you share the snippet of your routs.ts, around line 36?

from express-rate-limit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.