Files
outline/server/models/validators/IsUrlList.ts
T
Tom MoorandClaude Fable 5.1 a577d5c2c8 fix: Validate API key and OAuth scopes at the model layer (#13664)
* fix: Validate API key scopes with Sequelize-level validators

* test: Add API regression tests for duplicate OAuth redirect URIs

* fix: Preserve wildcard scope and guard non-string redirect URIs

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 23:10:32 -04:00

44 lines
1.3 KiB
TypeScript

import { addAttributeOptions } from "sequelize-typescript";
import isURL from "validator/lib/isURL";
/**
* 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.
*/
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,
allow_underscores: true,
})
) {
throw new Error("Must be a valid url");
}
}
},
},
});
}