Conversation
|
If I recall the reasoning correctly, the libsodium function does not work correctly and as intended when comparing different length values, and no such function exists within libsodium. |
|
Right, |
|
Oof, good catch. Pretty rough that they don't mention this in their docs. Comparing passwords in constant time is very common, but in DG there's a bit of friction because it has the secret in cleartext. Usually a backend would store hashes of passwords and hash the incoming password before comparing both. Still, I think we can use their pwhash API. DG would simply store the result of Let me try this approach before giving up. |
…f the pwhash API and sodium_memcmp
| } | ||
| if (!datum_secure_strequals(datum_config.api_csrf_token, sizeof(datum_config.api_csrf_token)-1, json_string_value(j_csrf))) { | ||
| const char * const csrf_s = json_string_value(j_csrf); | ||
| if ((strlen(csrf_s) == sizeof(datum_config.api_csrf_token)-1) && 0 != sodium_memcmp(datum_config.api_csrf_token, json_string_value(j_csrf), sizeof(datum_config.api_csrf_token)-1)) { |
There was a problem hiding this comment.
This length check before calling sodium_memcmp should not leak any information because the length of CSRF tokens is already public (64 bytes).
The DATUM gateway already depends on libsodium, and it has a constant-time comparison function. This other PR sounds like the sort of thing that we shouldn't be even thinking about in this repo.
Tested in my own DATUM deployment.