Skip to content

Bound the Liquid work of one email, and template request bodies - #644

Merged
pierre-b merged 1 commit into
devfrom
fix/compile-work-budget
Nov 18, 2026
Merged

pierre-b merged 1 commit into
devfrom
fix/compile-work-budget

Conversation

@pierre-b

Copy link
Copy Markdown
Contributor

The Liquid limits (render score, assign score, 5 seconds) applied to each render of a compilation, and a compilation makes one render per block, URL or alt attribute and display condition, plus the subject, the text and the whole document: nothing bounded how many of them a template made costly, and template request bodies had no size limit.

  • Work budget per compilation (pkg/notifuse_mjml/render_budget.go): CompileTemplate creates a budget of 10 s and 20 million of render score, and every render of the compilation takes the lower of its own limits and what is left, then has its score taken off. A spent budget fails the compilation with "liquid rendering exceeds the work budget of the email", like any Liquid error. The public functions (RenderWithTimeout, ProcessLiquidTemplate, Evaluate, ConvertJSONToMJMLWithData…) keep their signatures; the budget goes through internal parameters.
  • Body limit: templates.compile, templates.create and templates.update refuse a body over 1 MiB with 413 (decodeTemplateRequest). A gallery template weighs about 20 KB per language.
  • OpenAPI documents the 413; CHANGELOG 44.0 has a Security line.

Tests: render_budget_test.go (budget arithmetic, a render stopped by score or time left, a 100-block costly tree stopped in under a second, every gallery template in every language under 1% of the budget, with its Liquid rendered), TestTemplateHandler_RequestBodyLimit (413 above, decoded at the limit, on the three endpoints), integration TestTemplateCompileWorkLimits. Without the budget, the 100-block test takes 21.5 s and succeeds, so it fails.

Each render of a compilation had its own limits and its own 5 seconds, and nothing bounded how
many renders a template made: one block, attribute or condition each. A compilation now draws
all its renders from one budget of 10 seconds and 20 million of render score; a template of
the gallery spends well under 1% of it. templates.compile, templates.create and
templates.update refuse a body over 1 MiB with 413, before it is parsed.
@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.49593% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.47%. Comparing base (32b8bf6) to head (c354930).
⚠️ Report is 3 commits behind head on dev.

Files with missing lines Patch % Lines
internal/http/template_handler.go 82.35% 1 Missing and 2 partials ⚠️
pkg/notifuse_mjml/liquid_secure.go 93.47% 2 Missing and 1 partial ⚠️
pkg/notifuse_mjml/converter.go 93.93% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #644   +/-   ##
=======================================
  Coverage   90.46%   90.47%           
=======================================
  Files         390      391    +1     
  Lines       76569    76623   +54     
=======================================
+ Hits        69271    69326   +55     
+ Misses       4740     4739    -1     
  Partials     2558     2558           
Flag Coverage Δ
unit 90.47% <93.49%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pierre-b
pierre-b merged commit bec5eb3 into dev Nov 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant