fix: prevent path traversal vulnerability in object handlers#2
Open
Amahdip wants to merge 1 commit into
Open
Conversation
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.
Description
This PR addresses a critical Path Traversal (Directory Traversal) vulnerability in the S3 object handlers (
get_object,head_object,put_object,delete_object).The Issue:
Previously, the code used
storage.join(key.trim_start_matches('/')). If a client sent a malicious key containing traversal segments (e.g.,../../etc/passwd), the resultingPathBufcould escape the intended bucketstoragedirectory. This allowed unauthorized arbitrary file read, overwrite, and deletion on the host filesystem.The Fix:
safe_joinhelper function that lexically parses the requested key usingstd::path::Component.ParentDir(..) and WindowsPrefix(e.g.,C:) components.RootDir(/) andCurDir(.), and correctly appendsNormalcomponents to the base storage path.403 Access Deniedresponse.safe_joinbehaves securely under various edge cases.توضیحات فارسی
این PR یک آسیبپذیری امنیتی خطرناک از نوع Path Traversal (پیمایش پوشهها) را در هندلرهای مربوط به فایلها (شامل
get_object،head_object،put_objectوdelete_object) برطرف میکند.مشکل چه بود؟
پیش از این، در کدها از دستور
storage.join(key.trim_start_matches('/'))استفاده میشد. اگر یک کلاینت، کلید مخربی حاوی کاراکترهای بازگشتی (مثلاً../../etc/passwd) ارسال میکرد، مسیر نهایی میتوانست از پوشه اصلی باکت خارج شود. این موضوع اجازه میداد تا هر فایلی در کل سیستمعامل سرور بدون دسترسی مجاز خوانده، بازنویسی و یا حذف شود.راه حل اعمال شده:
safe_joinاضافه شد که کلید درخواستی را با استفاده از کتابخانه پایهstd::path::Componentبه صورت امن تحلیل میکند.ParentDir(یعنی..) و پیشوندهای ویندوزی (مثلC:) را کاملاً مسدود میکند.RootDir(/) وCurDir(.) را به درستی نادیده میگیرد و فقط مسیرهای معتبر را به مسیر اصلی باکت متصل میکند.403 Access Deniedرا برمیگردانند.safe_joinدر شرایط مختلف و در برابر ورودیهای عجیب، به درستی و با امنیت کامل کار میکند.