nextcloud-server/tests/lib
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 Adjust tests and check whether clear() is called 2015-04-01 17:19:44 +02:00
appframework If the execute method on the mapper receives an assoc array, it binds by value instead of index 2015-03-19 17:08:46 +01:00
archive
backgroundjob
cache kill OC_FileProxy 💥 2015-04-07 13:30:28 +02:00
command Allow configuring background job mode from the console 2015-03-02 20:51:40 +01:00
connector/sabre pass a stream to the tests 2015-04-14 15:25:52 +02:00
contacts
db
encryption add $encryptionModuleId to methods of Keys/IStorage 2015-04-22 11:53:05 +02:00
files Merge pull request #15809 from owncloud/view-null-root 2015-04-22 18:10:26 +02:00
group Remove unneeded comments 2015-04-14 16:44:24 +02:00
hooks
http/client Add wrapper for Guzzle 2015-03-25 16:04:41 +01:00
mail Add "Reply-To" support to sharing mails and refactor code 2015-04-10 17:30:07 +02:00
memcache Refactor \OC\Memcache\Factory 2015-03-05 11:36:34 +00:00
ocs
public
repair Fix namespace duplication and other issues in repairlegacystorages 2015-04-13 16:34:10 +02:00
security Adjust tests and statuscode 2015-04-20 13:00:02 +02:00
session
share Add "Reply-To" support to sharing mails and refactor code 2015-04-10 17:30:07 +02:00
template Add tests for correct path 2015-04-20 12:31:35 +02:00
user
activitymanager.php Make scrutinizer happy 2015-04-01 12:13:49 +02:00
allconfig.php
api.php
app.php Adjust tests and check whether clear() is called 2015-04-01 17:19:44 +02:00
appconfig.php
archive.php
autoloader.php
avatar.php fixing unit test execution related to trashbin 2015-04-07 13:30:31 +02:00
cache.php
config.php
contactsmanager.php
datetimeformatter.php
db.php Use data provider instead of hand-crafted for loops 2015-04-18 15:19:33 +02:00
dbschema.php
errorHandler.php
group.php
helper.php
helperstorage.php
httphelper.php Add wrapper for Guzzle 2015-03-25 16:04:41 +01:00
image.php Create an interface for OC_Image and OCP\Image for the public API 2015-03-16 12:45:15 +01:00
installer.php
l10n.php Merge pull request #14399 from owncloud/ignore-empty-plurals 2015-03-26 20:15:33 +01:00
largefilehelper.php
largefilehelpergetfilesize.php
logger.php
naturalsort.php
navigationmanagertest.php Add tests for the navigation manager (closure) behaviour 2015-03-16 16:46:17 +01:00
ocsclienttest.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 fix cherrypicking 2015-04-10 11:08:24 +02:00
repair.php
setup.php Properly handle available databases at runtime and respect setup checks in command line as well 2015-03-11 09:27:12 +01:00
streamwrappers.php Replace originalStorage in tests with a proper teardown 2015-04-08 12:45:38 +02:00
tags.php
template.php
tempmanager.php Fix collision on temporary files + adjust permissions 2015-04-23 15:07:54 +02:00
testcase.php Replace originalStorage in tests with a proper teardown 2015-04-08 12:45:38 +02:00
updater.php Add wrapper for Guzzle 2015-03-25 16:04:41 +01:00
urlgenerator.php Cache \OC\URLGenerator::imagePath 2015-03-17 12:35:47 +01:00
user.php
util.php Select the timezone on the right timestamp and assert it 2015-04-07 10:13:51 +02:00
utilcheckserver.php