mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🔓 refactor: Make Image URL Security Optional (#2415)
This commit is contained in:
parent
2cc580ba52
commit
fce7246ac1
4 changed files with 14 additions and 1 deletions
|
|
@ -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');
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue