Security/Reviews/Gaia/DownloadManager
Download Manager API
Review Details
- Topic: Download Manager API for FxOS
- Review Date: January, 2014
- Review Lead: Rob Fletcher <rfletcher@mozilla.com> (:omerta)
- Repo: git://github.com/mozilla-b2g/B2G.git:5a5ab327af050bc622d475bb29ca3ad3955bd238
- Connections: "Ghislain 'Aus' Lacroix" <aus@mozilla.com> (:auswerk), "Gregor Wagner" <gwagner@mozilla.com>
- Main Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=926955
- Landing: B2G 1.4
Overview
Download Manager API handles downloads on Firefox OS. The settings and system applications are the only applications that have the certified 'downloads' permission and they are responsible for managing downloads. The system application handles the download event and the settings application has a "Download" section that allows a user to view, delete, stop, and restart current downloads. When a download is initiated, a notification is created in the notifications pull down menu.
Any HTTP response with content type of "application/octet-stream" will cause the file to be downloaded. The files are saved to /sdcard/downloads/ on the filesystem.
The main file responsible for Download Manager API is:
Gaia
Code
System App
- github.com/mozilla-b2g/gaia/apps/system/js/download/download_manager.js
- github.com/mozilla-b2g/gaia/apps/system/js/download/download_notification.js
Settings App
- github.com/mozilla-b2g/gaia/apps/settings/js/downloads/download_api_manager.js
- github.com/mozilla-b2g/gaia/apps/settings/js/downloads/download_item.js
- github.com/mozilla-b2g/gaia/apps/settings/js/downloads/downloads_list.js
- github.com/mozilla-b2g/gaia/apps/settings/js/downloads/desktop/desktop_moz_downloads.js
- github.com/mozilla-b2g/gaia/blob/master/shared/js/download/download_formatter.js
- github.com/mozilla-b2g/gaia/blob/master/shared/js/download/download_helper.js
- github.com/mozilla-b2g/gaia/blob/master/shared/js/download/download_store.js
- github.com/mozilla-b2g/gaia/blob/master/shared/js/download/download_ui.js
Permissions
Settings and System are only apps with certified ‘downloads’ permission.
"downloads": { app: DENY_ACTION, privileged: DENY_ACTION, certified: ALLOW_ACTION },
Gecko
Code
WebIDL File for mozDownloadManager
Parent Process
- mxr.mozilla.org/mozilla-central/source/dom/downloads/src/DownloadsAPI.jsm
- mxr.mozilla.org/mozilla-central/source/toolkit/components/jsdownloads/src/Downloads.jsm
Child Process
- mxr.mozilla.org/mozilla-central/source/dom/downloads/src/DownloadsAPI.js
- mxr.mozilla.org/mozilla-central/source/dom/downloads/src/DownloadsIPC.jsm
Downloads.jsm
Downloads.jsm depracates nsIDownloadManager and is used in Download Manager on FxOS. Downloads.jsm provides single point of entry for all things relating to downloading.
Features
- 906255 - ability to view status of downloads
- 906256 - ability to cancel downloads
- 906257 - ability to view list of previously downloaded files
- 906265 - ability to open downloaded files with supported MIME types
- 848371 - ability to download any content through Browser to the SD Card(including HTTP downloading)
Conclusion
Attack surface is greatly reduced through the combination of using WebIDL, 'downloads' permissions is Certified, and the fact that Download Manager API uses the new Downloads.jsm.