mirror of
https://github.com/immich-app/immich.git
synced 2026-03-26 20:00:44 +03:00
fix: validate accept header before returning html (#27019)
This commit is contained in:
@@ -81,7 +81,7 @@ export const connect = async (url: string, key: string) => {
|
|||||||
|
|
||||||
const [error] = await withError(getMyUser());
|
const [error] = await withError(getMyUser());
|
||||||
if (isHttpError(error)) {
|
if (isHttpError(error)) {
|
||||||
logError(error, 'Failed to connect to server');
|
logError(error, `Failed to connect to server ${url}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, NotAcceptableException } from '@nestjs/common';
|
||||||
import { Interval } from '@nestjs/schedule';
|
import { Interval } from '@nestjs/schedule';
|
||||||
import { NextFunction, Request, Response } from 'express';
|
import { NextFunction, Request, Response } from 'express';
|
||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
@@ -72,6 +72,13 @@ export class ApiService {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const responseType = request.accepts('text/html');
|
||||||
|
if (!responseType) {
|
||||||
|
throw new NotAcceptableException(
|
||||||
|
`The route ${request.path} was requested as ${request.header('accept')}, but only returns text/html`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let status = 200;
|
let status = 200;
|
||||||
let html = index;
|
let html = index;
|
||||||
|
|
||||||
@@ -105,7 +112,7 @@ export class ApiService {
|
|||||||
html = render(index, meta);
|
html = render(index, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(status).type('text/html').header('Cache-Control', 'no-store').send(html);
|
res.status(status).type(responseType).header('Cache-Control', 'no-store').send(html);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user