mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
* 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>
27 lines
780 B
TypeScript
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");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
});
|
|
}
|