mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
* fix: Allow webhook urls without a top-level domain when self-hosted Webhook URL validation required a top-level domain, rejecting valid internal hostnames such as http://webhook on self-hosted installations. The TLD requirement is now only enforced when cloud hosted. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * refactor: Extract webhook url validation into reusable IsUrl decorator Move the conditional top-level domain validation into a reusable IsUrl validator alongside the other model validators, and restore mocks between create tests to keep hosting mode isolated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * test: Move webhook url validation tests onto IsUrl validator The top-level domain validation is owned by the IsUrl decorator, so test it directly via a collocated unit test rather than through the webhookSubscriptions API. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * PR feedback --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
27 lines
773 B
TypeScript
27 lines
773 B
TypeScript
import { isURL } from "class-validator";
|
|
import { addAttributeOptions } from "sequelize-typescript";
|
|
import env from "@server/env";
|
|
|
|
/**
|
|
* A decorator that validates that a string is a valid HTTP(S) url. A top-level
|
|
* domain is only required when cloud hosted, allowing self-hosted installations
|
|
* to use internal hostnames.
|
|
*/
|
|
export default function IsUrl(target: object, propertyName: string) {
|
|
return addAttributeOptions(target, propertyName, {
|
|
validate: {
|
|
validUrl(value: string) {
|
|
if (
|
|
!isURL(value, {
|
|
protocols: ["http", "https"],
|
|
require_protocol: true,
|
|
require_tld: env.isCloudHosted,
|
|
})
|
|
) {
|
|
throw new Error("Must be a valid url");
|
|
}
|
|
},
|
|
},
|
|
});
|
|
}
|