fix: fixes excessive alias count error#3925
Conversation
| export const parse = ( | ||
| src: string, | ||
| options?: yaml.ParseOptions & | ||
| yaml.DocumentOptions & | ||
| yaml.SchemaOptions & | ||
| yaml.ToJSOptions, | ||
| ): any => yaml.parse(src, { maxAliasCount: 10000, ...options }); |
There was a problem hiding this comment.
Missing reviver overload
The PR description states this wrapper has an "identical signature", but the yaml library's parse function actually has a second overload:
// overload 1 (implemented)
parse(src: string, options?: ParseOptions & ...): any
// overload 2 (missing)
parse(src: string, reviver: (key: any, value: any) => any, options?: ParseOptions & ...): anyIf a caller passes a reviver function as the second argument, it will silently be interpreted as the options parameter and spread into the options object — the reviver will never be called. No callers in the current codebase use the reviver variant, so this isn't an active bug, but the missing overload is a correctness gap. Consider adding the second signature to fully match the original API:
export const parse: typeof yaml.parse = (
src: string,
reviver?: ((key: any, value: any) => any) | (yaml.ParseOptions & ...),
options?: yaml.ParseOptions & ...,
): any => {
if (typeof reviver === "function") {
return yaml.parse(src, reviver, { maxAliasCount: 10000, ...options });
}
return yaml.parse(src, { maxAliasCount: 10000, ...reviver });
};There was a problem hiding this comment.
I could add that, but I really don't like the signature of that new function, i'ts almost unreadable. Given that we don't use the reviver option anywhere, I think it's better to keep it that way. One could always add a parseWithReviver() method to our utility.
IMHO this is a great example why function overloads are a bad language feature. Optional named parameters are the better alternative (well, not the way TS implemented it).
What is this PR about?
{maxAliasCount: 10000}(overridable) applied -> fixes docker-compose.yml: Excessive alias count indicates a resource exhaustion attack #3924Checklist
Before submitting this PR, please make sure that:
canarybranch.Issues related (if applicable)
closes #3924
Greptile Summary
This PR fixes the
ReferenceError: Excessive alias count indicates a resource exhaustion attackerror by introducing a thin wrapper aroundyaml.parsethat raisesmaxAliasCountfrom the default 100 to 10,000 (overridable). All 34 changed files migrate theiryamlimports to the new wrapper, and a regression test with 205 alias references is added to confirm the fix.Key changes:
packages/server/src/utils/yaml/index.ts: New wrapper that re-exportsstringifyandYAMLParseErrordirectly fromyamlwhile overridingmaxAliasCountto 10,000 forparsefrom "yaml"forfrom "@dokploy/server/utils/yaml"or the relative../yamlpath — no directyamlimports remain outside the wrapper itselfIssues found:
yaml.parseoverloads — the reviver-function variant (parse(src, (key, value) => ...)) is silently swallowed as an options object. Not a current bug, but the API is not fully equivalent to the original.Confidence Score: 4/5
Last reviewed commit: 08a172c
(2/5) Greptile learns from your feedback when you react with thumbs up/down!