Jenkins, the popular open-source automation server, has a vulnerability in Azure AD Plugin version 396.v86ce29279947 and earlier (excluding 378.380.v545b_1154b_3fb_). The issue is related to the usage of a non-constant time comparison function for verifying the equality of the provided and expected CSRF (Cross-Site Request Forgery) protection nonce. This vulnerability potentially allows attackers to use statistical methods to obtain a valid nonce, enabling them to bypass CSRF protection and perform unauthorized actions. This blog post details the exploit, provides a code snippet illustrating the issue, and discusses methods for mitigation.
Original Reference
- Jenkins Advisory
- CVE-2023-41935
Exploit Details
The vulnerability lies in the implementation of the CSRF protection nonce comparison function, which uses a non-constant time algorithm. The difference in time taken for different inputs can be used by attackers to gather information about the expected nonce value, allowing them to craft a valid nonce value and bypass the CSRF protection mechanism.
Code Snippet
In the affected versions of the Jenkins Azure AD Plugin, the vulnerable code can be found in the verifyNonce function:
private boolean verifyNonce(String provided, String expected) {
return provided.equals(expected);
}
The equals method is not constant-time, which can lead to timing attacks.
Mitigation
To fix this vulnerability, users should update the Azure AD Plugin to a version that uses a constant-time comparison function for verifying nonces. In the fixed version, the verifyNonce function should use a constant-time comparison algorithm, such as the one found in the Apache Commons Codec library:
import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;
//...
private boolean verifyNonce(String provided, String expected) {
return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, provided).hmac(expected);
}
The new verifyNonce implementation ensures that the comparison operation takes constant time, preventing attackers from exploiting timing differences to guess the valid nonce value.
Conclusion
CVE-2023-41935 highlights the importance of using constant-time algorithms when performing security-sensitive comparisons, especially in authentication-related mechanisms. Jenkins administrators should promptly update their Azure AD Plugin to a patched version to avoid potential CSRF attacks.
Timeline
Published on: 09/06/2023 13:15:10 UTC
Last modified on: 09/11/2023 17:54:37 UTC