Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,38 @@ class {{classname}}(Model):
{{/required}}
{{#hasValidation}}
{{#maxLength}}
{{#isByteArray}}
if {{name}} is not None:
import base64
try:
decoded_length = len(base64.b64decode({{name}}))
if decoded_length > {{maxLength}}:
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
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Fix with Cubic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR.

@1cbyc can you please review this feedback when you've time?

{{/isByteArray}}
{{^isByteArray}}
if {{name}} is not None and len({{name}}) > {{maxLength}}:
raise ValueError("Invalid value for `{{name}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501
{{/isByteArray}}
{{/maxLength}}
{{#minLength}}
{{#isByteArray}}
if {{name}} is not None:
import base64
try:
decoded_length = len(base64.b64decode({{name}}))
if decoded_length < {{minLength}}:
raise ValueError("Invalid value for `{{name}}`, byte length must be greater than or equal to `{{minLength}}`") # noqa: E501
except (TypeError, ValueError, base64.binascii.Error):
# If it's not valid base64, other validation will catch it
pass
{{/isByteArray}}
{{^isByteArray}}
if {{name}} is not None and len({{name}}) < {{minLength}}:
raise ValueError("Invalid value for `{{name}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501
{{/isByteArray}}
{{/minLength}}
{{#maximum}}
if {{name}} is not None and {{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}: # noqa: E501
Expand Down
Loading