Repository navigation
fix(security): guard ImageSharp decoding of user-uploaded images - #103
Merged
Merged
Conversation
SixLabors.ImageSharp 3.1.12 has 5 advisories (3 High) that are only fixed in 4.x (major). It is pulled in transitively via DUWENINK.Captcha 0.10.2, which has no ImageSharp 4 compatible release, so upgrading is blocked. As a short-term mitigation, every path that decodes user-supplied images (FileApiController.UploadImage / GetFile thumbnailing) now validates the input from the header before any full decode: format allowlist (JPEG, PNG, GIF, BMP, WebP; TIFF and others rejected), max bytes (default 10 MB) and max dimensions (8192x8192, 40 MP). Limits are configurable via the "ImageUploadLimits" section. Rejections reuse each endpoint's existing error behaviour. Captcha generation is untouched (it only encodes images it draws itself) and no public API changes. Refs #78 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
Security review: PR #103(ImageSharp 3.1.12 緩解)Verdict:REQUEST CHANGES(方向正確、能擋掉大多數向量,但有一個已實測的繞過:guard 以 1. 各 advisory 對 3.1.12 的影響與本 PR 是否擋得住套用 3.1.12 的共 5 個(EXR 與 ICC LUT16 僅影響 >=4.0.0,不適用):
先前已修(3.1.11/3.1.7/3.1.5 等的 GIF 無限迴圈、GIF 過量配置、OOB write)在 3.1.12 已含,非本 PR 範疇;但 GIF 仍是「允許」格式,見 M2。 2. 發現(依嚴重度)HIGH
MEDIUM
LOW
3. 其他解碼路徑與 Captcha
4. 建議合併條件
測試環境:.NET 10.0.401 / ImageSharp 3.1.12 實測 BigTIFF Identify(未受限 Configuration:卡住;受限 Configuration:UnknownImageFormatException)。未修改任何檔案。 |
Review of #103 found that Image.Identify with the default Configuration parses TIFF before the allowlist runs, so a 24-byte BigTIFF (GHSA-wmxv-xphr-5c9g) still hangs the request. The guard now uses a dedicated Configuration that registers only JPEG/PNG/GIF/BMP/WebP for both Identify and Load, so other formats are never parsed. Also: clamp requested thumbnail size (default max 4096) and use long math for the aspect ratio; load only the first frame (MaxFrames=1) and lower default MaxPixels to 25 MP; serve the GetFile fallback from the buffered copy when the provider stream is not seekable; dispose images on all paths and log rejection reasons. Refs #78 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
已依 review 修正(commit 見分支最新):
|
This was referenced Oct 19, 2026
cct08311github
added a commit
that referenced
this pull request
Oct 19, 2026
…rd (#151) The OpenApi 2.12.2 / Swashbuckle 10.3.0 upgrade (#54) changes generated swagger.json for untyped properties (nullable dropped); client generators should know it is semantically equivalent. The ImageSharp mitigation (#103) adds a configurable ImageUploadLimits section and changes rejection behaviour, which belongs in the unreleased notes. Closes #150 Co-authored-by: cct0831 <cct0831github@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
背景
SixLabors.ImageSharp 3.1.12 有 5 個 advisory(3 個 High),僅在 4.x(major)修復。它是經由 DUWENINK.Captcha 0.10.2 間接引入,而該套件尚無支援 ImageSharp 4 的版本,因此現階段無法升級。維護者決定:先做緩解,等上游支援後再升級。
變更
針對所有解碼「使用者上傳影像」的路徑,在完整解碼前先以標頭資訊(
Image.Identify)驗證:Configuration,同時用於Identify與Load(TIFF/BigTIFF 等根本不會被解析,避免 GHSA-wmxv-xphr-5c9g 在白名單前觸發)MaxFrames=1,縮圖輸出本來就是 JPEG 首幀,行為不變)ImageUploadLimits(MaxBytes / MaxWidth / MaxHeight / MaxPixels / MaxFrames / MaxResizeWidth / MaxResizeHeight)調整已防護的解碼路徑(全 repo grep 後僅此兩處,皆在 demo):
FileApiController.UploadImage(縮圖上傳):驗證失敗回傳既有的BadRequest(Sys.UploadFailed)FileApiController.GetFile(縮圖輸出):驗證失敗時維持既有行為,回傳原始檔案(不可 seek 的 provider stream 改由已緩衝的副本回傳);兩處皆會 Dispose 影像並以 ILogger 記錄拒絕原因新增
demo/.../Areas/_Admin/ImageDecodeGuard.cs(僅 demo,src/沒有解碼使用者影像的程式碼,故未動 src、無公開 API 變更)。Captcha 產生程式碼完全未動(只編碼自行繪製的影像)。測試結果
新增
ImageDecodeGuardTest(沿用 Core.Test 既有的 MSTest 慣例),涵蓋:PNG/JPEG/GIF/BMP/WebP 通過、TIFF 拒絕、寬度超限與總像素超限拒絕、位元組超限拒絕(含不可 seek 的 stream)、非影像與空內容拒絕。[Timeout])、動態 GIF 只載入首幀、尺寸夾限、不可 seek 緩衝回傳dotnet build WalkingTec.Mvvm.sln:0 錯誤dotnet test:Core.Test 368 通過 / 0 失敗;Admin.Test 9 通過 / 0 失敗對 LayUI/下游的影響
應為無:未變更任何公開 API、Captcha 行為與 LayUI 登入頁;僅在 demo 的影像上傳/縮圖路徑增加驗證,合法的常見格式與一般尺寸行為不變。
後續(未在本 PR 處理的低風險項目)
Entries需注意 GHSA-gwg2-r3hj-4w44(已在程式碼註記)Refs #78
🤖 Generated with Claude Code