🔓 refactor: Make Image URL Security Optional (#2415)

This commit is contained in:
Danny Avila 2024-04-14 19:34:13 -04:00 committed by GitHub
parent 2cc580ba52
commit fce7246ac1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 1 deletions

View file

@ -3,9 +3,14 @@ const jwt = require('jsonwebtoken');
const { logger } = require('~/config'); const { logger } = require('~/config');
/** /**
* Middleware to validate image request * Middleware to validate image request.
* Must be set by `secureImageLinks` via custom config file.
*/ */
function validateImageRequest(req, res, next) { function validateImageRequest(req, res, next) {
if (!req.app.locals.secureImageLinks) {
return next();
}
const refreshToken = req.headers.cookie ? cookies.parse(req.headers.cookie).refreshToken : null; const refreshToken = req.headers.cookie ? cookies.parse(req.headers.cookie).refreshToken : null;
if (!refreshToken) { if (!refreshToken) {
logger.warn('[validateImageRequest] Refresh token not provided'); logger.warn('[validateImageRequest] Refresh token not provided');

View file

@ -180,6 +180,7 @@ const AppService = async (app) => {
fileStrategy, fileStrategy,
fileConfig: config?.fileConfig, fileConfig: config?.fileConfig,
interface: config?.interface, interface: config?.interface,
secureImageLinks: config?.secureImageLinks,
paths, paths,
...endpointLocals, ...endpointLocals,
}; };

View file

@ -203,6 +203,12 @@ This example configuration file sets up LibreChat with detailed options across s
- **Description**: Determines where to save user uploaded/generated files. Defaults to `"local"` if omitted. - **Description**: Determines where to save user uploaded/generated files. Defaults to `"local"` if omitted.
- **Example**: `fileStrategy: "firebase"` - **Example**: `fileStrategy: "firebase"`
### Image Links
- **Key**: `secureImageLinks`
- **Type**: Boolean
- **Description**: Whether or not to secure access to image links that are hosted locally by the app. Default: false.
- **Example**: `secureImageLinks: true`
### File Configuration ### File Configuration
- **Key**: `fileConfig` - **Key**: `fileConfig`
- **Type**: Object - **Type**: Object

View file

@ -189,6 +189,7 @@ export const rateLimitSchema = z.object({
export const configSchema = z.object({ export const configSchema = z.object({
version: z.string(), version: z.string(),
cache: z.boolean().optional().default(true), cache: z.boolean().optional().default(true),
secureImageLinks: z.boolean().optional(),
interface: z interface: z
.object({ .object({
privacyPolicy: z privacyPolicy: z