Skip to content

Commit

Permalink
🔓 refactor: Make Image URL Security Optional (#2415)
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila authored Apr 14, 2024
1 parent 2cc580b commit fce7246
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion api/server/middleware/validateImageRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ const jwt = require('jsonwebtoken');
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) {
if (!req.app.locals.secureImageLinks) {
return next();
}

const refreshToken = req.headers.cookie ? cookies.parse(req.headers.cookie).refreshToken : null;
if (!refreshToken) {
logger.warn('[validateImageRequest] Refresh token not provided');
Expand Down
1 change: 1 addition & 0 deletions api/server/services/AppService.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const AppService = async (app) => {
fileStrategy,
fileConfig: config?.fileConfig,
interface: config?.interface,
secureImageLinks: config?.secureImageLinks,
paths,
...endpointLocals,
};
Expand Down
6 changes: 6 additions & 0 deletions docs/install/configuration/custom_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- **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
- **Key**: `fileConfig`
- **Type**: Object
Expand Down
1 change: 1 addition & 0 deletions packages/data-provider/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export const rateLimitSchema = z.object({
export const configSchema = z.object({
version: z.string(),
cache: z.boolean().optional().default(true),
secureImageLinks: z.boolean().optional(),
interface: z
.object({
privacyPolicy: z
Expand Down

0 comments on commit fce7246

Please sign in to comment.