Absolutely no leak for media proxies
This commit is contained in:
parent
0bc96fb197
commit
ec060b7a14
1 changed files with 13 additions and 9 deletions
|
@ -292,7 +292,7 @@ export class FileServerService {
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
private async proxyHandler(request: FastifyRequest<{ Params: { url: string; }; Querystring: { url?: string; }; }>, reply: FastifyReply) {
|
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') {
|
if (typeof url !== 'string') {
|
||||||
reply.code(400);
|
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
|
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)) {
|
for (const [key, value] of Object.entries(request.query)) {
|
||||||
url.searchParams.append(key, value);
|
externalURL.searchParams.append(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await reply.redirect(
|
if (mustOrigin) {
|
||||||
url.toString(),
|
url = `${this.config.mediaProxy}?url=${encodeURIComponent(url)}`;
|
||||||
301,
|
} else {
|
||||||
);
|
return await reply.redirect(
|
||||||
|
externalURL.toString(),
|
||||||
|
301,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!request.headers['user-agent']) {
|
if (!request.headers['user-agent']) {
|
||||||
|
|
Loading…
Reference in a new issue