Closed jpeterse closed 4 years ago
Yeah this was a big one @jpeterse , thank you very much for pointing this out. I fixed it with https://github.com/timonson/djwt/commit/ae0ec9d1146634e60c29572518d52f1b86e69235 and I would love to hear your opinion about this.
The default implementation, and the default examples provided, results in insecure implementation.
Since algorithm of "none" is a value algorithm, and the validation method by default is using the algorithm specified within the token itself, an attack will succeed, if a token is send without signature and algorithm of "none". This would allow access to the protected resources at any time, by generating tokens on the fly with algorithm "none", even if the original token was generated with HS256 or RS256 signature.
The validation function should be changed to always require an array of allowed algorithms as a required parameter. For a even more secure implementation, separate validation methods should be made available, one for each supported algorithm.
Prof of concept of the attack. The code below generates two tokens. One generated by makeJwt on the server, and one that could easily be generated locally by encoding a hacked payload and header. Submit each token to the server, and the server will respond with "Valid JWT' in both cases.