-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
CWE-331 in DigestAuthentication class #5053
Comments
Adding direct link to line 221 in the reported version 9.4.30 (for reference by future readers of this issue) ... |
@mslowiak Thanks for that report. It is not actually a security issue because the nonce used in DIGEST auth is just there to prevent replay attacks and doesn't need to be strong. In fact some common implementations just use the system time! However, we will make sure that our next release (out in a week or two) will use an algorithm that wont be flagged by Veracode. |
@gregw Thank you for fast check and willing to fix that :-) |
@gregw the PR is wrong as |
The apidoc for Also, the Java 9+ version of the SecureRandom javadoc says ...
|
Okay I learnt that But now it becomes a global contended lock, like the javadocs of I still think it should be reverted to allocating rather than contending a |
Plus, I think it should be benchmarked since the PR changed the use of |
Benchmarking SecureRandom can be difficult because it relies on a good sources of entropy like doing actual network traffic. A micro benchmark will quickly exhaust entropy because it is not having real interactions with real random sources. Using SecureRandom for digest auth is a good match because there is network traffic associated with every use, so there is entropy provided. Creating a temporary Random using it and then disposing of it was always a bad thing to do. Not only is it a source of needless garbage but it essentially makes your random numbers a function of (nanotime), rather than a function of (nanotime, previous requests). This makes them a lot easier to predict... at least reduces the search space. Creating a SecureRandom to discard is even worse as it does provider searches and I believe seeding can consumes more entropy than nextBytes, so that is just a bad idea. If we see contention on SecureRandom then we can create a pool of threadlocal ones.. or a pool of Randoms that are regularly seeded from a shared SecureRandom.... or something similar, but I would not be surprised if the providers already do something like that under the hood. |
Allow random to be passed in and can default to a weak pseudo random.
@sbordet @joakime @lorban Due to me being a heavy handed idiot, I just committed f6d3984 to jetty-9.4.x head. The default of digest is to use SecureRandom. Please have a look as see review in situ... if you don't like I'll roll back and make a PR. |
Copying my comments on the commit into here for reference at a later date. Regarding pseudo random on multipart boundary lines ... This pseudo random isn't sufficient for client multipart boundary. See similar discussion at firefox about this as well ...
In short, it needs to be using SecureRandom (like it was before). The only change this file needs is to remove the Regarding WebSocket client to server masking ... According to the WebSocket Protocol Spec.
This MUST be derived from SecureRandom. |
Signed-off-by: Joakim Erdfelt <[email protected]>
I added a simple jmh test for the various SecureRandom algorithms to a new branch . |
@joakime while I don't think micro benchmarks for random are going to be fair to any that wait for sufficient entropy, your results do indicate that there does not appear to be any significant problems with contention. The rate of random number production is not affected (good or bad) by thread count. |
@joakime the multipart boundary problem is only a problem for browsers, as the state of the random number generator can be determined and then future boundaries used to track users. |
Jetty version
jetty-client-9.4.30.v20200611
Java version
Java 11
OS type/version
Windows
Description
We are using the Wiremock standalone version (the newest com.github.tomakehurst:wiremock-jre8-standalone:2.27.1) with jetty-client-9.4.30.v20200611 included.
Veracode scan complains about CWE-331 located in DigestAuthentication in line 221 which contains code:
The text was updated successfully, but these errors were encountered: