nextcloud/tests
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
..
acceptance correct delete-icon to icon-delete, fix #11128 2014-09-22 18:17:33 +02:00
core Merge pull request #12085 from owncloud/add-swift-mailer 2015-03-17 11:15:39 +01:00
data Fix encryption feof to not return too early 2015-04-20 18:32:40 +02:00
lib Fix collision on temporary files + adjust permissions 2015-04-23 15:07:54 +02:00
settings Adjust tests and statuscode 2015-04-20 13:00:02 +02:00
apps.php load test cases from enabled apps 2012-10-08 14:26:51 +02:00
bootstrap.php kill OC_FileProxy 💥 2015-04-07 13:30:28 +02:00
enable_all.php Further cleanup of files_encryption 2015-04-07 13:30:28 +02:00
karma.config.js Use storage id + appframework for ext storage CRUD 2015-03-12 18:51:02 +01:00
phpunit-autotest-external.xml Setup a docker container that holds a webdav instance to test files_external 2014-12-17 21:50:35 +01:00
phpunit-autotest.xml Add provisioning_api app 2014-12-24 22:15:20 +01:00
phpunit.xml.dist Add provisioning_api app 2014-12-24 22:15:20 +01:00
preseed-config.php Do not add apps2/ directory if it does not exist 2015-03-19 09:07:29 +01:00
startsessionlistener.php kill OC::$session 2014-08-29 10:22:21 +02:00