Thalhammer / jwt-cpp

A header only library for creating and validating json web tokens in c++
https://thalhammer.github.io/jwt-cpp/
MIT License
917 stars 243 forks source link

Ensure array_type has front() method + fix array_type on jsoncpp #361

Closed omar-mohamed-khallaf closed 1 week ago

omar-mohamed-khallaf commented 2 months ago

Replace front() with [0] in get_x5c_key_value as front is not supported by jsoncpp on array types.

prince-chrismc commented 2 months ago

Would it be possible to implement the missing function in the trait definition?

Extending,

https://github.com/Thalhammer/jwt-cpp/blob/83703d718a180b178bfecac0f12355358d04181b/include/jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h#L16

Also it seems we are missing this function as a requirement for the json array

https://github.com/Thalhammer/jwt-cpp/blob/83703d718a180b178bfecac0f12355358d04181b/include/jwt-cpp/jwt.h#L2459

omar-mohamed-khallaf commented 2 months ago

Is front() the missing function for the second issue, or something else?

prince-chrismc commented 2 months ago

Yes, front() Should be checked.

Might also be worth checking if the unit tests are missing a case 🤔 we just dint run the unit tests with JSON libraries https://github.com/Thalhammer/jwt-cpp/blob/83703d718a180b178bfecac0f12355358d04181b/.github/workflows/traits.yml#L59

Notes:

https://github.com/Thalhammer/jwt-cpp/blob/83703d718a180b178bfecac0f12355358d04181b/example/jwks-verify.cpp#L111 https://github.com/Thalhammer/jwt-cpp/blob/83703d718a180b178bfecac0f12355358d04181b/tests/JwksTest.cpp#L117

omar-mohamed-khallaf commented 2 months ago

Yes, front() Should be checked.

I added this line !std::is_same<decltype(std::declval<array_type>().front()), void>::value to is_valid_json_array, is it ok?

std::is_member_function_pointer had problems resolving the overloaded front function, and I had no idea how to solve it.

prince-chrismc commented 1 month ago

Looks like a type error in the Danieljson changes from the CI

omar-mohamed-khallaf commented 1 month ago

Something is wrong in the current implementation.

static object_type as_object(const json& val) {
    if (val.type() != jsoncons::json_type::object_value) throw std::bad_cast();
    return object_type(val.object_value());
}

static array_type as_array(const json& val) {
    if (val.type() != jsoncons::json_type::array_value) throw std::bad_cast();
    return val.array_value();
}

These two functions use val.object_value() and val.array_value(), but I can't find any reference to these functions in the jsoncons library.

omar-mohamed-khallaf commented 1 month ago

The problem existed before the current modifications. Should it be fixed in a new PR?