Skip to content

Improved: Enhance validation checks for file uploads#1157

Merged
jacopoc merged 3 commits into
apache:trunkfrom
jacopoc:improve-validation-checks
May 4, 2026
Merged

Improved: Enhance validation checks for file uploads#1157
jacopoc merged 3 commits into
apache:trunkfrom
jacopoc:improve-validation-checks

Conversation

@jacopoc
Copy link
Copy Markdown
Contributor

@jacopoc jacopoc commented May 4, 2026

No description provided.

jacopoc added 3 commits May 4, 2026 10:04
The productId request parameter was concatenated directly into
filesystem paths across 7 service methods in ImageManagementServices without any path traversal validation.

Added Paths.normalize().startsWith() guards in all affected methods
(addMultipleuploadForProduct, removeImageFileForImageManagement, scaleImageMangementInAllSize, createContentThumbnail,
createNewImageThumbnail, resizeImageOfProduct, renameImage), following the same pattern already in use in ProductServices.java.
…lInPNG

The previous implementation returned after the first IDAT chunk, leaving any payload in subsequent IDAT chunks or bytes appended after IEND unreachable. PNG (RFC 2083) explicitly permits multiple IDAT chunks whose data must be concatenated before decompression.

The loop now accumulates all IDAT chunks into a single buffer and terminates on IEND. After IEND, any trailing bytes cause the file to be rejected. inflate() is called once on the fully concatenated payload, as the spec requires.
The imageMadeSafe() re-encoding pipeline already strips trailing bytes
for all formats, but JPEG and GIF uploads containing a webshell payload
appended after their respective terminators were silently sanitized
rather than explicitly rejected.

Added noWebshellInJPEG() and noWebshellInGIF(), called from
imageMadeSafe() alongside the existing noWebshellInPNG() check.
noWebshellInJPEG() walks the JPEG marker structure from SOI, handling
entropy-coded scan data with byte stuffing, and rejects the file if any
bytes follow the EOI (FF D9) marker. noWebshellInGIF() parses the GIF
block structure (extensions, image descriptors, and their sub-block
chains) and rejects the file if any bytes follow the Trailer (0x3B).
@jacopoc jacopoc self-assigned this May 4, 2026
@jacopoc jacopoc merged commit e1fc556 into apache:trunk May 4, 2026
5 checks passed
@jacopoc jacopoc deleted the improve-validation-checks branch May 4, 2026 09:05
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