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
780 B
TypeScript

import { addAttributeOptions } from "sequelize-typescript";
import AuthenticationHelper from "@shared/helpers/AuthenticationHelper";
/**
* A decorator that validates that every element of a string array is a
* well-formed API scope.
*/
export default function IsScope(target: object, propertyName: string) {
return addAttributeOptions(target, propertyName, {
validate: {
validScope(value: string[] | null) {
if (!value) {
return;
}
if (!Array.isArray(value)) {
throw new Error("Scope must be an array");
}
for (const scope of value) {
if (!AuthenticationHelper.isValidScope(scope)) {
throw new Error("Scope must be a valid API scope");
}
}
},
},
});
}