Skip to content

fix: add allocation bounds to prevent DoS via unbounded size parameters#476

Open
Yanhu007 wants to merge 1 commit intoMasterminds:masterfrom
Yanhu007:fix/unbounded-resource-allocation
Open

fix: add allocation bounds to prevent DoS via unbounded size parameters#476
Yanhu007 wants to merge 1 commit intoMasterminds:masterfrom
Yanhu007:fix/unbounded-resource-allocation

Conversation

@Yanhu007
Copy link
Copy Markdown

Addresses Finding 1 (HIGH) from #473.

Problem

Several template functions accept user-controlled size/count parameters with no upper bounds, enabling trivial denial-of-service:

Template Allocation
{{ "X" | repeat 100000000 }} ~95 MB
{{ until 50000000 }} ~2.2 GB
{{ randAlpha 50000000 }} ~4.2 GB

Fix

Add a maxAllocSize constant (1 MiB / ~1M elements) and clamp all size parameters in affected functions:

  • repeat — clamp count
  • until — clamp count
  • indent / nindent — clamp spaces
  • randAlpha / randAlphaNum / randAscii / randNumeric — clamp count
  • randBytes — clamp count

Values above the limit are silently capped rather than causing OOM. The limit of 1M elements is generous for any reasonable template use case.

All existing tests pass (the TestHtmlDate failure is pre-existing and timezone-related).

Several template functions accept user-controlled size/count parameters
with no upper bounds, enabling trivial denial-of-service attacks:

- repeat: strings.Repeat with arbitrary count
- until/untilStep: unbounded slice allocation
- indent: strings.Repeat for padding
- randAlpha/randAlphaNum/randAscii/randNumeric/randBytes: unbounded
  random data generation

Add a maxAllocSize constant (1 MiB / ~1M elements) and clamp all
size parameters. Values above the limit are silently capped rather
than causing OOM.

Ref Masterminds#473 (Finding 1)
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