3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-08 08:05:03 +00:00

Disallow anchors/aliases to objects when loading config YAML

This commit is contained in:
Dragory 2021-08-14 18:22:29 +03:00
parent e8e764c3b7
commit cb8d914fef
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
5 changed files with 96 additions and 3 deletions

View file

@ -0,0 +1,27 @@
import { Not } from "../utils";
const scalarTypes = ["string", "number", "boolean", "bigint"];
export class ObjectAliasError extends Error {}
/**
* Removes object aliases/anchors from a loaded YAML object
*/
export function validateNoObjectAliases<T extends {}>(obj: T, seen?: WeakSet<any>): void {
if (!seen) {
seen = new WeakSet();
}
for (const [key, value] of Object.entries(obj)) {
if (value == null || scalarTypes.includes(typeof value)) {
continue;
}
if (seen.has(value)) {
throw new ObjectAliasError("Object aliases are not allowed");
}
validateNoObjectAliases(value as {}, seen);
seen.add(value);
}
}