fix: remove subpath support for HD_BASE_URL

With this commit we drop the subpath support which results in the constraint that HedgeDoc must always run on the root of a domain. This makes a lot of things in testing, rendering and security much easier.

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-08-12 20:07:38 +02:00
parent 7401791ec8
commit dccd58f0c1
32 changed files with 111 additions and 116 deletions

View file

@ -180,11 +180,11 @@ describe('appConfig', () => {
restore();
});
it('when given a base url with path but no trailing slash in HD_BASE_URL', async () => {
it('when given a base url with subdirectory in HD_BASE_URL', async () => {
const restore = mockedEnv(
{
/* eslint-disable @typescript-eslint/naming-convention */
HD_BASE_URL: 'https://example.org/a',
HD_BASE_URL: 'https://example.org/subdirectory/',
HD_LOGLEVEL: loglevel,
/* eslint-enable @typescript-eslint/naming-convention */
},
@ -193,7 +193,7 @@ describe('appConfig', () => {
},
);
expect(() => appConfig()).toThrow(
'"HD_BASE_URL" must end with a trailing slash',
'"HD_BASE_URL" must not contain a subdirectory',
);
restore();
});

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import {
MissingTrailingSlashError,
NoSubdirectoryAllowedError,
parseUrl,
WrongProtocolError,
} from '@hedgedoc/commons';
@ -23,15 +23,15 @@ export interface AppConfig {
persistInterval: number;
}
function validateUrlWithTrailingSlash(
function validateUrl(
value: string,
helpers: CustomHelpers,
): string | ErrorReport {
try {
return parseUrl(value).isPresent() ? value : helpers.error('string.uri');
} catch (error) {
if (error instanceof MissingTrailingSlashError) {
return helpers.error('url.missingTrailingSlash');
if (error instanceof NoSubdirectoryAllowedError) {
return helpers.error('url.noSubDirectoryAllowed');
} else if (error instanceof WrongProtocolError) {
return helpers.error('url.wrongProtocol');
} else {
@ -41,11 +41,9 @@ function validateUrlWithTrailingSlash(
}
const schema = Joi.object({
baseUrl: Joi.string()
.custom(validateUrlWithTrailingSlash)
.label('HD_BASE_URL'),
baseUrl: Joi.string().custom(validateUrl).label('HD_BASE_URL'),
rendererBaseUrl: Joi.string()
.custom(validateUrlWithTrailingSlash)
.custom(validateUrl)
.default(Joi.ref('baseUrl'))
.optional()
.label('HD_RENDERER_BASE_URL'),
@ -69,7 +67,7 @@ const schema = Joi.object({
.label('HD_PERSIST_INTERVAL'),
}).messages({
// eslint-disable-next-line @typescript-eslint/naming-convention
'url.missingTrailingSlash': '{{#label}} must end with a trailing slash',
'url.noSubDirectoryAllowed': '{{#label}} must not contain a subdirectory',
// eslint-disable-next-line @typescript-eslint/naming-convention
'url.wrongProtocol': '{{#label}} protocol must be HTTP or HTTPS',
});