From a76ce4388f5e5f85eabf1d1fc201fee220726e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20So=C5=9Bnierz?= Date: Fri, 13 Sep 2024 13:59:07 +0200 Subject: [PATCH] Support secure connections to the homeserver in MediaProxy (#508) * Support secure connections to the homeserver in MediaProxy Fixes GH-507 * changelog --- changelog.d/508.bugfix | 1 + src/components/media-proxy.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog.d/508.bugfix diff --git a/changelog.d/508.bugfix b/changelog.d/508.bugfix new file mode 100644 index 00000000..6119bf15 --- /dev/null +++ b/changelog.d/508.bugfix @@ -0,0 +1 @@ +Support secure connections to the homeserver in MediaProxy. diff --git a/src/components/media-proxy.ts b/src/components/media-proxy.ts index 46664ff9..4ae16013 100644 --- a/src/components/media-proxy.ts +++ b/src/components/media-proxy.ts @@ -1,7 +1,8 @@ import { webcrypto } from 'node:crypto'; import { Request, Response, default as express, NextFunction, Router } from 'express'; import { ApiError, IApiError, Logger, ErrCode } from '..'; -import { Server, get } from 'http'; +import { Server, get as httpGet } from 'http'; +import { get as httpsGet } from "https"; import { MatrixClient } from '@vector-im/matrix-bot-sdk'; const subtleCrypto = webcrypto.subtle; const log = new Logger('MediaProxy'); @@ -153,6 +154,7 @@ export class MediaProxy { } const [, serverName, mediaId] = mxcMatch; const url = `${this.matrixClient.homeserverUrl}/_matrix/client/v1/media/download/${serverName}/${mediaId}`; + const get = url.startsWith("https:") ? httpsGet : httpGet; return new Promise((resolve, reject) => { get(url, { headers: {