scratch – Diff between revs 13 and 14
?pathlinks?
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) || |
|
27 | !in_array(strtoupper($fileExtension), $ALLOWED_FILE_EXTENSIONS)) |
28 | !in_array(strtoupper($fileExtension), $ALLOWED_FILE_EXTENSIONS)) |
|
28 | return; |
29 | $fileExtension = 'txt'; |
|
29 | |
- | ||
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 |
39 | $name |
|
40 | ) |
- | ||
41 | ) |
40 | ) |
|
42 | ). |
41 | ) |
|
43 | '.'. |
42 | ). '.'. |
|
- | 43 | $fileExtension |
||
- | 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, |
|
50 | $file |
51 | $file |
|
Line 51... | Line 52... | |||
51 | ) |
52 | ) |
|
52 | ); |
53 | ); |
|
53 | |
54 | |
|
54 | #### Check for path traversals. |
55 | #### Check for path traversals |
|
55 | $pathPart = pathinfo($userPath); |
- | ||
56 | if (realpath($pathPart['dirname']) == $storePath) { |
56 | $pathPart = pathinfo($userPath); |
|
- | 57 | if (realpath($pathPart['dirname']) != realpath($STORE_FOLDER)) |
||
- | 58 | return; |
||
Line 57... | Line 59... | |||
57 | atomized_put_contents($userPath, $data); |
59 | |
|
58 | $output = sprintf('%s/%s', trim($URL_PATH, '/'), $file); |
60 | #### Store the file. |
|
59 | } |
61 | atomized_put_contents($userPath, $data); |