Ethsim2
(Ethan )
20 نوفمبر 2026، 9:41ص
1
وصلني إشعار آلي من مراجعة أمنية بخصوص طلب السحب (PR) المقترح لاستئناف تنزيل النسخ الاحتياطية:
main ← Ethsim12:fix-backup-download-resume
[1] **Error**: The grant is scoped to a filename, not to the file version at tha… t name. It is never invalidated when `destroy` removes the local file, and the supported chunk-upload flow (`HandleChunkUpload#merge_chunks`) explicitly deletes and rewrites the destination under the same filename. An attacker with this administrator's authenticated session and still-live resume URL can therefore wait for a different backup to be uploaded at that name, then issue `Range: bytes=1-` and receive the replacement without a fresh emailed token; for a `.tar.gz`, the omitted first byte is fixed, so the archive is reconstructable. This violates the stated same-backup boundary and can expose the replacement database/uploads. Bind the grant to an immutable file identity/fingerprint and verify it before serving (and invalidate grants on every delete/replacement path), rather than treating the filename as the backup identity.
<details>
<summary>Fix with AI</summary>
````text
Investigate and resolve the following reported finding.
Repository: discourse/discourse
Reviewed head: 7e372b946265b6a3ab55bef8e3b26c747d354a25
Source: https://github.com/discourse/discourse/pull/43041
Location: lib/backup_download_resume_token.rb:5
Published finding:
[1] **Error**: The grant is scoped to a filename, not to the file version at that name. It is never invalidated when `destroy` removes the local file, and the supported chunk-upload flow (`HandleChunkUpload#merge_chunks`) explicitly deletes and rewrites the destination under the same filename. An attacker with this administrator's authenticated session and still-live resume URL can therefore wait for a different backup to be uploaded at that name, then issue `Range: bytes=1-` and receive the replacement without a fresh emailed token; for a `.tar.gz`, the omitted first byte is fixed, so the archive is reconstructable. This violates the stated same-backup boundary and can expose the replacement database/uploads. Bind the grant to an immutable file identity/fingerprint and verify it before serving (and invalidate grants on every delete/replacement path), rather than treating the filename as the backup identity.
Bounded actual source excerpt from reviewed HEAD 7e372b946265b6a3ab55bef8e3b26c747d354a25, around lib/backup_download_resume_token.rb:1-10 (long lines may be truncated):
```
# frozen_string_literal: true
class BackupDownloadResumeToken
def self.key(user_id, backup_filename)
filename_digest = Digest::SHA256.hexdigest(backup_filename)
"backup-download-resume-token:#{user_id}:#{filename_digest}"
end
def self.set(user_id, backup_filename, token, ttl:)
return if ttl.to_i <= 0
```
Acceptance is the reported behavior in the published finding, not merely that existing tests pass.
Before changing code, reproduce the behavior or narrow it to the exact code path and mechanism; state what you confirmed. Do not invent unsupported reproduction evidence.
If the finding is valid, identify the root cause and add a focused regression test that demonstrably fails before the fix and passes after it. If that is impractical, explain why and provide the strongest targeted verification available.
Implement the smallest root-cause-focused fix. Do not perform adjacent refactors or unrelated cleanup.
If the finding is a false positive, do not change the code; reject it with concrete evidence. Existing tests passing is not sufficient evidence.
Run the relevant tests and checks. Report the exact commands and results, plus any behavior you could not verify.
Preserve any reproduction evidence already present in the published finding, but do not seek, expose, copy, or publish private artifacts or internal assessment material, and do not expand the finding's visibility.
````
</details>
يتعلق الإشعار باحتمالية استخدام رمز استئناف (resume token) مُصرّح به سابقاً بعد حذف نسخة احتياطية ووجود ملف آخر تم تحميله بنفس اسم الملف.
فهمتُ أن أسماء الملفات المُنشأة تلقائياً للنسخ الاحتياطية في Discourse تتضمن طابعاً زمنياً بدقّة الثانية، مما يجعل إعادة الاستخدام العرضية نادرة الحدوث أثناء إنشاء النسخ الاحتياطية بشكل اعتيادي.
كما أن السيناريو المذكور في الإشعار يبدو أنه يتطلب جلسة إدارة مُصادق عليها، ومنح استئناف لا يزال سارياً، واستبدال نسخة احتياطية بنفس اسم الملف.
أدرك أن الملفات التي يتم تحميلها يدوياً قد تعيد استخدام اسم ملف موجود، وبالتالي فإن اسم الملف وحده لا يوفر هوية ثابتة للملف.
مع ذلك، أود الحصول على رأي المشرفين (maintainers) حول ما إذا كان هذا يمثل خطراً واقعياً بما يكفي لتبرير التحقق الإضافي من هوية الملف، خاصةً وأن ميزة الاستئناف تكون معطلة افتراضياً وأن مدة السماح بالاستئناف محدودة زمنياً.
هل من المعقول قبول هذه المخاطر المتبقية وتوثيقها، أم يرى المشرفون أن التحقق من هوية الملف ضروري قبل دمج الميزة؟
أبحث عن التوازن المناسب بين الأمان، وتعقيد التنفيذ، والهدف الأصلي المتمثل في السماح باستئناف تنزيل النسخ الاحتياطية الكبيرة المتقطعة.