feat(go): add configurable size guardrails#3475
Open
ayush00git wants to merge 6 commits intoapache:mainfrom
Open
feat(go): add configurable size guardrails#3475ayush00git wants to merge 6 commits intoapache:mainfrom
ayush00git wants to merge 6 commits intoapache:mainfrom
Conversation
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.
Why?
go deserialization didn't have any configured guardrails for untrusted paylaods which leads to high memory pressure while allocation and Out of memory attacks.
What does this PR do?
Added two configurable guardrails
MaxCollectionSizeandMaxBinarySize, and implement size guardrails across the fory codegen.MaxCollectionSizeandMaxBinarySizetoConfigstruct with corresponding optionsWithMaxCollectionSizeandWithMaxBinarySize.ReadCollectionLengthandReadBinaryLengthtoByteBufferandReadContext.ErrKindMaxCollectionSizeExceededandErrKindMaxBinarySizeExceeded.codegen/decoder.go) to use these guarded length methods in generated serializers.ReadLengthmethod to ensure all length-reading paths in the codebase are subject to guardrails.Related issues
Closes #3419
AI Contribution Checklist
Substantial AI assistance was used in this PR:
yesIf
yes, I included a completed AI Contribution Checklist in this PR description and the requiredAI Usage Disclosure.If
yes, I included the standardizedAI Usage Disclosureblock below.If
yes, I can explain and defend all important changes without AI help.If
yes, I reviewed AI-assisted code changes line by line before submission.If
yes, I ran adequate human verification and recorded evidence (checks run locally or in CI, pass/fail summary, and confirmation I reviewed results).If
yes, I added/updated tests and specs where required.If
yes, I validated protocol/performance impacts with evidence when applicable.If
yes, I verified licensing and provenance compliance.Does this PR introduce any user-facing change?
Benchmark