server/lib/private
Lukas Reschke 155ae44bc6 Fix collision on temporary files + adjust permissions
This changeset hardens the temporary file and directory creation to address multiple problems that may lead to exposure of files to other users, data loss or other unexpected behaviour that is impossible to debug.

**[CWE-668: Exposure of Resource to Wrong Sphere](https://cwe.mitre.org/data/definitions/668.html)**
The temporary file and folder handling as implemented in ownCloud is performed using a MD5 hash over `time()` concatenated with `rand()`. This is insufficiently and leads to the following security problems:
The generated filename could already be used by another user. It is not verified whether the file is already used and thus temporary files might be used for another user as well resulting in all possible stuff such as "user has file of other user".

Effectively this leaves us with:

1. A timestamp based on seconds (no entropy at all)
2. `rand()` which returns usually a number between 0 and 2,147,483,647

Considering the birthday paradox and that we use this method quite often (especially when handling external storage) this is quite error prone and needs to get addressed.

This behaviour has been fixed by using `tempnam` instead for single temporary files. For creating temporary directories an additional postfix will be appended, the solution is for directories still not absolutely bulletproof but the best I can think about at the moment. Improvement suggestions are welcome.

**[CWE-378: Creation of Temporary File With Insecure Permissions](https://cwe.mitre.org/data/definitions/378.html)**

Files were created using `touch()` which defaults to a permission of 0644. Thus other users on the machine may read potentially sensitive information as `/tmp/` is world-readable. However, ownCloud always encourages users to use a dedicated machine to run the ownCloud instance and thus this is no a high severe issue. Permissions have been adjusted to 0600.

**[CWE-379: Creation of Temporary File in Directory with Incorrect Permissions](https://cwe.mitre.org/data/definitions/379.html)**

Files were created using `mkdir()` which defaults to a permission of 0777. Thus other users on the machine may read potentially sensitive information as `/tmp/` is world-readable. However, ownCloud always encourages users to use a dedicated machine to run the ownCloud instance and thus this is no a high severe issue. Permissions have been adjusted to 0700.Please enter the commit message for your changes.
2015-04-23 15:07:54 +02:00
..
app Add experimental applications switch 2015-04-03 13:21:24 +02:00
appframework Merge pull request #15735 from owncloud/fix-visibility 2015-04-20 14:39:15 +02:00
archive Update license headers 2015-03-26 11:44:36 +01:00
assetic Update license headers 2015-03-26 11:44:36 +01:00
backgroundjob Update license headers 2015-03-26 11:44:36 +01:00
cache kill OC_FileProxy 💥 2015-04-07 13:30:28 +02:00
command Merge pull request #15129 from owncloud/version-command-bus 2015-03-26 19:55:13 +01:00
connector/sabre Do not trash part files, delete directly 2015-04-21 18:28:15 +02:00
console Convert error and hint to string before writing to the output - fixes https://mailman.owncloud.org/pipermail/devel/2015-April/001184.html 2015-04-16 12:32:17 +02:00
contacts Update license headers 2015-03-26 11:44:36 +01:00
db Using TRANSACTION_READ_COMMITTED 2015-04-16 11:49:12 +02:00
diagnostics Update license headers 2015-03-26 11:44:36 +01:00
encryption fix PHPDoc 2015-04-22 13:12:52 +02:00
files Merge pull request #15809 from owncloud/view-null-root 2015-04-22 18:10:26 +02:00
group Avoid php message "Invalid argument supplied for foreach()" - refs #15590 2015-04-14 11:00:20 +02:00
hooks Update license headers 2015-03-26 11:44:36 +01:00
http/client Update license headers 2015-03-26 11:44:36 +01:00
l10n Merge pull request #14399 from owncloud/ignore-empty-plurals 2015-03-26 20:15:33 +01:00
legacy Revert "Deprecated \OCP\IAppConfig - add missing methods to IConfig" 2015-03-27 18:50:11 +01:00
log Update license headers 2015-03-26 11:44:36 +01:00
mail Add "Reply-To" support for mails 2015-04-10 15:05:34 +02:00
memcache Memcache\Redis Add DB Select Functionality 2015-04-15 21:24:38 +01:00
ocs Remove unused variables 2015-04-18 16:35:19 +02:00
preview Scale up the font on larger previews 2015-04-15 14:03:40 +02:00
route Replace _method requirement by {g,s}etMethods() 2015-04-19 12:08:29 -04:00
search cach user folder for file search results 2015-04-13 11:29:10 +02:00
security Proper return types 2015-04-20 13:00:02 +02:00
session Update license headers 2015-03-26 11:44:36 +01:00
setup Remove unused variables 2015-04-18 16:35:19 +02:00
share Merge pull request #15729 from owncloud/remove-unused-variables 2015-04-19 12:38:29 +01:00
tagging Update license headers 2015-03-26 11:44:36 +01:00
template Fix wrong path generation 2015-04-20 11:01:33 +02:00
user fix followup issues with unneeded parameters 2015-04-18 17:02:39 +02:00
activitymanager.php Add logic for getting the user from the rss token to the Manager 2015-03-30 15:23:09 +02:00
allconfig.php Make scrutinizer happy 2015-04-01 12:13:49 +02:00
api.php Fix usage of deprecated private constants 2015-04-18 10:30:02 +02:00
app.php Merge pull request #15314 from owncloud/app-categories-15274 2015-04-09 10:07:32 +02:00
appconfig.php Update license headers 2015-03-26 11:44:36 +01:00
apphelper.php Update license headers 2015-03-26 11:44:36 +01:00
archive.php Update license headers 2015-03-26 11:44:36 +01:00
arrayparser.php Update license headers 2015-03-26 11:44:36 +01:00
avatar.php Update license headers 2015-03-26 11:44:36 +01:00
avatarmanager.php Fix visibility of public API methods 2015-04-20 12:52:40 +02:00
cache.php Update license headers 2015-03-26 11:44:36 +01:00
config.php Update license headers 2015-03-26 11:44:36 +01:00
contactsmanager.php Update license headers 2015-03-26 11:44:36 +01:00
databaseexception.php Update license headers 2015-03-26 11:44:36 +01:00
databasesetupexception.php Update license headers 2015-03-26 11:44:36 +01:00
datetimeformatter.php Update license headers 2015-03-26 11:44:36 +01:00
datetimezone.php When guessing the timezone, the offset might only be valid on a given timestamp 2015-04-07 10:13:06 +02:00
db.php fix followup issues with unneeded parameters 2015-04-18 17:02:39 +02:00
defaults.php Update license headers 2015-03-26 11:44:36 +01:00
eventsource.php Update license headers 2015-03-26 11:44:36 +01:00
filechunking.php kill OC_FileProxy 💥 2015-04-07 13:30:28 +02:00
files.php Removing files_encryption left overs 2015-04-07 13:30:28 +02:00
forbiddenexception.php Update license headers 2015-03-26 11:44:36 +01:00
group.php Update license headers 2015-03-26 11:44:36 +01:00
helper.php Remove unused variables 2015-04-18 16:35:19 +02:00
hintexception.php Update license headers 2015-03-26 11:44:36 +01:00
hook.php Throw ServerNotAvailableException always 2015-04-10 14:51:21 +02:00
httphelper.php Update license headers 2015-03-26 11:44:36 +01:00
image.php Update license headers 2015-03-26 11:44:36 +01:00
installer.php Add experimental applications switch 2015-04-03 13:21:24 +02:00
json.php Update license headers 2015-03-26 11:44:36 +01:00
l10n.php Remove unused variables 2015-04-18 16:35:19 +02:00
largefilehelper.php Update license headers 2015-03-26 11:44:36 +01:00
log.php Update license headers 2015-03-26 11:44:36 +01:00
mimetypes.list.php Introducing media types for yml, yaml, cnf, conf 2015-04-02 21:37:57 +02:00
naturalsort.php Update license headers 2015-03-26 11:44:36 +01:00
naturalsort_defaultcollator.php Update license headers 2015-03-26 11:44:36 +01:00
navigationmanager.php Update license headers 2015-03-26 11:44:36 +01:00
needsupdateexception.php Update license headers 2015-03-26 11:44:36 +01:00
notsquareexception.php Update license headers 2015-03-26 11:44:36 +01:00
ocs.php Update license headers 2015-03-26 11:44:36 +01:00
ocsclient.php Prevent php message: "Trying to get property of non-object at /xxx/lib/private/ocsclient.php#282" 2015-04-13 09:43:45 +02:00
preview.php Introducing the maximum size preview 2015-04-07 16:45:59 +02:00
previewmanager.php Split image provider in one sub-class per media type 2015-04-02 10:31:24 +02:00
repair.php Merge pull request #14665 from owncloud/fileid-increment 2015-03-26 19:36:18 +01:00
repairexception.php Update license headers 2015-03-26 11:44:36 +01:00
repairstep.php Update license headers 2015-03-26 11:44:36 +01:00
response.php Add version to deprecation notice 2015-04-20 10:30:16 +02:00
search.php Update license headers 2015-03-26 11:44:36 +01:00
server.php add $encryptionModuleId to methods of Keys/IStorage 2015-04-22 11:53:05 +02:00
servernotavailableexception.php throw exception if setup is incomplete 2015-04-10 09:12:37 +02:00
serviceunavailableexception.php Update license headers 2015-03-26 11:44:36 +01:00
setup.php Add check for activated local memcache 2015-03-28 13:59:22 +01:00
subadmin.php Remove unused variables 2015-04-18 16:35:19 +02:00
systemconfig.php Update license headers 2015-03-26 11:44:36 +01:00
tagmanager.php Update license headers 2015-03-26 11:44:36 +01:00
tags.php Merge pull request #15729 from owncloud/remove-unused-variables 2015-04-19 12:38:29 +01:00
template.php Update license headers 2015-03-26 11:44:36 +01:00
templatelayout.php Add experimental applications switch 2015-04-03 13:21:24 +02:00
tempmanager.php Fix collision on temporary files + adjust permissions 2015-04-23 15:07:54 +02:00
updater.php Update license headers 2015-03-26 11:44:36 +01:00
urlgenerator.php Fix UrlGenerator::imagePath() for app paths 2015-04-03 23:42:18 +01:00
user.php Fix namespace duplication and other issues in repairlegacystorages 2015-04-13 16:34:10 +02:00
util.php Disallow Windows Server in Server Check 2015-04-09 15:56:37 +02:00