Coder Social home page Coder Social logo

Comments (3)

adamjmcgrath avatar adamjmcgrath commented on July 20, 2024 1

Hi @aMahanna, thanks for raising this.

Your example is nearly right, you just need to execute the middleware with the request context jwtAuthz((...])(req, res, next).

However, I don't think this is a good idea, mainly from a security point of view. For example if multiple scopes are provided, the user only needs one of the specified scopes to access to route. If I had scope a and not b - I might be able to trick your route handler into giving me access to a by providing both a and b eg. /a%20b. I know in your current configuration this wouldn't be possible, but you can imagine some fairly innocent changes to the SDK or your code that might trigger a vulnerability.

It's always better to rely on server configuration rather than user input to configure security features on your server.

There's also usually a performance penalty to initialising a new instance of middleware on every request, since lots of middleware will likely cache work in memory to use across requests.

If you want to shorten your code you could maybe try something like:

for (const route of ['a', 'b', 'c']):
  app.get('/' + route,
   jwtAuthz(['read:' + route]),
   ...
);

from express-jwt-authz.

aMahanna avatar aMahanna commented on July 20, 2024 1

@adamjmcgrath thank you! and no worries on the delay

from express-jwt-authz.

adamjmcgrath avatar adamjmcgrath commented on July 20, 2024

(also apologies for the long delay in replying)

from express-jwt-authz.

Related Issues (18)

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.