fix(security): allow partial recursion when renderLimit is finite

Only reject render/include cycles when renderLimit is unlimited (default Infinity). With a finite time budget, recursion is bounded by renderLimit checks in renderTemplates.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yang Jun
2026-06-19 23:44:01 +08:00
co-authored by Cursor
parent a7efcc8f96
commit bcc4d5564f
5 changed files with 21 additions and 1 deletions
+3 -1
View File
@@ -181,7 +181,9 @@ export function * renderFilePath (file: ParsedFileName, ctx: Context, liquid: Li
export function pushPartialStack (ctx: Context, filepath: string, tag: 'render' | 'include') {
const stack: string[] = ctx.getRegister('partialStack', [])
if (stack.includes(filepath)) throw new Error(`${tag} tag cannot be nested`)
if (ctx.renderLimit.isUnlimited() && stack.includes(filepath)) {
throw new Error(`${tag} tag cannot be nested`)
}
stack.push(filepath)
}
+3
View File
@@ -19,4 +19,7 @@ export class Limiter {
assert(+count <= this.limit, this.message)
}
}
isUnlimited () {
return !Number.isFinite(this.limit)
}
}