fix: add allocation bounds to prevent DoS via unbounded size parameters#476
Open
Yanhu007 wants to merge 1 commit intoMasterminds:masterfrom
Open
fix: add allocation bounds to prevent DoS via unbounded size parameters#476Yanhu007 wants to merge 1 commit intoMasterminds:masterfrom
Yanhu007 wants to merge 1 commit intoMasterminds:masterfrom
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
{{ "X" | repeat 100000000 }}{{ until 50000000 }}{{ randAlpha 50000000 }}Fix
Add a
maxAllocSizeconstant (1 MiB / ~1M elements) and clamp all size parameters in affected functions:repeat— clamp countuntil— clamp countindent/nindent— clamp spacesrandAlpha/randAlphaNum/randAscii/randNumeric— clamp countrandBytes— clamp countValues 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
TestHtmlDatefailure is pre-existing and timezone-related).