Skip to content

Backport pr 1157 (Improved: Enhance validation checks for file uploads)#1158

Merged
jacopoc merged 3 commits into
apache:release24.09from
jacopoc:backport-pr-1157
May 4, 2026
Merged

Backport pr 1157 (Improved: Enhance validation checks for file uploads)#1158
jacopoc merged 3 commits into
apache:release24.09from
jacopoc:backport-pr-1157

Conversation

@jacopoc
Copy link
Copy Markdown
Contributor

@jacopoc jacopoc commented May 4, 2026

jacopoc added 3 commits May 4, 2026 11:29
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.

(cherry picked from commit 11f4e52)
…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.

(cherry picked from commit f8a1118)
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).

(cherry picked from commit e1fc556)
@jacopoc jacopoc self-assigned this May 4, 2026
@jacopoc jacopoc merged commit d1bfb92 into apache:release24.09 May 4, 2026
5 checks passed
@jacopoc jacopoc deleted the backport-pr-1157 branch May 4, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant