Skip to content

Use a finite default upload size when no scanner is present#867

Open
Schmarvinius wants to merge 2 commits into
mainfrom
fix/finite-default-upload-size
Open

Use a finite default upload size when no scanner is present#867
Schmarvinius wants to merge 2 commits into
mainfrom
fix/finite-default-upload-size

Conversation

@Schmarvinius

Copy link
Copy Markdown
Contributor

Issue

When no malware scanner binding was present, the default maximum attachment upload size was Long.MAX_VALUE (UNLIMITED_SIZE, documented as "effectively unlimited"). A deployment without a scanner therefore silently allowed unbounded uploads, with the associated resource-exhaustion risk, unless the app happened to set @Validation.Maximum.

Fix

The default maximum upload size is now a finite 400MB (DEFAULT_MAX_UPLOAD_SIZE) regardless of the scanner binding. Deployments that intentionally allow larger uploads opt in explicitly via the new cds.attachments.maxUploadSize property, or override per entity with @Validation.Maximum.

Resolution is centralized in Registration.resolveDefaultMaxSize (explicit config wins, otherwise the finite default). The redundant UNLIMITED_SIZE / scanner-dependent constants were consolidated into a single DEFAULT_MAX_UPLOAD_SIZE.

Tests

RegistrationTest: finite default when unconfigured or blank, and configured override honored.

Without a malware scanner binding the default maximum upload size was
Long.MAX_VALUE (effectively unlimited), so a missing scanner silently
allowed unbounded attachment uploads and the associated resource
exhaustion risk.

The default is now a finite 400 MB regardless of the scanner binding
(DEFAULT_MAX_UPLOAD_SIZE). Deployments that intentionally allow larger
uploads can opt in via the new cds.attachments.maxUploadSize property, or
override per entity with @Validation.Maximum.
Adds RegistrationTest cases for resolveDefaultMaxSize (finite default
when unconfigured or blank, configured override honored) and updates
handler tests to the renamed DEFAULT_MAX_UPLOAD_SIZE constant.
@Schmarvinius
Schmarvinius requested a review from a team as a code owner July 21, 2026 10:42
@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Use a Finite Default Upload Size When No Scanner Is Present

Bug Fix

🐛 Previously, when no malware scanner binding was present, the default maximum attachment upload size fell back to Long.MAX_VALUE (effectively unlimited). This silently allowed unbounded uploads with an associated resource-exhaustion risk unless the application explicitly set @Validation.Maximum.

The default maximum upload size is now a finite 400 MB (DEFAULT_MAX_UPLOAD_SIZE) regardless of whether a malware scanner binding is present. Apps that intentionally require larger uploads can opt in via the new cds.attachments.maxUploadSize configuration property, or override per entity using @Validation.Maximum.

Changes

  • Registration.java: Replaced scanner-conditional size logic with a call to the new resolveDefaultMaxSize helper method. Added resolveDefaultMaxSize(CdsEnvironment) which reads cds.attachments.maxUploadSize from configuration and falls back to DEFAULT_MAX_UPLOAD_SIZE (400 MB) if not set or blank.

  • ModifyApplicationHandlerHelper.java: Consolidated the two previous constants (DEFAULT_SIZE_WITH_SCANNER and UNLIMITED_SIZE) into a single DEFAULT_MAX_UPLOAD_SIZE = "400MB" constant, with updated Javadoc explaining the rationale.

  • RegistrationTest.java: Added three new unit tests for resolveDefaultMaxSize:

    • Returns the finite default when no configuration is present.
    • Ignores blank/whitespace-only configuration values.
    • Honors an explicitly configured override (e.g., "1GB").
  • CreateAttachmentsHandlerTest.java, UpdateAttachmentsHandlerTest.java, ModifyApplicationHandlerHelperTest.java, DraftPatchAttachmentsHandlerTest.java: Updated all test references from the removed DEFAULT_SIZE_WITH_SCANNER constant to the new DEFAULT_MAX_UPLOAD_SIZE.


  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.28.2

  • Correlation ID: dcf30e90-84f0-11f1-830e-eed41851c4d1
  • Event Trigger: pull_request.opened
  • Summary Prompt: Default Prompt
  • File Content Strategy: Full file content
  • LLM: anthropic--claude-4.6-sonnet
  • Output Template: Default Template

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The PR is well-structured and achieves its stated goal cleanly. Removing the scanner-dependent UNLIMITED_SIZE path and centralizing resolution in resolveDefaultMaxSize is a clear security improvement, and the test coverage for the new method is thorough. The one issue flagged above is that an invalid cds.attachments.maxUploadSize configuration value is only caught at upload time rather than at startup, which could be confusing for operators. Addressing that would make the configuration contract more robust.

PR Bot Information

Version: 1.28.2

  • Correlation ID: dcf30e90-84f0-11f1-830e-eed41851c4d1
  • Event Trigger: pull_request.opened
  • File Content Strategy: Full file content
  • LLM: anthropic--claude-4.6-sonnet
  • Agent Instructions:

Comment on lines +202 to +209
static String resolveDefaultMaxSize(CdsEnvironment environment) {
String configured =
environment.getProperty("cds.attachments.maxUploadSize", String.class, null);
if (configured != null && !configured.isBlank()) {
return configured;
}
return ModifyApplicationHandlerHelper.DEFAULT_MAX_UPLOAD_SIZE;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Best Practice: resolveDefaultMaxSize accepts any non-blank configured value without validating its format, but an invalid value (e.g. "400 megabytes" or "abc") is only caught later at upload time when FileSizeUtils.parseFileSizeToBytes throws IllegalArgumentException, turning a configuration error into a runtime crash on the first upload attempt.

Consider validating the configured value at resolution time by calling FileSizeUtils.parseFileSizeToBytes and falling back to the default (or re-throwing with a clear message) if it is malformed:

Suggested change
static String resolveDefaultMaxSize(CdsEnvironment environment) {
String configured =
environment.getProperty("cds.attachments.maxUploadSize", String.class, null);
if (configured != null && !configured.isBlank()) {
return configured;
}
return ModifyApplicationHandlerHelper.DEFAULT_MAX_UPLOAD_SIZE;
}
static String resolveDefaultMaxSize(CdsEnvironment environment) {
String configured =
environment.getProperty("cds.attachments.maxUploadSize", String.class, null);
if (configured != null && !configured.isBlank()) {
try {
FileSizeUtils.parseFileSizeToBytes(configured); // validate format eagerly
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"Invalid value for cds.attachments.maxUploadSize: '" + configured + "'", e);
}
return configured;
}
return ModifyApplicationHandlerHelper.DEFAULT_MAX_UPLOAD_SIZE;
}

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

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