Coder Social home page Coder Social logo

Comments (5)

mxstbr avatar mxstbr commented on June 30, 2024 2

Thanks for double-checking my work, I had missed that nuance. Fixed in v1.0.11!

from passport-magic-login.

mxstbr avatar mxstbr commented on June 30, 2024 1

Published the second idea in v1.0.10. I appreciate the detailed writeup and suggestions @lukasz-wronski!

from passport-magic-login.

mxstbr avatar mxstbr commented on June 30, 2024

Thank you for the careful read of the source; I agree that this isn't an optimal implication of the API design. (even though I wish that JS-based ORMs handled this properly 😬)

Do you think something like if (!payload.destination) throw new Error('Please provide a destination') would solve this potential hazard?

from passport-magic-login.

lukasz-wronski avatar lukasz-wronski commented on June 30, 2024

Hey @mxstbr, thanks for quick reaction. In fact this is discovery was made with a real system I was pentesting. Developers were confident the links are verified correctly and I've managed to login as a random user just by messing the token up.

Regarding the code change. In my opinion it would be best to catch it as soon as possible adding this exception right inside the decodeToken function. In example like this:

export const decodeToken = (secret: string, token?: string) => {
  try {
    return jwt.verify(token, secret) as JwtPayload;
  } catch (err) {
    throw new Error('JWT incorrect or missing');
  }
};

Please note that if (typeof token !== 'string') you have now is redundant as jsonwebtoken library already checks this in the line below:

https://github.com/auth0/node-jsonwebtoken/blob/74d5719bd03993fcf71e3b176621f133eb6138c0/verify.js#L56

I think it's safe to just put anything into jwt.verify and rely on @auth0 to have all these checks implemented correctly.

If you want to make it even simplier you can make decodeToken to directly call jwt.verify and do no try..catch wrapping. Then your users will get more detailed error about the problem with the JWT provided. Your choice, both options seem to be right.

Let me know if I can assist you further.

from passport-magic-login.

lukasz-wronski avatar lukasz-wronski commented on June 30, 2024

@mxstbr One thing that I can see you've left the if (typeof token !== 'string') and it's still working the same way as before in case I'm not adding ?token in query string. Undefined is not a string so it returns false. It still needs to be fixed.

from passport-magic-login.

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.