Commit Graph

11 Commits

Author SHA1 Message Date
Robin McCorkell 5a1619d80d Unit test getting temp dir from config 2015-08-30 23:34:38 +01:00
Robin McCorkell a0dfaf9be3 Clean up TempManager to follow code guidelines
tmpBaseDir can be overridden for unit testing purposes
2015-08-30 23:30:56 +01:00
root acae208f2f moved code to /lib/private/tempmanager.php
fix for unit test

some fixes
2015-08-29 16:59:02 +01:00
Joas Schilling d3e3a84cae Move the helpful method to the TestCase class 2015-06-03 12:33:29 +02:00
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
Lukas Reschke 9622fbdf29 Filter potential dangerous characters in path name
We should not allow / or \ in the postfix here.
2015-03-26 23:17:18 +01:00
Olivier Paroz f890c3ffb1 Make the method compatible with all types of extensions
Fix existing tests
2015-03-19 16:09:16 +01:00
Thomas Müller 5d4b7e0e2b fix failing unit test for the temp manager - concurrently executed unit tests influence each other 2014-11-25 22:16:48 +01:00
Joas Schilling cb3a598cdb Make root tests extend the \Test\TestCase 2014-11-19 14:53:51 +01:00
Joas Schilling a9c2e5a08e Windows does not support CHMOD, therefor we can not test not writable folders 2014-11-10 11:05:17 +01:00
Robin Appelman 83c74b80ad Add \OC\TempManager to handle creating and cleaning temporary files 2014-10-24 12:18:46 +02:00