mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
* fix: Allow private-use URI schemes for OAuth redirect URIs Native apps receive OAuth redirects on a private-use URI scheme (RFC 8252 section 7.1), e.g. com.example.app:/oauth2redirect or myapp://callback. These were rejected when registering a client because IsUrlList only accepted http, https and ftp, and the recommended com.example.app:/path form was also rejected at authorize time because it has no host. Add isPrivateUseSchemeUrl, which accepts private-use schemes while excluding web schemes and schemes that can execute or embed content, and use it in both places. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: Require a protocol for OAuth redirect URIs isURL treats a bare word such as "callback" as a hostname, so a client could be saved with a redirect URI that validateRedirectUri would always reject at authorize time. Require a protocol when validating the list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: Accept one-character private-use URI destinations The destination check compared the pathname length, so a valid opaque URI such as myapp:a was rejected along with the empty myapp: and myapp:/. Reject only those empty forms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { addAttributeOptions } from "sequelize-typescript";
|
|
import isURL from "validator/lib/isURL";
|
|
import { isPrivateUseSchemeUrl } from "@shared/utils/urls";
|
|
|
|
/**
|
|
* A decorator that validates that a value is an array of unique, well-formed
|
|
* URLs with a length within the given bounds. A top-level domain is not
|
|
* required, allowing local and internal hostnames. Private-use schemes such
|
|
* as `com.example.app:/callback` are allowed for native apps (RFC 8252).
|
|
*/
|
|
export default function IsUrlList({
|
|
min = 1,
|
|
max,
|
|
}: {
|
|
min?: number;
|
|
max: number;
|
|
}): (target: object, propertyName: string) => void {
|
|
return (target: object, propertyName: string) =>
|
|
addAttributeOptions(target, propertyName, {
|
|
validate: {
|
|
validUrlList(value: string[] | null) {
|
|
if (!Array.isArray(value)) {
|
|
throw new Error("Must be an array of urls");
|
|
}
|
|
if (value.length < min || value.length > max) {
|
|
throw new Error(`Must contain between ${min} and ${max} urls`);
|
|
}
|
|
if (new Set(value).size !== value.length) {
|
|
throw new Error("Must not contain duplicate urls");
|
|
}
|
|
for (const url of value) {
|
|
if (
|
|
typeof url !== "string" ||
|
|
!(
|
|
isURL(url, {
|
|
require_tld: false,
|
|
require_protocol: true,
|
|
allow_underscores: true,
|
|
}) || isPrivateUseSchemeUrl(url)
|
|
)
|
|
) {
|
|
throw new Error("Must be a valid url");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
});
|
|
}
|