Absolutely no leak for media proxies

This commit is contained in:
ゆめ 2024-10-19 00:44:43 -05:00
parent 0bc96fb197
commit ec060b7a14
No known key found for this signature in database

View file

@ -292,7 +292,7 @@ export class FileServerService {
@bindThis
private async proxyHandler(request: FastifyRequest<{ Params: { url: string; }; Querystring: { url?: string; }; }>, reply: FastifyReply) {
const url = 'url' in request.query ? request.query.url : 'https://' + request.params.url;
let url = 'url' in request.query ? request.query.url : 'https://' + request.params.url;
if (typeof url !== 'string') {
reply.code(400);
@ -300,23 +300,27 @@ export class FileServerService {
}
// アバタークロップなど、どうしてもオリジンである必要がある場合
const mustOrigin = 'origin=1' in request.query;
const mustOrigin = 'origin' in request.query;
if (this.config.externalMediaProxyEnabled && !mustOrigin) {
if (this.config.externalMediaProxyEnabled) {
// 外部のメディアプロキシが有効なら、そちらにリダイレクト
reply.header('Cache-Control', 'public, max-age=259200'); // 3 days
const url = new URL(`${this.config.mediaProxy}/${request.params.url || ''}`);
const externalURL = new URL(`${this.config.mediaProxy}/${request.params.url || ''}`);
for (const [key, value] of Object.entries(request.query)) {
url.searchParams.append(key, value);
externalURL.searchParams.append(key, value);
}
return await reply.redirect(
url.toString(),
301,
);
if (mustOrigin) {
url = `${this.config.mediaProxy}?url=${encodeURIComponent(url)}`;
} else {
return await reply.redirect(
externalURL.toString(),
301,
);
}
}
if (!request.headers['user-agent']) {