Files
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

27 lines
773 B
TypeScript

import isURL from "validator/lib/isURL";
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");
}
},
},
});
}