-
Notifications
You must be signed in to change notification settings - Fork 1
Description
ISSUE_NUMBER: GH-5
Description
The fetchCloudinaryFile function in src/controllers/GeminiChat/index.ts fetches data from a URL provided as input. If this URL is controlled by the user, it could potentially lead to an open redirect vulnerability.
File: repositories/chatgptapi/src/controllers/GeminiChat/index.ts
Line: 11
Severity: high
Current Behavior
The function fetches data from any URL without proper validation.
Expected Behavior
The function should validate the URL against a whitelist of allowed domains to prevent fetching data from arbitrary locations.
Suggested Fix
Implement URL validation in fetchCloudinaryFile to only allow fetching data from trusted domains (e.g., Cloudinary).
Code Context
const fetchCloudinaryFile = async (url: string): Promise<{ data: string; mimeType: string }> => {
try {
const cloudinaryUrl = new URL(url);
// ...
const response = await axios.get(cloudinaryUrl.toString(), {
responseType: 'arraybuffer',
timeout: 10000,
});
// ...
} catch (error) {
console.error(`Cloudinary fetch error: ${url}`, error);
throw new Error(`Failed to fetch Cloudinary file: ${url}`);
}
};Additional Notes
While Cloudinary URLs are likely trusted, it's still a good practice to validate the URL against a whitelist of allowed domains to prevent potential security risks.