The vulnerability is a stored Cross-Site Scripting (XSS) issue in the 'friendly name' field for API keys. Authenticated users could inject JavaScript by renaming an API key's friendly name. This injected script would then execute in the browser of any user viewing the API key overview page.
The root cause lies in the unsafe use of innerHTML in the JavaScript code responsible for handling and displaying these friendly names.
-
Injection Point: The addFriendlyNameChange function in internal/webserver/web/static/js/admin_ui_api.js was directly responsible for the injection. When a user edited a friendly name, the new name (newName) was taken from an input field and then written back to the table cell using cell.innerHTML = newName;. This allowed arbitrary HTML and JavaScript to be injected and rendered immediately in the editor's view, and then saved to the server via apiAuthFriendlyName.
-
Stored XSS Trigger: The addRowApi function in the same file is responsible for generating and displaying the list of API keys in a table. When this table was rendered, if a stored friendly name contained malicious JavaScript, and if addRowApi used innerHTML to display this name, the script would execute in the context of any user viewing the page. The patch extensively refactors addRowApi to use safer methods like innerText and document.createElement for rendering cell content, indicating that this function was also a critical part of the vulnerability display and mitigation.
The patch addresses these issues by replacing innerHTML assignments with innerText where user-controlled or dynamic data is displayed. innerText treats the content as plain text, preventing HTML or script injection. Additionally, dynamic HTML elements (like buttons) are now created using DOM manipulation methods (document.createElement, appendChild, etc.) rather than string concatenation with innerHTML, which is a more secure practice.
Therefore, both addFriendlyNameChange (for input and immediate rendering of the malicious name) and addRowApi (for displaying the stored malicious name to other users) are key functions related to this vulnerability.