From d04883cf3f3142a13f8e1a031c37fb44ab6a7a1a Mon Sep 17 00:00:00 2001 From: Comunic Server Date: Mon, 30 Mar 2020 16:14:40 +0100 Subject: [PATCH] Fix HTTPS requirement --- src/entities/RequestHandler.ts | 5 +++-- src/helpers/ConfigHelper.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/entities/RequestHandler.ts b/src/entities/RequestHandler.ts index de32c03..325f1cb 100644 --- a/src/entities/RequestHandler.ts +++ b/src/entities/RequestHandler.ts @@ -1,3 +1,4 @@ +import { conf } from "../helpers/ConfigHelper"; import { Response, Request } from "express"; import { APIHelper } from "../helpers/APIHelper"; import { APIClient } from "./APIClient"; @@ -486,7 +487,7 @@ export class RequestHandler { if(client.domain) { - const allowedOrigin = "http://" + client.domain; + const allowedOrigin = (conf().force_clients_https ? "https://" : "http://") + client.domain; const referer = this.req.get("Referer"); if(!referer || !referer.startsWith(allowedOrigin)) @@ -621,4 +622,4 @@ export class RequestHandler { this.response.send(data); } -} \ No newline at end of file +} diff --git a/src/helpers/ConfigHelper.ts b/src/helpers/ConfigHelper.ts index 986c7b8..41e54bd 100644 --- a/src/helpers/ConfigHelper.ts +++ b/src/helpers/ConfigHelper.ts @@ -20,7 +20,8 @@ export interface Configuration { storageURL : string, storagePath : string, database : DatabaseConfiguration, - proxy ?: string + proxy ?: string, + force_clients_https ?: boolean } export class ConfigurationHelper { @@ -46,4 +47,4 @@ export class ConfigurationHelper { */ export function conf() : Configuration { return ConfigurationHelper.getConf(); -} \ No newline at end of file +}