fix(python-flask): validate byte length for format:byte fields#23177
Open
1cbyc wants to merge 1 commit intoOpenAPITools:masterfrom
Open
fix(python-flask): validate byte length for format:byte fields#231771cbyc wants to merge 1 commit intoOpenAPITools:masterfrom
1cbyc wants to merge 1 commit intoOpenAPITools:masterfrom
Conversation
When a string field has format:byte with minLength/maxLength constraints, the generated validation code incorrectly checks string length instead of base64-decoded byte length. Added conditional logic using isByteArray flag to validate decoded byte length for byte array fields. Maintains existing string length validation for non-byte fields. Fixes OpenAPITools#450
Contributor
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/resources/python-flask/model.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/python-flask/model.mustache:142">
P2: Byte-array length validation silently skips invalid base64/type errors, allowing malformed `format:byte` values to bypass validation.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| raise ValueError("Invalid value for `{{name}}`, byte length must be less than or equal to `{{maxLength}}`") # noqa: E501 | ||
| except (TypeError, ValueError, base64.binascii.Error): | ||
| # If it's not valid base64, other validation will catch it | ||
| pass |
Contributor
There was a problem hiding this comment.
P2: Byte-array length validation silently skips invalid base64/type errors, allowing malformed format:byte values to bypass validation.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/python-flask/model.mustache, line 142:
<comment>Byte-array length validation silently skips invalid base64/type errors, allowing malformed `format:byte` values to bypass validation.</comment>
<file context>
@@ -130,12 +130,38 @@ class {{classname}}(Model):
+ raise ValueError("Invalid value for `{{name}}`, byte length must be less than or equal to `{{maxLength}}`") # noqa: E501
+ except (TypeError, ValueError, base64.binascii.Error):
+ # If it's not valid base64, other validation will catch it
+ pass
+{{/isByteArray}}
+{{^isByteArray}}
</file context>
Suggested change
| pass | |
| raise ValueError("Invalid value for `{{name}}`, must be valid base64-encoded data") # noqa: E501 |
Member
There was a problem hiding this comment.
thanks for the PR.
@1cbyc can you please review this feedback when you've time?
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.
When a string field has format:byte with minLength/maxLength constraints,
the generated validation code incorrectly checks string length instead
of base64-decoded byte length.
Added conditional logic using isByteArray flag to validate decoded
byte length for byte array fields. Maintains existing string length
validation for non-byte fields.
Fixes #450
Summary by cubic
Fixes validation for
format:bytefields in the Python Flask generator by checking the base64-decoded byte length forminLength/maxLength. Prevents incorrect passes/failures when validating byte arrays; non-byte fields still use string length checks.isByteArrayguards inmodel.mustacheto validate decoded byte length forminLengthandmaxLength.Written for commit 25e4582. Summary will update on new commits.