The vulnerability analysis identified a privilege escalation flaw within the Gokapi application, specifically in the creation of API keys. The root cause was an improper access control vulnerability in the api.apiCreateApiKey function. The investigation began by examining the provided security advisory, which indicated that the vulnerability was patched in version 2.2.3. By comparing the git tags for versions 2.2.2 and 2.2.3, I identified the specific commit that contained the security fix. The commit message, "Added DISABLE_API_MENU env to hide API menu and disable generation of new API keys for non-admin users," directly pointed to the nature of the patch.
A detailed review of the code changes in this commit revealed that the api.apiCreateApiKey function in internal/webserver/api/Api.go was modified to include an authorization check. Previously, this function did not verify if the user making the request had the necessary permissions to create an API key. This allowed any authenticated user, regardless of their privilege level, to access this function and generate a new key. The exploit scenario involves a low-privileged user creating a key that could then be used to perform actions reserved for more privileged accounts, such as creating file requests. The patch introduces a check that prevents non-admin users from creating API keys when a new environment variable, GOKAPI_DISABLE_API_MENU, is set. This effectively closes the privilege escalation vector. Therefore, the api.apiCreateApiKey function is the primary vulnerable function that would appear in a runtime profile during exploitation.