scratch – Diff between revs 13 and 14

Subversion Repositories:
Rev:
Show entire fileRegard whitespace
Rev 13 Rev 14
Line 18... Line 18...
18 # Raw POST data. 18 # Raw POST data.
19 $name = urldecode(@$_SERVER['HTTP_X_FILE_NAME']); 19 $name = urldecode(@$_SERVER['HTTP_X_FILE_NAME']);
20 $data = file_get_contents("php://input"); 20 $data = file_get_contents("php://input");
21 } 21 }
Line -... Line 22...
-   22  
22   23 #### Grab the file extension.
Line 23... Line 24...
23 $fileExtension = pathinfo($name, PATHINFO_EXTENSION); 24 $fileExtension = pathinfo($name, PATHINFO_EXTENSION);
24   25  
25 #### Check that the file extension is allowed. 26 #### If the extension is not allowed then change it to a text extension.
26 if(!isset($fileExtension) || 27 if (!isset($fileExtension) ||
Line 27... Line 28...
27 !in_array(strtoupper($fileExtension), $ALLOWED_FILE_EXTENSIONS)) 28 !in_array(strtoupper($fileExtension), $ALLOWED_FILE_EXTENSIONS))
28 return; -  
29   29 $fileExtension = 'txt';
30 #### Hash filename and check storage in the upload folder. 30
31 $storePath = realpath($STORE_FOLDER); 31 #### Hash filename.
32 $file = strtolower( 32 $file = strtolower(
33 PseudoCrypt::hash( 33 PseudoCrypt::hash(
34 preg_replace( 34 preg_replace(
35 '/\D/', 35 '/\D/',
36 '', 36 '',
37 hash( 37 hash(
38 'sha512', 38 'sha512',
39 $name -  
40 ) 39 $name
41 ) 40 )
42 ). 41 )
-   42 ). '.'.
-   43 $fileExtension
43 '.'. 44 );
44 $fileExtension 45  
45 ); 46 #### Build the user path.
46 $userPath = join( 47 $userPath = join(
47 DIRECTORY_SEPARATOR, 48 DIRECTORY_SEPARATOR,
48 array( 49 array(
49 $STORE_FOLDER, 50 $STORE_FOLDER,
Line 50... Line 51...
50 $file 51 $file
51 ) 52 )
52 ); 53 );
-   54  
-   55 #### Check for path traversals
-   56 $pathPart = pathinfo($userPath);
53   57 if (realpath($pathPart['dirname']) != realpath($STORE_FOLDER))
54 #### Check for path traversals. -  
55 $pathPart = pathinfo($userPath); -  
Line 56... Line 58...
56 if (realpath($pathPart['dirname']) == $storePath) { 58 return;
57 atomized_put_contents($userPath, $data); 59  
58 $output = sprintf('%s/%s', trim($URL_PATH, '/'), $file); 60 #### Store the file.